| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Groups Groups
- * @ingroup UnaModules
- *
- * @{
- */
- class BxBaseModGroupsConnectionFans extends BxTemplConnection
- {
- protected $_sModule;
- protected $_oModule;
- protected $_bQuestionnaire;
- public function __construct($aObject)
- {
- parent::__construct($aObject);
- $this->_oModule = BxDolModule::getInstance($this->_sModule);
- $this->_bQuestionnaire = false;
- }
- public function getModule()
- {
- return $this->_sModule;
- }
-
- public function actionRemove($iContent = 0, $iInitiator = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $aResult = parent::actionRemove($iContent, $iInitiator);
- if($aResult['err'] == false) {
- if(!$iContent)
- $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
- $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContent);
- if(!empty($aContentInfo) && is_array($aContentInfo))
- $this->_oModule->_oDb->deleteAnswersProfileId($aContentInfo[$CNF['FIELD_ID']], $iInitiator ? $iInitiator : bx_get_logged_profile_id());
- }
- return $aResult;
- }
-
- public function actionReject ($iInitiator = 0, $iContent = false)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $aResult = parent::actionReject($iInitiator, $iContent);
- if($aResult['err'] == false) {
- if(!$iContent)
- $iContent = bx_process_input($_POST['id'], BX_DATA_INT);
- $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContent);
- if(!empty($aContentInfo) && is_array($aContentInfo))
- $this->_oModule->_oDb->deleteAnswersProfileId($aContentInfo[$CNF['FIELD_ID']], $iInitiator ? $iInitiator : bx_get_logged_profile_id());
- }
- return $aResult;
- }
-
- public function getActionTitle($sAction, $iInitiatorId, $iContentId, $bFlip = false)
- {
- $aResult = [];
- if($this->isConnectedNotMutual($iInitiatorId, $iContentId))
- $aResult = [
- 'add' => '',
- 'remove' => _t('_sys_menu_item_title_sm_leave_cancel'),
- ];
- else if($this->isConnectedNotMutual($iContentId, $iInitiatorId))
- $aResult = [
- 'add' => _t('_sys_menu_item_title_sm_join_confirm'),
- 'remove' => _t('_sys_menu_item_title_sm_leave_reject'),
- ];
- else if($this->isConnected($iInitiatorId, $iContentId, true))
- $aResult = [
- 'add' => '',
- 'remove' => _t('_sys_menu_item_title_sm_leave'),
- ];
- else
- $aResult = [
- 'add' => _t('_sys_menu_item_title_sm_join'),
- 'remove' => '',
- ];
- $aFlip = ['add' => 'remove', 'remove' => 'add'];
- if($bFlip)
- $sAction = $aFlip[$sAction];
- return !empty($aResult[$sAction]) ? _t($aResult[$sAction]) : '';
- }
- public function hasQuestionnaire($iContentProfileId)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
-
- if(!$this->_bQuestionnaire || empty($CNF['FIELD_JOIN_CONFIRMATION']))
- return false;
- $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return false;
- return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->hasQuestions($aContentInfo[$CNF['FIELD_ID']]);
- }
-
- public function isQuestionnaireAnswered($iContentProfileId, $iProfileId = 0)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(!$iProfileId)
- $iProfileId = bx_get_logged_profile_id();
- if(!$iProfileId)
- return false;
- if(!$this->_bQuestionnaire || empty($CNF['FIELD_JOIN_CONFIRMATION']))
- return false;
- $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return false;
- return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->areQuestionsAnswered($aContentInfo[$CNF['FIELD_ID']], $iProfileId);
- }
- public function getQuestionnaireForm($sAction, $iContentProfileId, $aParams = [])
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
-
- if(!$this->_bQuestionnaire)
- return false;
- if(empty($aParams['request']) || !is_array($aParams['request']))
- $aParams['request'] = [];
- $aForm = [
- 'form_attrs' => [
- 'id' => $this->_oModule->getName() . '_questionnaire',
- 'action' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oModule->_oConfig->getBaseUri() . 'get_questionnaire', array_merge([
- 'o' => $this->_sObject,
- 'a' => $sAction,
- 'cpi' => $iContentProfileId
- ], $aParams['request']))
- ],
- 'params' => [
- 'db' => [
- 'table' => $CNF['TABLE_ANSWERS'],
- 'key' => '',
- 'uri' => '',
- 'uri_title' => '',
- 'submit_name' => 'do_submit'
- ],
- 'module' => $this->_sModule,
- 'object' => $this->_sModule . '_questionnaire',
- 'display' => $this->_sModule . '_questionnaire_answer',
- 'view_mode' => 0,
- ],
- 'inputs' => []
- ];
- $aQuestions = $this->_oModule->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
- if(empty($aQuestions) || !is_array($aQuestions))
- return false;
- foreach($aQuestions as $aQuestion) {
- $sName = 'question_' . $aQuestion['id'];
- $aForm['inputs'][$sName] = [
- 'type' => 'text',
- 'name' => $sName,
- 'caption' => $aQuestion['question'],
- 'value' => '',
- 'required' => '1',
- 'checker' => [
- 'func' => 'Avail',
- 'params' => [],
- 'error' => _t($CNF['T']['form_qnr_field_qn_err']),
- ],
- 'db' => [
- 'pass' => 'Xss',
- ],
- ];
- }
- $aForm['inputs']['controls'] = [
- 'name' => 'controls',
- 'type' => 'input_set', [
- 'type' => 'submit',
- 'name' => 'do_submit',
- 'value' => _t('_Submit'),
- ], [
- 'type' => 'reset',
- 'name' => 'close',
- 'value' => _t('_Cancel'),
- 'attrs' => [
- 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
- 'class' => 'bx-def-margin-sec-left',
- ],
- ]
- ];
- return new BxTemplFormView($aForm);
- }
- protected function _checkAllowedConnectInitiator ($oInitiator, $isPerformAction = false)
- {
- if(!bx_srv($oInitiator->getModule(), 'act_as_profile'))
- return CHECK_ACTION_RESULT_ALLOWED;
- return parent::_checkAllowedConnectInitiator($oInitiator, $isPerformAction);
- }
- public function _checkAllowedConnectContent ($oContent)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if(bx_srv($oContent->getModule(), 'act_as_profile'))
- return CHECK_ACTION_RESULT_ALLOWED;
- if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false) {
- $iContentId = $oContent->getContentId();
- $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
- if(in_array($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), ['s'])))
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- return parent::_checkAllowedConnectContent($oContent);
- }
- }
- /** @} */
|