1
0

BxBaseModGroupsConnectionFans.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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($this->_bQuestionnaire && $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($this->_bQuestionnaire && $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 hasQuestionnaire($iContentProfileId)
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. if(!$this->_bQuestionnaire || empty($CNF['FIELD_JOIN_CONFIRMATION']))
  56. return false;
  57. $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
  58. if(empty($aContentInfo) || !is_array($aContentInfo))
  59. return false;
  60. return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->hasQuestions($aContentInfo[$CNF['FIELD_ID']]);
  61. }
  62. public function isQuestionnaireAnswered($iContentProfileId, $iProfileId = 0)
  63. {
  64. $CNF = &$this->_oModule->_oConfig->CNF;
  65. if(!$iProfileId)
  66. $iProfileId = bx_get_logged_profile_id();
  67. if(!$iProfileId)
  68. return false;
  69. if(!$this->_bQuestionnaire || empty($CNF['FIELD_JOIN_CONFIRMATION']))
  70. return false;
  71. $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
  72. if(empty($aContentInfo) || !is_array($aContentInfo))
  73. return false;
  74. return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->areQuestionsAnswered($aContentInfo[$CNF['FIELD_ID']], $iProfileId);
  75. }
  76. public function getQuestionnaireForm($sAction, $iContentProfileId, $aParams = [])
  77. {
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. if(!$this->_bQuestionnaire)
  80. return false;
  81. if(empty($aParams['request']) || !is_array($aParams['request']))
  82. $aParams['request'] = [];
  83. $aForm = [
  84. 'form_attrs' => [
  85. 'id' => $this->_oModule->getName() . '_questionnaire',
  86. 'action' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oModule->_oConfig->getBaseUri() . 'get_questionnaire', array_merge([
  87. 'o' => $this->_sObject,
  88. 'a' => $sAction,
  89. 'cpi' => $iContentProfileId
  90. ], $aParams['request']))
  91. ],
  92. 'params' => [
  93. 'db' => [
  94. 'table' => $CNF['TABLE_ANSWERS'],
  95. 'key' => '',
  96. 'uri' => '',
  97. 'uri_title' => '',
  98. 'submit_name' => 'do_submit'
  99. ],
  100. 'module' => $this->_sModule,
  101. 'object' => $this->_sModule . '_questionnaire',
  102. 'display' => $this->_sModule . '_questionnaire_answer',
  103. 'view_mode' => 0,
  104. ],
  105. 'inputs' => []
  106. ];
  107. $aQuestions = $this->_oModule->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
  108. if(empty($aQuestions) || !is_array($aQuestions))
  109. return false;
  110. foreach($aQuestions as $aQuestion) {
  111. $sName = 'question_' . $aQuestion['id'];
  112. $aForm['inputs'][$sName] = [
  113. 'type' => 'text',
  114. 'name' => $sName,
  115. 'caption' => $aQuestion['question'],
  116. 'value' => '',
  117. 'required' => '1',
  118. 'checker' => [
  119. 'func' => 'Avail',
  120. 'params' => [],
  121. 'error' => _t($CNF['T']['form_qnr_field_qn_err']),
  122. ],
  123. 'db' => [
  124. 'pass' => 'Xss',
  125. ],
  126. ];
  127. }
  128. $aForm['inputs']['controls'] = [
  129. 'name' => 'controls',
  130. 'type' => 'input_set', [
  131. 'type' => 'submit',
  132. 'name' => 'do_submit',
  133. 'value' => _t('_Submit'),
  134. ], [
  135. 'type' => 'reset',
  136. 'name' => 'close',
  137. 'value' => _t('_Cancel'),
  138. 'attrs' => [
  139. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  140. 'class' => 'bx-def-margin-sec-left',
  141. ],
  142. ]
  143. ];
  144. return new BxTemplFormView($aForm);
  145. }
  146. protected function _checkAllowedConnectInitiator ($oInitiator, $isPerformAction = false)
  147. {
  148. if(!bx_srv($oInitiator->getModule(), 'act_as_profile'))
  149. return CHECK_ACTION_RESULT_ALLOWED;
  150. return parent::_checkAllowedConnectInitiator($oInitiator, $isPerformAction);
  151. }
  152. public function _checkAllowedConnectContent ($oContent)
  153. {
  154. $CNF = &$this->_oModule->_oConfig->CNF;
  155. if(bx_srv($oContent->getModule(), 'act_as_profile'))
  156. return CHECK_ACTION_RESULT_ALLOWED;
  157. if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false) {
  158. $iContentId = $oContent->getContentId();
  159. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  160. if(in_array($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), ['s'])))
  161. return CHECK_ACTION_RESULT_ALLOWED;
  162. }
  163. return parent::_checkAllowedConnectContent($oContent);
  164. }
  165. }
  166. /** @} */