BxBasePagesSearchResult.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBasePagesSearchResult extends BxTemplSearchResult
  10. {
  11. function __construct()
  12. {
  13. parent::__construct();
  14. $this->aCurrent = array(
  15. 'name' => 'sys_pages',
  16. 'module_name' => 'system',
  17. 'title' => _t('_sys_pages'),
  18. 'table' => 'sys_pages_blocks',
  19. 'ownFields' => array('text_updated`, MAX(`text_updated`) AS `updated_max'),
  20. 'searchFields' => array('text'),
  21. 'restriction' => array(
  22. 'visible_for_levels' => array('value' => '', 'field' => 'visible_for_levels', 'operator' => '&'),
  23. ),
  24. 'join' => array(
  25. 'albums' => array(
  26. 'type' => 'INNER',
  27. 'table' => 'sys_objects_page',
  28. 'mainField' => 'object',
  29. 'onField' => 'object',
  30. 'joinFields' => array('id', 'title', 'url', 'module'),
  31. 'groupTable' => 'sys_objects_page',
  32. 'groupField' => 'object',
  33. ),
  34. ),
  35. 'paginate' => array('perPage' => 10, 'start' => 0),
  36. 'sorting' => 'last',
  37. 'ident' => 'id',
  38. );
  39. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  40. $this->aCurrent['restriction']['visible_for_levels']['value'] = 1; // for guests
  41. if (isAdmin()) {
  42. // admin can view anything
  43. $this->aCurrent['restriction']['visible_for_levels']['value'] = '';
  44. }
  45. elseif ($iProfileId = bx_get_logged_profile_id()) {
  46. $oAcl = BxDolAcl::getInstance();
  47. $iProfileAclBit = $oAcl->getMemberLevelBit($iProfileId);
  48. if ($iProfileAclBit)
  49. $this->aCurrent['restriction']['visible_for_levels']['value'] = $iProfileAclBit;
  50. }
  51. // TODO: check for privacy
  52. }
  53. function displaySearchUnit($aData)
  54. {
  55. $sModule = $aData['module'];
  56. $sIcon = 'file-alt';
  57. if ('system' == $sModule || 'custom' == $sModule) {
  58. $sModule = '';
  59. }
  60. elseif (($oModule = BxDolModule::getInstance($aData['module'])) && isset($oModule->_oConfig->CNF)) {
  61. $CNF = $oModule->_oConfig->CNF;
  62. if (isset($CNF['T']['txt_sample_single']))
  63. $sModule = _t($CNF['T']['txt_sample_single']);
  64. if (isset($CNF['ICON']))
  65. $sIcon = $CNF['ICON'];
  66. }
  67. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($aData['url']);
  68. $aVars = array(
  69. 'title' => _t($aData['title']),
  70. 'content_url' => $sUrl,
  71. 'updated' => $aData['updated_max'] ? bx_time_js($aData['updated_max']) : '',
  72. 'ts' => $aData['updated_max'],
  73. 'module_name' => $sModule,
  74. 'icon' => $sIcon,
  75. );
  76. if ($this->_bLiveSearch) {
  77. $sTemplate = 'search_pages_results_live.html';
  78. }
  79. else {
  80. $sTemplate = 'search_pages_results.html';
  81. }
  82. return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, $aVars);
  83. }
  84. function getAlterOrder()
  85. {
  86. if($this->aCurrent['sorting'] == 'last')
  87. return array('order' => " ORDER BY `text_updated` DESC");
  88. return array();
  89. }
  90. }
  91. /** @} */