1
0

BxReviewsModule.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 Reviews Reviews
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Reviews module
  13. */
  14. class BxReviewsModule extends BxBaseModTextModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. $CNF = &$this->_oConfig->CNF;
  20. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  21. $CNF['FIELD_ALLOW_COMMENTS']
  22. ));
  23. }
  24. public function serviceGetSearchableFields($aInputsAdd = array())
  25. {
  26. $CNF = &$this->_oConfig->CNF;
  27. $aResult = parent::serviceGetSearchableFields($aInputsAdd);
  28. unset($aResult[$CNF['FIELD_PRODUCT']]);
  29. return $aResult;
  30. }
  31. public function serviceGetContextModulesOptions() {
  32. if (!($aModules = BxDolModuleQuery::getInstance()->getModules()))
  33. return [];
  34. $aValues = [];
  35. foreach ($aModules as $aModule) {
  36. if (!$aModule['enabled'])
  37. continue;
  38. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  39. continue;
  40. $aValues[$aModule['name']] = $aModule['title'];
  41. }
  42. return $aValues;
  43. }
  44. /**
  45. * Entry post for Timeline module
  46. */
  47. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  48. {
  49. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  50. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  51. return $aResult;
  52. return $aResult;
  53. }
  54. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  55. {
  56. $CNF = &$this->_oConfig->CNF;
  57. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  58. if ($aContentInfo && $aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  59. return false;
  60. return parent::serviceCheckAllowedCommentsPost($iContentId, $sObjectComments);
  61. }
  62. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  63. {
  64. $CNF = &$this->_oConfig->CNF;
  65. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  66. if ($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  67. return false;
  68. return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
  69. }
  70. /*
  71. * Rating block for entry view page
  72. **/
  73. public function serviceEntityVotingOptions($iContentId = 0) {
  74. if (!$iContentId) $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  75. if ($iContentId) {
  76. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  77. $aOptions = !empty($aContentInfo['voting_options']) ? unserialize($aContentInfo['voting_options']) : array();
  78. return $this->_oTemplate->getMultiVoting($aOptions, false);
  79. }
  80. return '';
  81. }
  82. /*
  83. * Stars Rating block for rate by users
  84. **/
  85. public function serviceEntityRating($iContentId = 0) {
  86. if (!$iContentId) $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  87. if ($iContentId) {
  88. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  89. if (!$aContentInfo) return '';
  90. return $this->_oTemplate->entryRating($aContentInfo);
  91. }
  92. return '';
  93. }
  94. /*
  95. * Reviewed content block for module homepage
  96. **/
  97. public function serviceBrowseReviewedContent() {
  98. if ($this->_oDb->getParam($this->_oConfig->CNF['PARAM_CONTEXT_CONTROL_ENABLE']))
  99. return $this->_oTemplate->browseReviewedContent();
  100. }
  101. /*
  102. * ACTIONS
  103. */
  104. public function actionGetReviewRatingDetails($iContentId) {
  105. $sVoting = $this->serviceEntityVotingOptions($iContentId);
  106. if (!empty($sVoting))
  107. echo BxTemplFunctions::getInstance()->transBox('bx_reviews_rating', DesignBoxContent('',$sVoting, BX_DB_PADDING_CONTENT_ONLY), false);
  108. }
  109. public function actionSuggestProfileForReview ($sTerm, $iLimit = 20)
  110. {
  111. if (!$sTerm && isset($_GET['term'])) $sTerm = bx_get('term');
  112. $CNF = &$this->_oConfig->CNF;
  113. $sModules = $this->_oDb->getParam($CNF['PARAM_CONTEXT_MODULES_AVAILABLE']);
  114. $aResult = array();
  115. if ($sModules) {
  116. $aInstalledModules = BxDolModuleQuery::getInstance()->getModules();
  117. $aEnabledModules = [];
  118. foreach ($aInstalledModules as $aModule) $aEnabledModules[$aModule['name']] = $aModule['enabled'];
  119. $aModulesList = explode(',', $sModules);
  120. foreach ($aModulesList as $sModulename) {
  121. if (!isset($aEnabledModules[$sModulename]) || !$aEnabledModules[$sModulename]) continue;
  122. $aResult = array_merge($aResult, BxDolService::call($sModulename, 'profiles_search', array($sTerm, getParam('sys_per_page_search_keyword_single'))));
  123. }
  124. // sort result
  125. usort($aResult, function($r1, $r2) {
  126. return strcmp($r1['label'], $r2['label']);
  127. });
  128. }
  129. bx_alert('system', 'profiles_search', 0, 0, array(
  130. 'term' => $sTerm,
  131. 'result' => &$aResult,
  132. 'module' => $this->_aModule['name'],
  133. ));
  134. header('Content-Type:text/javascript; charset=utf-8');
  135. echo json_encode(array_slice($aResult, 0, $iLimit));
  136. }
  137. }
  138. /** @} */