BxBasePagesSearchResult.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. 'url' => array('value' => 'n/a', 'field' => 'url', 'operator' => 'not empty value', 'table' => 'sys_objects_page'),
  24. ),
  25. 'join' => array(
  26. 'albums' => array(
  27. 'type' => 'INNER',
  28. 'table' => 'sys_objects_page',
  29. 'mainField' => 'object',
  30. 'onField' => 'object',
  31. 'joinFields' => array('id', 'title', 'url', 'module'),
  32. 'groupTable' => 'sys_objects_page',
  33. 'groupField' => 'object',
  34. ),
  35. ),
  36. 'paginate' => array('perPage' => 10, 'start' => 0),
  37. 'sorting' => 'last',
  38. 'ident' => 'id',
  39. 'added' => 'id'
  40. );
  41. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  42. $this->aCurrent['restriction']['visible_for_levels']['value'] = 1; // for guests
  43. if (isAdmin()) {
  44. // admin can view anything
  45. $this->aCurrent['restriction']['visible_for_levels']['value'] = '';
  46. }
  47. elseif ($iProfileId = bx_get_logged_profile_id()) {
  48. $oAcl = BxDolAcl::getInstance();
  49. $iProfileAclBit = $oAcl->getMemberLevelBit($iProfileId);
  50. if ($iProfileAclBit)
  51. $this->aCurrent['restriction']['visible_for_levels']['value'] = $iProfileAclBit;
  52. }
  53. // TODO: check for privacy
  54. }
  55. function displaySearchUnit($aData)
  56. {
  57. $sModule = $aData['module'];
  58. $sIcon = 'file-alt';
  59. if ('system' == $sModule || 'custom' == $sModule) {
  60. $sModule = '';
  61. }
  62. elseif (($oModule = BxDolModule::getInstance($aData['module'])) && isset($oModule->_oConfig->CNF)) {
  63. $CNF = $oModule->_oConfig->CNF;
  64. if (isset($CNF['T']['txt_sample_single']))
  65. $sModule = _t($CNF['T']['txt_sample_single']);
  66. if (isset($CNF['ICON']))
  67. $sIcon = $CNF['ICON'];
  68. }
  69. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($aData['url']));
  70. $sTitle = _t($aData['title']);
  71. if (preg_match ('/{.*?}/', $sTitle))
  72. return '';
  73. $aVars = array(
  74. 'title' => $sTitle,
  75. 'content_url' => $sUrl,
  76. 'updated' => $aData['updated_max'] ? bx_time_js($aData['updated_max']) : '',
  77. 'ts' => $aData['updated_max'],
  78. 'module_name' => $sModule,
  79. 'icon' => $sIcon,
  80. );
  81. if ($this->_bLiveSearch) {
  82. $sTemplate = 'search_pages_results_live.html';
  83. }
  84. else {
  85. $sTemplate = 'search_pages_results.html';
  86. }
  87. return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, $aVars);
  88. }
  89. function getAlterOrder()
  90. {
  91. if($this->aCurrent['sorting'] == 'last')
  92. return array('order' => " ORDER BY `text_updated` DESC");
  93. return array();
  94. }
  95. }
  96. /** @} */