BxNotesSearchResult.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. $oProfileAuthor = null;
  41. $oModuleMain = $this->getMain();
  42. switch ($sMode) {
  43. case 'search':
  44. if ($sValue)
  45. $this->aCurrent['restriction']['keyword'] = array('value' => $sValue,'field' => '','operator' => 'against');
  46. $this->sBrowseUrl = "search/?q=" . $sValue;
  47. $this->aCurrent['title'] = _t('_bx_notes_page_title_search_results', $sValue);
  48. unset($this->aCurrent['rss']);
  49. break;
  50. case 'author':
  51. bx_import('BxDolProfile');
  52. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  53. if (!$oProfileAuthor) {
  54. $this->isError = true;
  55. break;
  56. }
  57. $this->aCurrent['restriction']['author']['value'] = $oProfileAuthor->id();
  58. $this->sBrowseUrl = 'page.php?i=notes-author&profile_id={profile_id}';
  59. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_by_author');
  60. break;
  61. case 'public':
  62. case '':
  63. $this->sBrowseUrl = 'page.php?i=notes-home';
  64. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_recent');
  65. break;
  66. default:
  67. $this->isError = true;
  68. }
  69. // add replacable markers and replace them
  70. if ($oProfileAuthor) {
  71. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replacable
  72. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replacable
  73. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replacable
  74. }
  75. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  76. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  77. // add conditions for private content
  78. bx_import('BxDolPrivacy');
  79. $oPrivacy = BxDolPrivacy::getObjectInstance(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  80. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oProfileAuthor ? $oProfileAuthor->id() : 0) : array();
  81. if (isset($a['restriction']))
  82. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  83. if (isset($a['join']))
  84. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  85. $this->setProcessPrivateContent(false);
  86. // set rss links if required
  87. if (isset($this->aCurrent['rss']))
  88. $this->aCurrent['rss']['link'] = BX_DOL_URL_ROOT . $this->sBrowseUrl;
  89. if (bx_get('rss'))
  90. $this->aCurrent['paginate']['perPage'] = 10;//$oModuleMain->_oDb->getParam('bx_groups_max_rss_num');
  91. $this->sFilterName = 'bx_notes_filter';
  92. // $this->aCurrent['paginate']['perPage'] = $oModuleMain->_oDb->getParam('bx_groups_perpage_browse'); // TODO:
  93. parent::__construct();
  94. }
  95. function displayResultBlock () {
  96. $s = parent::displayResultBlock ();
  97. $s = '<div class="bx-notes-wrapper">' . $s . '</div>';
  98. return $s;
  99. }
  100. function getAlterOrder() {
  101. if ($this->aCurrent['sorting'] == 'last') {
  102. $aSql = array();
  103. $aSql['order'] = " ORDER BY `bx_notes_posts`.`added` DESC";
  104. return $aSql;
  105. }
  106. return array();
  107. }
  108. function getMain() {
  109. return BxDolModule::getInstance($this->aCurrent['name']);
  110. }
  111. function getRssUnitLink (&$a) {
  112. bx_import('BxDolPermalinks');
  113. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $a['id']);
  114. }
  115. function _getPseud () {
  116. return array(
  117. 'id' => 'id',
  118. 'title' => 'title',
  119. 'text' => 'text',
  120. 'added' => 'added',
  121. 'author' => 'author',
  122. 'photo' => 'photo',
  123. );
  124. }
  125. }
  126. /** @} */