1
0

BxBaseModGroupsConnectionFans.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 Groups Groups
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsConnectionFans extends BxTemplConnection
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_bQuestionnaire;
  16. public function __construct($aObject)
  17. {
  18. parent::__construct($aObject);
  19. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  20. $this->_bQuestionnaire = false;
  21. }
  22. public function getModule()
  23. {
  24. return $this->_sModule;
  25. }
  26. public function actionRemove($iContent = 0, $iInitiator = false)
  27. {
  28. $CNF = &$this->_oModule->_oConfig->CNF;
  29. $aResult = parent::actionRemove($iContent, $iInitiator);
  30. if($aResult['err'] == false) {
  31. if(!$iContent)
  32. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  33. $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContent);
  34. if(!empty($aContentInfo) && is_array($aContentInfo))
  35. $this->_oModule->_oDb->deleteAnswersProfileId($aContentInfo[$CNF['FIELD_ID']], $iInitiator ? $iInitiator : bx_get_logged_profile_id());
  36. }
  37. return $aResult;
  38. }
  39. public function actionReject ($iInitiator = 0, $iContent = false)
  40. {
  41. $CNF = &$this->_oModule->_oConfig->CNF;
  42. $aResult = parent::actionReject($iInitiator, $iContent);
  43. if($aResult['err'] == false) {
  44. if(!$iContent)
  45. $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
  46. $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContent);
  47. if(!empty($aContentInfo) && is_array($aContentInfo))
  48. $this->_oModule->_oDb->deleteAnswersProfileId($aContentInfo[$CNF['FIELD_ID']], $iInitiator ? $iInitiator : bx_get_logged_profile_id());
  49. }
  50. return $aResult;
  51. }
  52. public function getActionTitle($sAction, $iInitiatorId, $iContentId, $bFlip = false)
  53. {
  54. $aResult = [];
  55. if($this->isConnectedNotMutual($iInitiatorId, $iContentId))
  56. $aResult = [
  57. 'add' => '',
  58. 'remove' => _t('_sys_menu_item_title_sm_leave_cancel'),
  59. ];
  60. else if($this->isConnectedNotMutual($iContentId, $iInitiatorId))
  61. $aResult = [
  62. 'add' => _t('_sys_menu_item_title_sm_join_confirm'),
  63. 'remove' => _t('_sys_menu_item_title_sm_leave_reject'),
  64. ];
  65. else if($this->isConnected($iInitiatorId, $iContentId, true))
  66. $aResult = [
  67. 'add' => '',
  68. 'remove' => _t('_sys_menu_item_title_sm_leave'),
  69. ];
  70. else
  71. $aResult = [
  72. 'add' => _t('_sys_menu_item_title_sm_join'),
  73. 'remove' => '',
  74. ];
  75. $aFlip = ['add' => 'remove', 'remove' => 'add'];
  76. if($bFlip)
  77. $sAction = $aFlip[$sAction];
  78. return !empty($aResult[$sAction]) ? _t($aResult[$sAction]) : '';
  79. }
  80. public function hasQuestionnaire($iContentProfileId)
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. if(!$this->_bQuestionnaire || empty($CNF['FIELD_JOIN_CONFIRMATION']))
  84. return false;
  85. $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
  86. if(empty($aContentInfo) || !is_array($aContentInfo))
  87. return false;
  88. return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->hasQuestions($aContentInfo[$CNF['FIELD_ID']]);
  89. }
  90. public function isQuestionnaireAnswered($iContentProfileId, $iProfileId = 0)
  91. {
  92. $CNF = &$this->_oModule->_oConfig->CNF;
  93. if(!$iProfileId)
  94. $iProfileId = bx_get_logged_profile_id();
  95. if(!$iProfileId)
  96. return false;
  97. if(!$this->_bQuestionnaire || empty($CNF['FIELD_JOIN_CONFIRMATION']))
  98. return false;
  99. $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
  100. if(empty($aContentInfo) || !is_array($aContentInfo))
  101. return false;
  102. return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->areQuestionsAnswered($aContentInfo[$CNF['FIELD_ID']], $iProfileId);
  103. }
  104. public function getQuestionnaireForm($sAction, $iContentProfileId, $aParams = [])
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. if(!$this->_bQuestionnaire)
  108. return false;
  109. if(empty($aParams['request']) || !is_array($aParams['request']))
  110. $aParams['request'] = [];
  111. $aForm = [
  112. 'form_attrs' => [
  113. 'id' => $this->_oModule->getName() . '_questionnaire',
  114. 'action' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oModule->_oConfig->getBaseUri() . 'get_questionnaire', array_merge([
  115. 'o' => $this->_sObject,
  116. 'a' => $sAction,
  117. 'cpi' => $iContentProfileId
  118. ], $aParams['request']))
  119. ],
  120. 'params' => [
  121. 'db' => [
  122. 'table' => $CNF['TABLE_ANSWERS'],
  123. 'key' => '',
  124. 'uri' => '',
  125. 'uri_title' => '',
  126. 'submit_name' => 'do_submit'
  127. ],
  128. 'module' => $this->_sModule,
  129. 'object' => $this->_sModule . '_questionnaire',
  130. 'display' => $this->_sModule . '_questionnaire_answer',
  131. 'view_mode' => 0,
  132. ],
  133. 'inputs' => []
  134. ];
  135. $aQuestions = $this->_oModule->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
  136. if(empty($aQuestions) || !is_array($aQuestions))
  137. return false;
  138. foreach($aQuestions as $aQuestion) {
  139. $sName = 'question_' . $aQuestion['id'];
  140. $aForm['inputs'][$sName] = [
  141. 'type' => 'text',
  142. 'name' => $sName,
  143. 'caption' => $aQuestion['question'],
  144. 'value' => '',
  145. 'required' => '1',
  146. 'checker' => [
  147. 'func' => 'Avail',
  148. 'params' => [],
  149. 'error' => _t($CNF['T']['form_qnr_field_qn_err']),
  150. ],
  151. 'db' => [
  152. 'pass' => 'Xss',
  153. ],
  154. ];
  155. }
  156. $aForm['inputs']['controls'] = [
  157. 'name' => 'controls',
  158. 'type' => 'input_set', [
  159. 'type' => 'submit',
  160. 'name' => 'do_submit',
  161. 'value' => _t('_Submit'),
  162. ], [
  163. 'type' => 'reset',
  164. 'name' => 'close',
  165. 'value' => _t('_Cancel'),
  166. 'attrs' => [
  167. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  168. 'class' => 'bx-def-margin-sec-left',
  169. ],
  170. ]
  171. ];
  172. return new BxTemplFormView($aForm);
  173. }
  174. protected function _checkAllowedConnectInitiator ($oInitiator, $isPerformAction = false)
  175. {
  176. if(!bx_srv($oInitiator->getModule(), 'act_as_profile'))
  177. return CHECK_ACTION_RESULT_ALLOWED;
  178. return parent::_checkAllowedConnectInitiator($oInitiator, $isPerformAction);
  179. }
  180. public function _checkAllowedConnectContent ($oContent)
  181. {
  182. $CNF = &$this->_oModule->_oConfig->CNF;
  183. if(bx_srv($oContent->getModule(), 'act_as_profile'))
  184. return CHECK_ACTION_RESULT_ALLOWED;
  185. if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false) {
  186. $iContentId = $oContent->getContentId();
  187. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  188. if(in_array($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), ['s'])))
  189. return CHECK_ACTION_RESULT_ALLOWED;
  190. }
  191. return parent::_checkAllowedConnectContent($oContent);
  192. }
  193. }
  194. /** @} */