BxBaseModGroupsGridBans.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsGridBans extends BxDolGridConnections
  12. {
  13. protected $_oModule;
  14. protected $_sContentModule;
  15. protected $_iGroupProfileId;
  16. protected $_aContentInfo = [];
  17. protected $_bManageMembers;
  18. public function __construct ($aOptions, $oTemplate = false)
  19. {
  20. $this->_oModule = BxDolModule::getInstance($this->_sContentModule);
  21. $this->_sObjectConnections = 'sys_profiles_bans';
  22. parent::__construct ($aOptions, $oTemplate);
  23. if(!$this->_bInit)
  24. return;
  25. $this->_iGroupProfileId = $this->_oProfile->id();
  26. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_oProfile->getContentId());
  27. if($this->_oModule->checkAllowedEdit($this->_aContentInfo) === CHECK_ACTION_RESULT_ALLOWED || $this->_iGroupProfileId == bx_get_logged_profile_id())
  28. $this->_bOwner = true;
  29. $this->_bManageMembers = $this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED || $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED;
  30. $aSQLParts = $this->_oConnection->getConnectedContentAsSQLParts('p', 'id', $this->_iGroupProfileId, $this->_bOwner ? false : true);
  31. $this->addMarkers(array(
  32. 'profile_id' => $this->_iGroupProfileId,
  33. 'join_connections' => $aSQLParts['join'],
  34. 'content_module' => $this->_sContentModule,
  35. ));
  36. }
  37. protected function _getCellAdded ($mixedValue, $sKey, $aField, $aRow)
  38. {
  39. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  40. }
  41. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  42. {
  43. if (!$this->_bManageMembers)
  44. return $this->_bIsApi ? [] : '';
  45. if (isset($aRow[$this->_aOptions['field_id']]))
  46. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  47. return parent::_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  48. }
  49. protected function _delete ($mixedId)
  50. {
  51. list($iProfileId, $iContextId) = $this->__prepareIds($mixedId);
  52. if($this->_oConnection->isConnected($iContextId, $iProfileId))
  53. $a = $this->_oConnection->removeConnection($iContextId, $iProfileId);
  54. if(isset($a['err']) && $a['err'])
  55. return false;
  56. return true;
  57. }
  58. }
  59. /** @} */