| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup Groups Groups
- * @ingroup TridentModules
- *
- * @{
- */
- /**
- * Groups profiles module.
- */
- class BxGroupsModule extends BxBaseModProfileModule
- {
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- }
- /**
- * Get possible recipients for start conversation form
- */
- public function actionAjaxGetInitialMembers ()
- {
- $sTerm = bx_get('term');
- $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
- header('Content-Type:text/javascript; charset=utf-8');
- echo(json_encode($a));
- }
- public function serviceActAsProfile ()
- {
- return false;
- }
- /**
- * Delete profile from fans and admins tables
- * @param $iProfileId profile id
- */
- public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
- {
- $CNF = &$this->_oConfig->CNF;
- $this->_oDb->deleteAdminsByProfileId($iProfileId);
- if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
- $oConnection->onDeleteInitiatorAndContent($iProfileId);
- }
- /**
- * Reset group's author for particular group
- * @param $iContentId group id
- * @return false of error, or number of updated records on success
- */
- public function serviceReassignEntityAuthor ($iContentId)
- {
- $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
- if (!$aContentInfo)
- return false;
- if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
- return false;
- $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
- return $this->_oDb->updateAuthorById($iContentId, $aAdmins ? array_pop($aAdmins) : 0);
- }
- /**
- * Reset group's author when author profile is deleted
- * @param $iProfileId profile id
- * @return number of changed items
- */
- public function serviceReassignEntitiesByAuthor ($iProfileId)
- {
- $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
- if (!$a)
- return 0;
- $iCount = 0;
- foreach ($a as $aContentInfo)
- $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
- return $iCount;
- }
- public function servicePrepareFields ($aFieldsProfile)
- {
- $aFieldsProfile['group_name'] = $aFieldsProfile['name'];
- $aFieldsProfile['group_desc'] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
- unset($aFieldsProfile['name']);
- unset($aFieldsProfile['description']);
- return $aFieldsProfile;
- }
- public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
- {
- $CNF = &$this->_oConfig->CNF;
- if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
- return false;
- if ($oGroupProfile->getModule() == $this->getName()) {
- $iProfileId = $iInitiatorId;
- $iGroupProfileId = $oGroupProfile->id();
- } else {
- $iProfileId = $oGroupProfile->id();
- $iGroupProfileId = $iInitiatorId;
- }
- if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
- return false;
- if (!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
- return false;
- $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
- $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
- // send invitation to the group
- if ($iIgnoreJoinConfirmation && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
- sendMailTemplate('bx_groups_invitation', 0, $iProfileId, array(
- 'InviterUrl' => BxDolProfile::getInstance()->getUrl(),
- 'InviterDisplayName' => BxDolProfile::getInstance()->getDisplayName(),
- 'EntryUrl' => $sEntryUrl,
- 'EntryTitle' => $sEntryTitle,
- ), BX_EMAIL_NOTIFY);
- }
- // send notification to group's admins that new connection is pending confirmation
- elseif (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
- $aAdmins = $this->_oDb->getAdmins($iGroupProfileId);
- foreach ($aAdmins as $iAdminProfileId) {
- sendMailTemplate('bx_groups_join_request', 0, $iAdminProfileId, array(
- 'NewMemberUrl' => BxDolProfile::getInstance($iProfileId)->getUrl(),
- 'NewMemberDisplayName' => BxDolProfile::getInstance($iProfileId)->getDisplayName(),
- 'EntryUrl' => $sEntryUrl,
- 'EntryTitle' => $sEntryTitle,
- ), BX_EMAIL_NOTIFY);
- }
- }
- // send notification that join request was accepted
- else if (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
- sendMailTemplate('bx_groups_join_confirm', 0, $iProfileId, array(
- 'EntryUrl' => $sEntryUrl,
- 'EntryTitle' => $sEntryTitle,
- ), BX_EMAIL_NOTIFY);
- }
- // don't automatically add back connection (mutual) if group requires manual join confirmation
- if (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation'])
- return false;
- // check if connection already exists
- if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
- return false;
- if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
- return false;
- return true;
- }
- public function serviceFansTable ()
- {
- $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
- if (!$oGrid)
- return false;
- return $oGrid->getCode();
- }
- public function serviceFans ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
- return false;
- bx_import('BxDolConnection');
- $s = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
- if (!$s)
- return MsgBox(_t('_sys_txt_empty'));
- return $s;
- }
- public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
- {
- if (!$iProfileId)
- $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
- if (!$iProfileId)
- return '';
- return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- public function checkAllowedView ($aDataEntry, $isPerformAction = false)
- {
- $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
- if ($oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected(bx_get_logged_profile_id(), $oGroupProfile->id(), true))
- return CHECK_ACTION_RESULT_ALLOWED;
- return parent::checkAllowedView ($aDataEntry, $isPerformAction);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
- {
- return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
- {
- if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
- return CHECK_ACTION_RESULT_ALLOWED;
- return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
- }
- public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
- {
- $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
- return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
- }
- public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
- {
- $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
- if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
- return CHECK_ACTION_RESULT_ALLOWED;
- return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
- }
- public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
- {
- $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
- if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
- return CHECK_ACTION_RESULT_ALLOWED;
- return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
- }
- public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
- {
- $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
- if ($oGroupProfile && $this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
- return CHECK_ACTION_RESULT_ALLOWED;
- return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
- }
- protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
- {
- $sResult = $this->checkAllowedView($aDataEntry);
- if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
- return $sResult;
- return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
- }
- }
- /** @} */
|