BxCoursesSearchResult.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 Courses Courses
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxCoursesSearchResult extends BxBaseModGroupsSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_courses',
  18. 'module_name' => 'bx_courses',
  19. 'object_metatags' => 'bx_courses',
  20. 'title' => _t('_bx_courses_page_title_browse'),
  21. 'table' => 'sys_profiles',
  22. 'tableSearch' => 'bx_courses_data',
  23. 'ownFields' => array(),
  24. 'searchFields' => array(),
  25. 'restriction' => array(
  26. 'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
  27. 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  28. 'perofileType' => array('value' => 'bx_courses', 'field' => 'type', 'operator' => '='),
  29. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_courses_data'),
  30. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_courses_data'),
  31. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '=', 'table' => 'bx_courses_data'),
  32. 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '=', 'table' => 'bx_courses_data'),
  33. ),
  34. 'join' => array (
  35. 'profile' => array(
  36. 'type' => 'INNER',
  37. 'table' => 'bx_courses_data',
  38. 'mainField' => 'content_id',
  39. 'onField' => 'id',
  40. 'joinFields' => array('id', 'name', 'desc', 'picture', 'cover', 'cover_data', 'added', 'author', 'allow_view_to', 'status'),
  41. ),
  42. 'account' => array(
  43. 'type' => 'INNER',
  44. 'table' => 'sys_accounts',
  45. 'mainField' => 'account_id',
  46. 'onField' => 'id',
  47. 'joinFields' => array(),
  48. ),
  49. ),
  50. 'paginate' => array('perPage' => getParam('bx_courses_per_page_browse'), 'start' => 0),
  51. 'sorting' => 'last',
  52. 'rss' => array(
  53. 'title' => '',
  54. 'link' => '',
  55. 'image' => '',
  56. 'profile' => 0,
  57. 'fields' => array (
  58. 'Guid' => 'link',
  59. 'Link' => 'link',
  60. 'Title' => 'group_name',
  61. 'DateTimeUTS' => 'added',
  62. 'Desc' => 'group_name',
  63. 'Image' => 'picture',
  64. ),
  65. ),
  66. 'ident' => 'id'
  67. );
  68. $this->sFilterName = 'bx_courses_data_filter';
  69. $this->oModule = $this->getMain();
  70. $CNF = &$this->oModule->_oConfig->CNF;
  71. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  72. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  73. $oJoinedProfile = null;
  74. $bProcessConditionsForPrivateContent = true;
  75. switch ($sMode) {
  76. case 'created_entries':
  77. $this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile);
  78. break;
  79. case 'context':
  80. $oProfileAuthor = null;
  81. if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor))
  82. break;
  83. if(!$this->aCurrent['title'])
  84. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_by_context');
  85. break;
  86. case 'joined_entries':
  87. $oJoinedProfile = null;
  88. if(!$this->_updateCurrentForJoinedEntries($sMode, $aParams, $oJoinedProfile))
  89. break;
  90. $bProcessConditionsForPrivateContent = false;
  91. if(!$this->aCurrent['title'])
  92. $this->aCurrent['title'] = _t('_bx_courses_page_title_joined_entries');
  93. break;
  94. case 'connections':
  95. if ($this->_setConnectionsConditions($aParams)) {
  96. $bProcessConditionsForPrivateContent = false;
  97. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  98. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  99. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  100. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  101. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  102. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_connections', $oProfile->getDisplayName());
  103. $this->aCurrent['rss']['link'] = 'modules/?r=courses/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  104. }
  105. break;
  106. case 'favorite':
  107. $this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile);
  108. break;
  109. case 'recent':
  110. $this->aCurrent['rss']['link'] = 'modules/?r=courses/rss/' . $sMode;
  111. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_recent');
  112. $this->aCurrent['sorting'] = 'last';
  113. $this->sBrowseUrl = 'page.php?i=courses-home';
  114. break;
  115. case 'featured':
  116. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  117. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_featured');
  118. $this->aCurrent['restriction']['featured']['value'] = '0';
  119. $this->aCurrent['rss']['link'] = 'modules/?r=courses/rss/' . $sMode;
  120. $this->aCurrent['sorting'] = 'featured';
  121. break;
  122. case 'recommended':
  123. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  124. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_recommended');
  125. $this->aCurrent['restriction']['featured']['value'] = '0';
  126. $this->aCurrent['rss']['link'] = 'modules/?r=courses/rss/' . $sMode;
  127. $this->aCurrent['sorting'] = 'recommended';
  128. $this->_setConditionsForRecommended();
  129. break;
  130. case 'top':
  131. $this->aCurrent['rss']['link'] = 'modules/?r=courses/rss/' . $sMode;
  132. $this->aCurrent['title'] = _t('_bx_courses_page_title_browse_top');
  133. $this->aCurrent['sorting'] = 'top';
  134. $this->sBrowseUrl = 'page.php?i=courses-top';
  135. break;
  136. case '': // search results
  137. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  138. $this->aCurrent['title'] = _t('_bx_courses');
  139. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  140. break;
  141. default:
  142. $this->isError = true;
  143. }
  144. if ($bProcessConditionsForPrivateContent) {
  145. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  146. $this->addCustomConditions($CNF, $oJoinedProfile, $sMode, $aParams);
  147. }
  148. $this->sCenterContentUnitSelector = false;
  149. }
  150. function getAlterOrder()
  151. {
  152. switch ($this->aCurrent['sorting']) {
  153. case 'featured':
  154. return array('order' => ' ORDER BY `bx_courses_data`.`featured` DESC ');
  155. case 'recommended':
  156. return array('order' => ' ORDER BY RAND() ');
  157. case 'none':
  158. return array();
  159. case 'top':
  160. return array('order' => ' ORDER BY `bx_courses_data`.`views` DESC ');
  161. case 'last':
  162. default:
  163. return array('order' => ' ORDER BY `bx_courses_data`.`added` DESC ');
  164. }
  165. }
  166. function _getPseud ()
  167. {
  168. return array(
  169. 'id' => 'id',
  170. 'name' => 'name',
  171. 'added' => 'added',
  172. 'author' => 'author',
  173. 'picture' => 'picture',
  174. );
  175. }
  176. }
  177. /** @} */