web/lib/Zend/Controller/Action/Helper/AutoCompleteScriptaculous.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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: AutoCompleteScriptaculous.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 Scriptaculous-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_AutoCompleteScriptaculous extends Zend_Controller_Action_Helper_AutoComplete_Abstract
       
    39 {
       
    40     /**
       
    41      * Validate data for autocompletion
       
    42      *
       
    43      * @param  mixed $data
       
    44      * @return bool
       
    45      */
       
    46     public function validateData($data)
       
    47     {
       
    48         if (!is_array($data) && !is_scalar($data)) {
       
    49             return false;
       
    50         }
       
    51 
       
    52         return true;
       
    53     }
       
    54 
       
    55     /**
       
    56      * Prepare data for autocompletion
       
    57      *
       
    58      * @param  mixed   $data
       
    59      * @param  boolean $keepLayouts
       
    60      * @throws Zend_Controller_Action_Exception
       
    61      * @return string
       
    62      */
       
    63     public function prepareAutoCompletion($data, $keepLayouts = false)
       
    64     {
       
    65         if (!$this->validateData($data)) {
       
    66             /**
       
    67              * @see Zend_Controller_Action_Exception
       
    68              */
       
    69             require_once 'Zend/Controller/Action/Exception.php';
       
    70             throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
       
    71         }
       
    72 
       
    73         $data = (array) $data;
       
    74         $data = '<ul><li>' . implode('</li><li>', $data) . '</li></ul>';
       
    75 
       
    76         if (!$keepLayouts) {
       
    77             $this->disableLayouts();
       
    78         }
       
    79 
       
    80         return $data;
       
    81     }
       
    82 }