2
0

AutoCompleteDojo.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Dojo-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_AutoCompleteDojo extends Zend_Controller_Action_Helper_AutoComplete_Abstract
  37. {
  38. /**
  39. * Validate data for autocompletion
  40. *
  41. * Stub; unused
  42. *
  43. * @param mixed $data
  44. * @return boolean
  45. */
  46. public function validateData($data)
  47. {
  48. return true;
  49. }
  50. /**
  51. * Prepare data for autocompletion
  52. *
  53. * @param mixed $data
  54. * @param boolean $keepLayouts
  55. * @return string
  56. */
  57. public function prepareAutoCompletion($data, $keepLayouts = false)
  58. {
  59. if (!$data instanceof Zend_Dojo_Data) {
  60. require_once 'Zend/Dojo/Data.php';
  61. $items = array();
  62. foreach ($data as $key => $value) {
  63. $items[] = array('label' => $value, 'name' => $value);
  64. }
  65. $data = new Zend_Dojo_Data('name', $items);
  66. }
  67. if (!$keepLayouts) {
  68. require_once 'Zend/Controller/Action/HelperBroker.php';
  69. Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
  70. require_once 'Zend/Layout.php';
  71. $layout = Zend_Layout::getMvcInstance();
  72. if ($layout instanceof Zend_Layout) {
  73. $layout->disableLayout();
  74. }
  75. }
  76. $response = Zend_Controller_Front::getInstance()->getResponse();
  77. $response->setHeader('Content-Type', 'application/json');
  78. return $data->toJson();
  79. }
  80. }