BxBaseSearchResult.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolSearch');
  10. class BxBaseSearchResult extends BxDolSearchResult
  11. {
  12. public $isError;
  13. protected $sBrowseUrl; ///< currect browse url, used for paginate and other links in browsing
  14. protected $sUnitTemplate = 'unit.html'; ///< common template to try to use for displaying one item
  15. protected $aGetParams = array(); ///< get params to keep in paginate and other browsing links
  16. protected $iDesignBoxTemplate = BX_DB_PADDING_DEF; ///< design box ID to warp result in
  17. protected $aConstants;
  18. function __construct($oFunctions = false)
  19. {
  20. parent::__construct();
  21. if ($oFunctions) {
  22. $this->oFunctions = $oFunctions;
  23. } else {
  24. bx_import('BxTemplFunctions');
  25. $this->oFunctions = BxTemplFunctions::getInstance();
  26. }
  27. }
  28. function getMain()
  29. {
  30. // override this to return main module class
  31. }
  32. function displayResultBlock ()
  33. {
  34. $sCode = '';
  35. $aData = $this->getSearchData();
  36. if ($this->aCurrent['paginate']['num'] > 0) {
  37. $sCode .= $this->addCustomParts();
  38. foreach ($aData as $aValue) {
  39. $sCode .= $this->displaySearchUnit($aValue);
  40. }
  41. $sCode = '<div class="bx-search-result-block bx-clearfix">' . $sCode . '</div>';
  42. }
  43. return $sCode;
  44. }
  45. function displaySearchBox ($sCode, $sPaginate = '')
  46. {
  47. $sTitle = _t($this->aCurrent['title']);
  48. $sCode = $this->oFunctions->designBoxContent($sTitle, $sCode . $sPaginate, $this->iDesignBoxTemplate, $this->getDesignBoxMenu());
  49. if (!isset($_GET['searchMode']))
  50. $sCode = '<div id="page_block_' . $this->id . '" class="bx-clearfix">' . $sCode . '</div>';
  51. return $sCode;
  52. }
  53. function displaySearchUnit ($aData)
  54. {
  55. $oMain = $this->getMain();
  56. return $oMain->_oTemplate->unit($aData, $this->bProcessPrivateContent, $this->sUnitTemplate);
  57. }
  58. function getDesignBoxMenu ()
  59. {
  60. if (false === ($sLink = $this->getRssPageUrl ()))
  61. return false;
  62. return array(
  63. array('name' => 'rss', 'title' => _t('_sys_menu_title_rss'), 'link' => $sLink, 'icon' => 'rss')
  64. );
  65. }
  66. function getRssPageUrl ()
  67. {
  68. if (!isset($this->aCurrent['rss']) || !$this->aCurrent['rss']['link'])
  69. return false;
  70. bx_import('BxDolPermalinks');
  71. $oPermalinks = BxDolPermalinks::getInstance();
  72. return BX_DOL_URL_ROOT . bx_append_url_params($oPermalinks->permalink($this->aCurrent['rss']['link']), 'rss=1');
  73. }
  74. function showAdminActionsPanel($sWrapperId, $aButtons, $sCheckboxName = 'entry', $bSelectAll = true, $bSelectAllChecked = false, $sCustomHtml = '')
  75. {
  76. $aBtns = array();
  77. foreach ($aButtons as $k => $v) {
  78. if(is_array($v)) {
  79. $aBtns[] = $v;
  80. continue;
  81. }
  82. $aBtns[] = array(
  83. 'type' => 'submit',
  84. 'name' => $k,
  85. 'value' => '_' == $v[0] ? _t($v) : $v,
  86. 'onclick' => '',
  87. );
  88. }
  89. $aUnit = array(
  90. 'bx_repeat:buttons' => $aBtns,
  91. 'bx_if:customHTML' => array(
  92. 'condition' => strlen($sCustomHtml) > 0,
  93. 'content' => array(
  94. 'custom_HTML' => $sCustomHtml,
  95. )
  96. ),
  97. 'bx_if:selectAll' => array(
  98. 'condition' => $bSelectAll,
  99. 'content' => array(
  100. 'wrapperId' => $sWrapperId,
  101. 'checkboxName' => $sCheckboxName,
  102. 'checked' => ($bSelectAll && $bSelectAllChecked ? 'checked="checked"' : '')
  103. )
  104. ),
  105. );
  106. return BxDolTemplate::getInstance()->parseHtmlByName('adminActionsPanel.html', $aUnit, array('{','}'));
  107. }
  108. function showAdminFilterPanel($sFilterValue, $sInputId = 'filter_input_id', $sCheckboxId = 'filter_checkbox_id', $sFilterName = 'filter', $sOnApply = '')
  109. {
  110. $sFilter = _t('_sys_admin_filter');
  111. $sApply = _t('_sys_admin_apply');
  112. $sFilterValue = bx_html_attribute($sFilterValue);
  113. $isChecked = $sFilterValue ? ' checked="checked" ' : '';
  114. $sJsContent = "";
  115. if(empty($sOnApply)) {
  116. $sOnApply = 'on_filter_apply(this)';
  117. ob_start();
  118. ?>
  119. <script type="text/javascript">
  120. function on_filter_apply (e) {
  121. var s = ('' + document.location).replace (/[&]{0,1}<?=$sFilterName;?>=.*/, ''); // remove filter
  122. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  123. if (e.checked && $('#<?=$sInputId;?>').val().length > 2)
  124. s += (-1 == s.indexOf('?') ? '?' : '&') + '<?=$sFilterName;?>=' + $('#<?=$sInputId;?>').val(); // append filter
  125. document.location = s;
  126. }
  127. function on_filter_key_up (e) {
  128. if (13 == e.keyCode) {
  129. $('#<?php echo $sCheckboxId; ?>').attr('checked', 'checked');
  130. on_filter_apply($('#<?php echo $sCheckboxId; ?>').get(0));
  131. return false;
  132. } else {
  133. $('#<?php echo $sCheckboxId; ?>').attr('checked', '');
  134. return true;
  135. }
  136. }
  137. </script>
  138. <?
  139. $sJsContent = ob_get_clean();
  140. }
  141. return <<<EOF
  142. {$sJsContent}
  143. <div class="admin_filter_panel">
  144. <table>
  145. <tr>
  146. <td>{$sFilter}</td>
  147. <td>
  148. <div class="input_wrapper input_wrapper_text">
  149. <input type="text" id="{$sInputId}" value="{$sFilterValue}" class="form_input_text" onkeypress="return on_filter_key_up(event)" />
  150. <div class="input_close input_close_text">&nbsp;</div>
  151. </div>
  152. </td>
  153. <td><input type="checkbox" id="{$sCheckboxId}" $isChecked onclick="{$sOnApply}" /></td>
  154. <td><label for="{$sCheckboxId}">{$sApply}</label></td>
  155. </tr>
  156. </table>
  157. </div>
  158. EOF;
  159. }
  160. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  161. {
  162. $oMain = $this->getMain();
  163. $oConfig = $oMain->_oConfig;
  164. $sUrlStart = $this->getCurrentUrl(array(), false);
  165. bx_import('BxTemplPaginate');
  166. $oPaginate = new BxTemplPaginate(array(
  167. 'page_url' => $sUrlStart,
  168. 'num' => $this->aCurrent['paginate']['num'],
  169. 'per_page' => $this->aCurrent['paginate']['perPage'],
  170. 'start' => $this->aCurrent['paginate']['start'],
  171. ));
  172. return $oPaginate->getPaginate();
  173. }
  174. /**
  175. * Get current browse URL with current page and additional params
  176. * @param $aAdditionalParams set custom additional params as key value pair
  177. * @param $bReplacePagesParams replace paginate params with current values or leave markers for use in paginate class
  178. * @return ready to use URL string with BX_DOL_URL_ROOT added in the beginning
  179. */
  180. protected function getCurrentUrl($aAdditionalParams = array(), $bReplacePagesParams = true)
  181. {
  182. bx_import('BxDolPermalinks');
  183. $oPermalinks = BxDolPermalinks::getInstance();
  184. // base url
  185. $sUrlStart = BX_DOL_URL_ROOT . $oPermalinks->permalink($this->sBrowseUrl);
  186. // add pages params
  187. $sUrlStart = bx_append_url_params($sUrlStart, array (
  188. 'start' => $bReplacePagesParams ? (int)$this->aCurrent['paginate']['start'] : '{start}',
  189. 'per_page' => $bReplacePagesParams ? (int)$this->aCurrent['paginate']['perPage'] : '{per_page}',
  190. ));
  191. // add additional params
  192. foreach ($this->aGetParams as $sGetParam) {
  193. $sValue = false;
  194. if (isset($aAdditionalParams[$sGetParam]))
  195. $sValue = $aAdditionalParams[$sGetParam];
  196. elseif (false !== bx_get($sGetParam))
  197. $sValue = bx_get($sGetParam);
  198. if (false !== $sValue)
  199. $sUrlStart = bx_append_url_params($sUrlStart, $sGetParam . '=' . rawurlencode($sValue));
  200. }
  201. return $sUrlStart;
  202. }
  203. function showPaginationAjax($sBlockId)
  204. {
  205. bx_import('BxTemplPaginate');
  206. $oPaginate = new BxTemplPaginate(array(
  207. 'page_url' => 'javascript:void(0);',
  208. 'num' => $this->aCurrent['paginate']['num'],
  209. 'per_page' => $this->aCurrent['paginate']['perPage'],
  210. 'start' => $this->aCurrent['paginate']['start'],
  211. ));
  212. return $oPaginate->getSimplePaginate(false, -1, -1, false);
  213. }
  214. function clearFilters ($aPassParams = array(), $aPassJoins = array())
  215. {
  216. //clear sorting
  217. $this->aCurrent['sorting'] = 'last';
  218. //clear restrictions
  219. foreach ($this->aCurrent['restriction'] as $sKey => $aValue) {
  220. if (!in_array($sKey, $aPassParams))
  221. $this->aCurrent['restriction'][$sKey]['value'] = '';
  222. }
  223. //clear unnecessary joins (remains only profile join)
  224. $aPassJoins[] = 'profile';
  225. $aTemp = array();
  226. foreach ($aPassJoins as $sValue) {
  227. if (isset($this->aCurrent['join'][$sValue]) && is_array($this->aCurrent['join'][$sValue]))
  228. $aTemp[$sValue] = $this->aCurrent['join'][$sValue];
  229. }
  230. $this->aCurrent['join'] = $aTemp;
  231. }
  232. function fillFilters ($aParams)
  233. {
  234. // transform all given values to fields values
  235. if (is_array($aParams)) {
  236. foreach ($aParams as $sKey => $mixedValue) {
  237. if (isset($this->aCurrent['restriction'][$sKey]))
  238. $this->aCurrent['restriction'][$sKey]['value'] = $mixedValue;
  239. }
  240. }
  241. }
  242. /**
  243. * Set design box template id to use to wrap search results in
  244. */
  245. function setDesignBoxTemplateId ($i)
  246. {
  247. $this->iDesignBoxTemplate = $i;
  248. }
  249. }
  250. /** @} */