/application/website/default/controllers/SearchController.php

https://github.com/massiveart-webservices/ZOOLU · PHP · 157 lines · 75 code · 27 blank · 55 comment · 6 complexity · 9d15aebb272745e0d619dd5109142361 MD5 · raw file

  1. <?php
  2. /**
  3. * SearchController
  4. *
  5. * Version history (please keep backward compatible):
  6. * 1.0, 2009-08-20: Cornelius Hansjakob
  7. *
  8. * @author Cornelius Hansjakob <cha@massiveart.com>
  9. * @version 1.0
  10. */
  11. class SearchController extends Zend_Controller_Action {
  12. /**
  13. * @var Core
  14. */
  15. private $core;
  16. /**
  17. * @var integer
  18. */
  19. protected $intLanguageId;
  20. /**
  21. * @var string
  22. */
  23. protected $strLanguageCode;
  24. /**
  25. * @var HtmlTranslate
  26. */
  27. private $translate;
  28. /**
  29. * @var boolean
  30. */
  31. private $blnHasSegments;
  32. /**
  33. * @var integer
  34. */
  35. private $intSegmentId;
  36. /**
  37. * @var string
  38. */
  39. private $strSegmentCode;
  40. /**
  41. * init index controller and get core obj
  42. */
  43. public function init(){
  44. $this->core = Zend_Registry::get('Core');
  45. }
  46. /**
  47. * indexAction
  48. * @author Cornelius Hansjakob <cha@massiveart.com>
  49. * @version 1.0
  50. */
  51. public function indexAction(){
  52. $this->core->logger->debug('website->controllers->SearchController->indexAction()');
  53. $request = $this->getRequest();
  54. $strSearchValue = strip_tags($request->getParam('q'));
  55. $intRootLevelId = $request->getParam('rootLevelId');
  56. $arrSegmentationInfos = $request->getParam('segmentation');
  57. $this->blnHasSegments = (array_key_exists('hasSegments', $arrSegmentationInfos)) ? $arrSegmentationInfos['hasSegments'] : false;
  58. $this->intSegmentId = (array_key_exists('id', $arrSegmentationInfos)) ? $arrSegmentationInfos['id'] : null;
  59. $this->strSegmentCode = (array_key_exists('code', $arrSegmentationInfos)) ? $arrSegmentationInfos['code'] : null;
  60. $this->intLanguageId = $this->core->intLanguageId;
  61. $this->strLanguageCode = $this->core->strLanguageCode;
  62. /**
  63. * set for output
  64. */
  65. $this->view->strLanguageCode = $this->strLanguageCode;
  66. /**
  67. * set up zoolu translate obj
  68. */
  69. if(file_exists(GLOBAL_ROOT_PATH.'application/website/default/language/website-'.$this->strLanguageCode.'.mo')){
  70. $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH.'application/website/default/language/website-'.$this->strLanguageCode.'.mo');
  71. }else{
  72. $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH.'application/website/default/language/website-'.$this->core->sysConfig->languages->default->code.'.mo');
  73. }
  74. $this->view->translate = $this->translate;
  75. $objSearch = New Search();
  76. $objSearch->setSearchValue($strSearchValue);
  77. $objSearch->setLanguageId($this->intLanguageId);
  78. $objSearch->setRootLevelId($intRootLevelId);
  79. /**
  80. * set for output
  81. */
  82. $this->view->objHits = $objSearch->search();
  83. $this->view->strSearchValue = $strSearchValue;
  84. $this->view->languageCode = $this->strLanguageCode;
  85. $this->view->rootLevelId = $intRootLevelId;
  86. $this->view->hasSegments = $this->blnHasSegments;
  87. $this->view->segmentId = $this->intSegmentId;
  88. $this->view->segmentCode = $this->strSegmentCode;
  89. $this->view->setScriptPath(GLOBAL_ROOT_PATH.'public/website/themes/'.$request->getParam('theme').'/');
  90. $this->renderScript('search.php');
  91. }
  92. /**
  93. * livesearchAction
  94. * @author Cornelius Hansjakob <cha@massiveart.com>
  95. * @version 1.0
  96. */
  97. public function livesearchAction(){
  98. $this->core->logger->debug('website->controllers->SearchController->livesearchAction()');
  99. if (isset($_GET['q']) && $_GET['q'] != '') {
  100. $request = $this->getRequest();
  101. $strSearchValue = $request->getParam('q');
  102. $this->intLanguageId = $request->getParam('languageId');
  103. $this->strLanguageCode = $request->getParam('languageCode', $this->core->strLanguageCode);
  104. $this->intSegmentId = intval($request->getParam('segmentId'));
  105. $this->strSegmentCode = $request->getParam('segmentCode');
  106. $intRootLevelId = $request->getParam('rootLevelId');
  107. /**
  108. * set up zoolu translate obj
  109. */
  110. if(file_exists(GLOBAL_ROOT_PATH.'application/website/default/language/website-'.$this->strLanguageCode.'.mo')){
  111. $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH.'application/website/default/language/website-'.$this->strLanguageCode.'.mo');
  112. }else{
  113. $this->translate = new HtmlTranslate('gettext', GLOBAL_ROOT_PATH.'application/website/default/language/website-'.$this->core->sysConfig->languages->default->code.'.mo');
  114. }
  115. $this->view->translate = $this->translate;
  116. $objSearch = New Search();
  117. $objSearch->setSearchValue($strSearchValue);
  118. $objSearch->setLanguageId($this->intLanguageId);
  119. $objSearch->setRootLevelId($intRootLevelId);
  120. $objSearch->setLimitLiveSearch(5);
  121. $this->view->objHits = $objSearch->livesearch();
  122. $this->view->rootLevelId = $intRootLevelId;
  123. $this->view->segmentId = $this->intSegmentId;
  124. $this->view->segmentCode = $this->strSegmentCode;
  125. } else {
  126. $this->_helper->viewRenderer->setNoRender();
  127. }
  128. }
  129. }
  130. ?>