2
0

AutoComplete.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 ZendX
  16. * @package ZendX_JQuery
  17. * @subpackage View
  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$
  21. */
  22. require_once "Zend/Controller/Action/Helper/AutoComplete/Abstract.php";
  23. class ZendX_JQuery_Controller_Action_Helper_AutoComplete
  24. extends Zend_Controller_Action_Helper_AutoComplete_Abstract
  25. {
  26. /**
  27. * Validate autocompletion data
  28. *
  29. * @param mixed $data
  30. * @return boolean
  31. */
  32. public function validateData($data)
  33. {
  34. if (!is_array($data)) {
  35. return false;
  36. }
  37. return true;
  38. }
  39. /**
  40. * Prepare autocompletion data
  41. *
  42. * @param mixed $data
  43. * @param boolean $keepLayouts
  44. * @return mixed
  45. */
  46. public function prepareAutoCompletion($data, $keepLayouts = false)
  47. {
  48. if (!$this->validateData($data)) {
  49. /**
  50. * @see Zend_Controller_Action_Exception
  51. */
  52. require_once 'Zend/Controller/Action/Exception.php';
  53. throw new Zend_Controller_Action_Exception('Invalid data passed for autocompletion');
  54. }
  55. $data = (array) $data;
  56. $output = "";
  57. foreach($data AS $k => $v) {
  58. if(is_numeric($k)) {
  59. $output .= $v."\n";
  60. } else {
  61. $output .= $k."|".$v."\n";
  62. }
  63. }
  64. if (!$keepLayouts) {
  65. $this->disableLayouts();
  66. }
  67. return $output;
  68. }
  69. }