File indexing completed on 2025-01-26 05:24:53

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 Scriptaculous-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_AutoCompleteScriptaculous extends Zend_Controller_Action_Helper_AutoComplete_Abstract
0039 {
0040     /**
0041      * Validate data for autocompletion
0042      *
0043      * @param  mixed $data
0044      * @return bool
0045      */
0046     public function validateData($data)
0047     {
0048         if (!is_array($data) && !is_scalar($data)) {
0049             return false;
0050         }
0051 
0052         return true;
0053     }
0054 
0055     /**
0056      * Prepare data for autocompletion
0057      *
0058      * @param  mixed   $data
0059      * @param  boolean $keepLayouts
0060      * @throws Zend_Controller_Action_Exception
0061      * @return string
0062      */
0063     public function prepareAutoCompletion($data, $keepLayouts = false)
0064     {
0065         if (!$this->validateData($data)) {
0066             /**
0067              * @see Zend_Controller_Action_Exception
0068              */
0069             // require_once 'Zend/Controller/Action/Exception.php';
0070             throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
0071         }
0072 
0073         $data = (array) $data;
0074         $data = '<ul><li>' . implode('</li><li>', $data) . '</li></ul>';
0075 
0076         if (!$keepLayouts) {
0077             $this->disableLayouts();
0078         }
0079 
0080         return $data;
0081     }
0082 }