BxNotesSearchResult.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 Notes Notes
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplSearchResult');
  12. class BxNotesSearchResult extends BxTemplSearchResult {
  13. var $aCurrent = array(
  14. 'name' => 'bx_notes',
  15. 'title' => '_bx_notes_page_title_browse',
  16. 'table' => 'bx_notes_posts',
  17. 'ownFields' => array('id', 'title', 'text', 'summary', 'thumb', 'author', 'added'),
  18. 'searchFields' => array('title', 'text'),
  19. 'restriction' => array(
  20. 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
  21. ),
  22. 'paginate' => array('perPage' => 8, 'start' => 0),
  23. 'sorting' => 'last',
  24. 'rss' => array(
  25. 'title' => '',
  26. 'link' => '',
  27. 'image' => '',
  28. 'profile' => 0,
  29. 'fields' => array (
  30. 'Guid' => 'link',
  31. 'Link' => 'link',
  32. 'Title' => 'title',
  33. 'DateTimeUTS' => 'added',
  34. 'Desc' => 'text',
  35. ),
  36. ),
  37. 'ident' => 'id'
  38. );
  39. function __construct($sMode = '', $aParams) {
  40. $this->sUnitTemplate = 'unit_gallery.html';
  41. $oProfileAuthor = null;
  42. $oModuleMain = $this->getMain();
  43. switch ($sMode) {
  44. case 'search':
  45. if ($sValue)
  46. $this->aCurrent['restriction']['keyword'] = array('value' => $sValue,'field' => '','operator' => 'against');
  47. $this->sBrowseUrl = "search/?q=" . $sValue;
  48. $this->aCurrent['title'] = _t('_bx_notes_page_title_search_results', $sValue);
  49. unset($this->aCurrent['rss']);
  50. break;
  51. case 'author':
  52. bx_import('BxDolProfile');
  53. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  54. if (!$oProfileAuthor) {
  55. $this->isError = true;
  56. break;
  57. }
  58. $this->aCurrent['restriction']['author']['value'] = $oProfileAuthor->id();
  59. $this->sBrowseUrl = 'page.php?i=notes-author&profile_id={profile_id}';
  60. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_by_author');
  61. break;
  62. case 'public':
  63. case '':
  64. $this->sBrowseUrl = 'page.php?i=notes-home';
  65. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_recent');
  66. break;
  67. default:
  68. $this->isError = true;
  69. }
  70. // add replacable markers and replace them
  71. if ($oProfileAuthor) {
  72. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replacable
  73. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replacable
  74. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replacable
  75. }
  76. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  77. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  78. // add conditions for private content
  79. bx_import('BxDolPrivacy');
  80. $oPrivacy = BxDolPrivacy::getObjectInstance(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  81. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oProfileAuthor ? $oProfileAuthor->id() : 0) : array();
  82. if (isset($a['restriction']))
  83. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  84. if (isset($a['join']))
  85. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  86. $this->setProcessPrivateContent(false);
  87. // set rss links if required
  88. if (isset($this->aCurrent['rss']))
  89. $this->aCurrent['rss']['link'] = BX_DOL_URL_ROOT . $this->sBrowseUrl;
  90. if (bx_get('rss'))
  91. $this->aCurrent['paginate']['perPage'] = 10;//$oModuleMain->_oDb->getParam('bx_groups_max_rss_num');
  92. $this->sFilterName = 'bx_notes_filter';
  93. // $this->aCurrent['paginate']['perPage'] = $oModuleMain->_oDb->getParam('bx_groups_perpage_browse'); // TODO:
  94. parent::__construct();
  95. }
  96. function displayResultBlock () {
  97. $s = parent::displayResultBlock ();
  98. $s = '<div class="bx-notes-wrapper ' . ('unit_gallery.html' == $this->sUnitTemplate ? 'bx-def-margin-neg bx-clearfix' : '') . '">' . $s . '</div>';
  99. return $s;
  100. }
  101. function getAlterOrder() {
  102. if ($this->aCurrent['sorting'] == 'last') {
  103. $aSql = array();
  104. $aSql['order'] = " ORDER BY `bx_notes_posts`.`added` DESC";
  105. return $aSql;
  106. }
  107. return array();
  108. }
  109. function getMain() {
  110. return BxDolModule::getInstance($this->aCurrent['name']);
  111. }
  112. function getRssUnitLink (&$a) {
  113. bx_import('BxDolPermalinks');
  114. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $a['id']);
  115. }
  116. function _getPseud () {
  117. return array(
  118. 'id' => 'id',
  119. 'title' => 'title',
  120. 'text' => 'text',
  121. 'added' => 'added',
  122. 'author' => 'author',
  123. 'photo' => 'photo',
  124. );
  125. }
  126. }
  127. /** @} */