BxPersonsSearchResult.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 Persons Persons
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplSearchResult');
  12. class BxPersonsSearchResult extends BxTemplSearchResult {
  13. var $aCurrent = array(
  14. 'name' => 'bx_persons',
  15. 'title' => '_bx_persons_page_title_browse',
  16. 'table' => 'sys_profiles',
  17. 'ownFields' => array(),
  18. 'searchFields' => array('fullname'),
  19. 'restriction' => array(
  20. 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  21. 'perofileType' => array('value' => 'bx_persons', 'field' => 'type', 'operator' => '='),
  22. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_persons_data'),
  23. ),
  24. 'join' => array (
  25. 'profile' => array(
  26. 'type' => 'INNER',
  27. 'table' => 'bx_persons_data',
  28. 'mainField' => 'content_id',
  29. 'onField' => 'id',
  30. 'joinFields' => array('id', 'fullname', 'picture', 'added'),
  31. ),
  32. ),
  33. 'paginate' => array('perPage' => 20, 'start' => 0),
  34. 'sorting' => 'none',
  35. 'rss' => array(
  36. 'title' => '',
  37. 'link' => '',
  38. 'image' => '',
  39. 'profile' => 0,
  40. 'fields' => array (
  41. 'Guid' => 'link',
  42. 'Link' => 'link',
  43. 'Title' => 'fullname',
  44. 'DateTimeUTS' => 'added',
  45. 'Desc' => 'fullname',
  46. 'Picture' => 'picture',
  47. ),
  48. ),
  49. 'ident' => 'id'
  50. );
  51. function __construct($sMode = '', $mixedParams = false) {
  52. $oModuleMain = $this->getMain();
  53. switch ($sMode) {
  54. case 'connections':
  55. $aParams = $mixedParams;
  56. bx_import('BxDolConnection');
  57. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  58. if ($oConnection && isset($aParams['profile']) && (int)$aParams['profile']) {
  59. $sMethod = 'getConnectedContentAsCondition';
  60. if (isset($aParams['type']) && $aParams['type'] == 'initiators')
  61. $sMethod = 'getConnectedInitiatorsAsCondition';
  62. $a = $oConnection->$sMethod('id', (int)$aParams['profile'], isset($aParams['mutual']) ? $aParams['mutual'] : false);
  63. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  64. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  65. }
  66. break;
  67. case 'search':
  68. $sValue = $mixedParams;
  69. if ($sValue)
  70. $this->aCurrent['restriction']['keyword'] = array('value' => $sValue,'field' => '','operator' => 'against');
  71. $this->sBrowseUrl = "search/?q=" . $sValue;
  72. $this->aCurrent['title'] = _t('_bx_persons_page_title_search_results', $sValue);
  73. unset($this->aCurrent['rss']);
  74. break;
  75. case 'user':
  76. $iProfileId = (int)$mixedParams;
  77. $aContentInfo = $oModuleMain->_oDb->getContentInfoById($iContentId);
  78. if (!$aContentInfo)
  79. $this->isError = true;
  80. else
  81. $this->aCurrent['restriction']['owner']['value'] = $iProfileId;
  82. $this->sBrowseUrl = "browse/user/$iProfileId";
  83. $this->aCurrent['title'] = _t('_bx_persons_page_title_browse_by_author', $aContentInfo['fullname']); // TODO: owner name here
  84. if (bx_get('rss')) {
  85. $aData = getProfileInfo($iProfileId);
  86. if ($aData['Avatar']) {
  87. if (!$aImage['no_image'])
  88. $this->aCurrent['rss']['image'] = $aImage['file'];
  89. }
  90. }
  91. break;
  92. case 'recent':
  93. case '':
  94. $this->sBrowseUrl = 'browse/recent';
  95. $this->aCurrent['title'] = _t('_bx_persons_page_title_browse_recent');
  96. break;
  97. default:
  98. $this->isError = true;
  99. }
  100. // $this->aCurrent['paginate']['perPage'] = $oModuleMain->_oDb->getParam('bx_groups_perpage_browse'); // TODO:
  101. if (isset($this->aCurrent['rss']))
  102. $this->aCurrent['rss']['link'] = BX_DOL_URL_ROOT . $oModuleMain->_oConfig->getBaseUri() . $this->sBrowseUrl;
  103. if (bx_get('rss')) {
  104. $this->aCurrent['paginate']['perPage'] = 10;//$oModuleMain->_oDb->getParam('bx_groups_max_rss_num');
  105. }
  106. $this->sFilterName = 'bx_persons_filter';
  107. parent::__construct();
  108. }
  109. function getAlterOrder() {
  110. switch ($this->aCurrent['sorting']) {
  111. case 'none':
  112. return array();
  113. case 'last':
  114. default:
  115. $aSql = array();
  116. $aSql['order'] = " ORDER BY `bx_persons_data`.`added` DESC";
  117. return $aSql;
  118. }
  119. }
  120. function displayResultBlock () {
  121. $s = parent::displayResultBlock ();
  122. if ($s) {
  123. $oModuleMain = $this->getMain();
  124. BxDolTemplate::getInstance()->addDynamicLocation($oModuleMain->_oConfig->getHomePath(), $oModuleMain->_oConfig->getHomeUrl());
  125. bx_import('BxTemplFunctions');
  126. return BxTemplFunctions::getInstance()->centerContent ($s, '.bx-persons-unit');
  127. }
  128. return '';
  129. }
  130. function getMain() {
  131. return BxDolModule::getInstance($this->aCurrent['name']);
  132. }
  133. function getRssUnitLink (&$a) {
  134. bx_import('BxDolPermalinks');
  135. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-persons-profile&id=' . $a['id']);
  136. }
  137. function _getPseud () {
  138. return array(
  139. 'id' => 'id',
  140. 'fullname' => 'fullname',
  141. 'added' => 'added',
  142. 'author' => 'author',
  143. 'picture' => 'picture',
  144. );
  145. }
  146. }
  147. /** @} */