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