BxBaseSearchResult.php 9.9 KB

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