|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Controller |
|
17 * @subpackage Zend_Controller_Action_Helper |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: AutoCompleteDojo.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Controller_Action_Helper_AutoComplete_Abstract |
|
25 */ |
|
26 require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php'; |
|
27 |
|
28 /** |
|
29 * Create and send Dojo-compatible autocompletion lists |
|
30 * |
|
31 * @uses Zend_Controller_Action_Helper_AutoComplete_Abstract |
|
32 * @category Zend |
|
33 * @package Zend_Controller |
|
34 * @subpackage Zend_Controller_Action_Helper |
|
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
37 */ |
|
38 class Zend_Controller_Action_Helper_AutoCompleteDojo extends Zend_Controller_Action_Helper_AutoComplete_Abstract |
|
39 { |
|
40 /** |
|
41 * Validate data for autocompletion |
|
42 * |
|
43 * Stub; unused |
|
44 * |
|
45 * @param mixed $data |
|
46 * @return boolean |
|
47 */ |
|
48 public function validateData($data) |
|
49 { |
|
50 return true; |
|
51 } |
|
52 |
|
53 /** |
|
54 * Prepare data for autocompletion |
|
55 * |
|
56 * @param mixed $data |
|
57 * @param boolean $keepLayouts |
|
58 * @return string |
|
59 */ |
|
60 public function prepareAutoCompletion($data, $keepLayouts = false) |
|
61 { |
|
62 if (!$data instanceof Zend_Dojo_Data) { |
|
63 require_once 'Zend/Dojo/Data.php'; |
|
64 $items = array(); |
|
65 foreach ($data as $key => $value) { |
|
66 $items[] = array('label' => $value, 'name' => $value); |
|
67 } |
|
68 $data = new Zend_Dojo_Data('name', $items); |
|
69 } |
|
70 |
|
71 if (!$keepLayouts) { |
|
72 require_once 'Zend/Controller/Action/HelperBroker.php'; |
|
73 Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); |
|
74 |
|
75 require_once 'Zend/Layout.php'; |
|
76 $layout = Zend_Layout::getMvcInstance(); |
|
77 if ($layout instanceof Zend_Layout) { |
|
78 $layout->disableLayout(); |
|
79 } |
|
80 } |
|
81 |
|
82 $response = Zend_Controller_Front::getInstance()->getResponse(); |
|
83 $response->setHeader('Content-Type', 'application/json'); |
|
84 |
|
85 return $data->toJson(); |
|
86 } |
|
87 } |