File indexing completed on 2024-12-29 05:27:31

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Controller
0017  * @subpackage Zend_Controller_Action_Helper
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Controller_Action_Helper_AutoComplete_Abstract
0025  */
0026 // require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
0027 
0028 /**
0029  * Create and send Dojo-compatible autocompletion lists
0030  *
0031  * @uses       Zend_Controller_Action_Helper_AutoComplete_Abstract
0032  * @category   Zend
0033  * @package    Zend_Controller
0034  * @subpackage Zend_Controller_Action_Helper
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Controller_Action_Helper_AutoCompleteDojo extends Zend_Controller_Action_Helper_AutoComplete_Abstract
0039 {
0040     /**
0041      * Validate data for autocompletion
0042      *
0043      * Stub; unused
0044      *
0045      * @param  mixed $data
0046      * @return boolean
0047      */
0048     public function validateData($data)
0049     {
0050         return true;
0051     }
0052 
0053     /**
0054      * Prepare data for autocompletion
0055      *
0056      * @param  mixed   $data
0057      * @param  boolean $keepLayouts
0058      * @return string
0059      */
0060     public function prepareAutoCompletion($data, $keepLayouts = false)
0061     {
0062         if (!$data instanceof Zend_Dojo_Data) {
0063             // require_once 'Zend/Dojo/Data.php';
0064             $items = array();
0065             foreach ($data as $key => $value) {
0066                 $items[] = array('label' => $value, 'name' => $value);
0067             }
0068             $data = new Zend_Dojo_Data('name', $items);
0069         }
0070 
0071         if (!$keepLayouts) {
0072             // require_once 'Zend/Controller/Action/HelperBroker.php';
0073             Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
0074 
0075             // require_once 'Zend/Layout.php';
0076             $layout = Zend_Layout::getMvcInstance();
0077             if ($layout instanceof Zend_Layout) {
0078                 $layout->disableLayout();
0079             }
0080         }
0081 
0082         $response = Zend_Controller_Front::getInstance()->getResponse();
0083         $response->setHeader('Content-Type', 'application/json');
0084 
0085         return $data->toJson();
0086     }
0087 }