1
0

BxBasePagesSearchResult.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. );
  40. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  41. $this->aCurrent['restriction']['visible_for_levels']['value'] = 1; // for guests
  42. if (isAdmin()) {
  43. // admin can view anything
  44. $this->aCurrent['restriction']['visible_for_levels']['value'] = '';
  45. }
  46. elseif ($iProfileId = bx_get_logged_profile_id()) {
  47. $oAcl = BxDolAcl::getInstance();
  48. $iProfileAclBit = $oAcl->getMemberLevelBit($iProfileId);
  49. if ($iProfileAclBit)
  50. $this->aCurrent['restriction']['visible_for_levels']['value'] = $iProfileAclBit;
  51. }
  52. // TODO: check for privacy
  53. }
  54. function displaySearchUnit($aData)
  55. {
  56. $sModule = $aData['module'];
  57. $sIcon = 'file-alt';
  58. if ('system' == $sModule || 'custom' == $sModule) {
  59. $sModule = '';
  60. }
  61. elseif (($oModule = BxDolModule::getInstance($aData['module'])) && isset($oModule->_oConfig->CNF)) {
  62. $CNF = $oModule->_oConfig->CNF;
  63. if (isset($CNF['T']['txt_sample_single']))
  64. $sModule = _t($CNF['T']['txt_sample_single']);
  65. if (isset($CNF['ICON']))
  66. $sIcon = $CNF['ICON'];
  67. }
  68. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($aData['url']));
  69. $sTitle = _t($aData['title']);
  70. if (preg_match ('/{.*?}/', $sTitle))
  71. return '';
  72. $aVars = array(
  73. 'title' => $sTitle,
  74. 'content_url' => $sUrl,
  75. 'updated' => $aData['updated_max'] ? bx_time_js($aData['updated_max']) : '',
  76. 'ts' => $aData['updated_max'],
  77. 'module_name' => $sModule,
  78. 'icon' => $sIcon,
  79. );
  80. if ($this->_bLiveSearch) {
  81. $sTemplate = 'search_pages_results_live.html';
  82. }
  83. else {
  84. $sTemplate = 'search_pages_results.html';
  85. }
  86. return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, $aVars);
  87. }
  88. function getAlterOrder()
  89. {
  90. if($this->aCurrent['sorting'] == 'last')
  91. return array('order' => " ORDER BY `text_updated` DESC");
  92. return array();
  93. }
  94. }
  95. /** @} */