BxGroupsGridConnections.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Groups Groups
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxGroupsGridConnections extends BxDolGridConnections
  12. {
  13. protected $_iGroupProfileId;
  14. protected $_oModule;
  15. protected $_oConnection;
  16. protected $_aContentInfo = array();
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. $this->_sContentModule = 'bx_groups';
  20. $this->_oModule = BxDolModule::getInstance($this->_sContentModule);
  21. $this->_sObjectConnections = $this->_oModule->_oConfig->CNF['OBJECT_CONNECTIONS'];
  22. parent::__construct ($aOptions, $oTemplate);
  23. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  24. if (!$iProfileId)
  25. return;
  26. $oProfile = BxDolProfile::getInstance($iProfileId);
  27. if (!$oProfile)
  28. return;
  29. $aProfileInfo = $oProfile->getInfo();
  30. $this->_iGroupProfileId = $oProfile->id();
  31. $this->_aContentInfo = BxDolService::call($aProfileInfo['type'], 'get_content_info_by_id', array($aProfileInfo['content_id']));
  32. if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedEdit($this->_aContentInfo) || $oProfile->id() == bx_get_logged_profile_id())
  33. $this->_bOwner = true;
  34. $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $this->_iGroupProfileId, $this->_bOwner ? false : true);
  35. $this->addMarkers(array(
  36. 'profile_id' => $oProfile->id(),
  37. 'join_connections' => $aSQLParts['join'],
  38. 'content_module' => $this->_sContentModule,
  39. ));
  40. }
  41. protected function _getActionAccept ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  42. {
  43. if (isset($aRow[$this->_aOptions['field_id']]))
  44. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  45. return parent::_getActionAccept ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  46. }
  47. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  48. {
  49. if (isset($aRow[$this->_aOptions['field_id']]))
  50. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  51. return parent::_getActionDelete ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  52. }
  53. protected function _getActionToAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  54. {
  55. if ($this->_oModule->_oDb->isAdmin($this->_iGroupProfileId, $aRow[$this->_aOptions['field_id']]))
  56. return '';
  57. return $this->_getAction_Admins ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  58. }
  59. protected function _getActionFromAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  60. {
  61. if (!$this->_oModule->_oDb->isAdmin($this->_iGroupProfileId, $aRow[$this->_aOptions['field_id']]))
  62. return '';
  63. return $this->_getAction_Admins ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  64. }
  65. protected function _getAction_Admins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  66. {
  67. if (!$this->_oConnection->isConnected($aRow[$this->_aOptions['field_id']], $this->_iGroupProfileId, true))
  68. return '';
  69. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId))
  70. return '';
  71. if (isset($aRow[$this->_aOptions['field_id']]))
  72. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  73. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  74. }
  75. /**
  76. * 'To Admins' action handler
  77. */
  78. public function performActionToAdmins()
  79. {
  80. $this->_performActionAdmins('toAdmins');
  81. }
  82. /**
  83. * 'From Admins' action handler
  84. */
  85. public function performActionFromAdmins()
  86. {
  87. $this->_performActionAdmins('fromAdmins');
  88. }
  89. public function _performActionAdmins($sFunc)
  90. {
  91. list ($iId, $iGroupProfileId) = $this->_prepareIds();
  92. if (!$iId) {
  93. echoJson(array('msg' => _t('_sys_txt_error_occured')));
  94. exit;
  95. }
  96. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedManageAdmins($iGroupProfileId)) {
  97. echoJson(array('msg' => _t('_sys_txt_access_denied')));
  98. exit;
  99. }
  100. if (!$this->_oModule->_oDb->$sFunc($iGroupProfileId, $iId)) {
  101. echoJson(array('msg' => _t('_sys_txt_error_occured')));
  102. }
  103. else {
  104. $sEmailTemplate = 'toAdmins' == $sFunc ? $this->_oModule->_oConfig->CNF['EMAIL_FAN_BECOME_ADMIN'] : $this->_oModule->_oConfig->CNF['EMAIL_ADMIN_BECOME_FAN'];
  105. list($iGroupProfileId, $iProfileId) = $this->_prepareGroupProfileAndMemberProfile($iGroupProfileId, $iId);
  106. if (bx_get_logged_profile_id() != $iProfileId) {
  107. // notify about admin status
  108. sendMailTemplate($sEmailTemplate, 0, $iProfileId, array(
  109. 'EntryUrl' => BxDolProfile::getInstance($iGroupProfileId)->getUrl(),
  110. 'EntryTitle' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName(),
  111. ), BX_EMAIL_NOTIFY);
  112. }
  113. // subscribe admins automatically
  114. if ('toAdmins' == $sFunc && ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
  115. $oConn->addConnection($iProfileId, $iGroupProfileId);
  116. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
  117. }
  118. }
  119. protected function _delete ($mixedId)
  120. {
  121. list ($iId, $iViewedId) = $this->_prepareIds();
  122. // send email notification
  123. $sEmailTemplate = $this->_oConnection->isConnected($iViewedId, $iId, true) ? $this->_oModule->_oConfig->CNF['EMAIL_FAN_REMOVE'] : $this->_oModule->_oConfig->CNF['EMAIL_JOIN_REJECT'];
  124. list($iGroupProfileId, $iProfileId) = $this->_prepareGroupProfileAndMemberProfile($iId, $iViewedId);
  125. if (bx_get_logged_profile_id() != $iProfileId) {
  126. sendMailTemplate($sEmailTemplate, 0, $iProfileId, array(
  127. 'EntryUrl' => BxDolProfile::getInstance($iGroupProfileId)->getUrl(),
  128. 'EntryTitle' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName(),
  129. ), BX_EMAIL_NOTIFY);
  130. }
  131. // delete admin associated with profile
  132. $this->_oModule->_oDb->deleteAdminsByProfileId($iProfileId);
  133. return parent::_delete ($mixedId);
  134. }
  135. /**
  136. * @return array where first element is group profile id and second element is some other persons profile id
  137. */
  138. protected function _prepareGroupProfileAndMemberProfile($iId1, $iId2)
  139. {
  140. if (BxDolProfile::getInstance($iId1)->getModule() == $this->_sContentModule)
  141. return array($iId1, $iId2);
  142. else
  143. return array($iId2, $iId1);
  144. }
  145. }
  146. /** @} */