2
0

AutoCompleteScriptaculous.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Controller_Action_Helper_AutoComplete_Abstract
  24. */
  25. require_once 'Zend/Controller/Action/Helper/AutoComplete/Abstract.php';
  26. /**
  27. * Create and send Scriptaculous-compatible autocompletion lists
  28. *
  29. * @uses Zend_Controller_Action_Helper_AutoComplete_Abstract
  30. * @category Zend
  31. * @package Zend_Controller
  32. * @subpackage Zend_Controller_Action_Helper
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Controller_Action_Helper_AutoCompleteScriptaculous extends Zend_Controller_Action_Helper_AutoComplete_Abstract
  37. {
  38. /**
  39. * Validate data for autocompletion
  40. *
  41. * @param mixed $data
  42. * @return bool
  43. */
  44. public function validateData($data)
  45. {
  46. if (!is_array($data) && !is_scalar($data)) {
  47. return false;
  48. }
  49. return true;
  50. }
  51. /**
  52. * Prepare data for autocompletion
  53. *
  54. * @param mixed $data
  55. * @param boolean $keepLayouts
  56. * @throws Zend_Controller_Action_Exception
  57. * @return string
  58. */
  59. public function prepareAutoCompletion($data, $keepLayouts = false)
  60. {
  61. if (!$this->validateData($data)) {
  62. /**
  63. * @see Zend_Controller_Action_Exception
  64. */
  65. require_once 'Zend/Controller/Action/Exception.php';
  66. throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
  67. }
  68. $data = (array) $data;
  69. $data = '<ul><li>' . implode('</li><li>', $data) . '</li></ul>';
  70. if (!$keepLayouts) {
  71. $this->disableLayouts();
  72. }
  73. return $data;
  74. }
  75. }