1
0

BxBaseModGroupsGridInvites.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 BxBaseModGroupsGridinvites extends BxTemplGrid
  12. {
  13. protected $_oModule;
  14. protected $_sContentModule;
  15. protected $_iGroupProfileId;
  16. protected $_bManageMembers;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. $this->_oModule = BxDolModule::getInstance($this->_sContentModule);
  20. parent::__construct ($aOptions, $oTemplate);
  21. $this->_iGroupProfileId = 0;
  22. if(($iProfileId = bx_get('profile_id')) !== false)
  23. $this->_iGroupProfileId = (int)$iProfileId;
  24. $this->_bManageMembers = $this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED || $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED;
  25. $this->_aQueryAppend['profile_id'] = $this->_iGroupProfileId;
  26. }
  27. public function getCode ($isDisplayHeader = true)
  28. {
  29. if(!$this->_bManageMembers)
  30. return '';
  31. return parent::getCode($isDisplayHeader);
  32. }
  33. public function getCodeAPI()
  34. {
  35. if(!$this->_bManageMembers)
  36. return [];
  37. return parent::getCodeAPI();
  38. }
  39. protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
  40. {
  41. $oProfile = BxDolProfile::getInstance($aRow['invited_profile_id']);
  42. if(!$oProfile && ($sMessage = _t('_sys_txt_error_occured')) !== false)
  43. return $this->_bIsApi ? ['type' => 'text', 'value' => $sMessage] : $sMessage;
  44. if($this->_bIsApi)
  45. return ['type' => 'profile', 'data' => BxDolProfile::getData($oProfile->id())];
  46. return parent::_getCellDefault ($oProfile->getUnit(), $sKey, $aField, $aRow);
  47. }
  48. protected function _getCellAdded ($mixedValue, $sKey, $aField, $aRow)
  49. {
  50. if($this->_bIsApi)
  51. return ['type' => 'time', 'data' => $mixedValue];
  52. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  53. }
  54. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  55. {
  56. $iLoggedId = bx_get_logged_profile_id();
  57. $aCheck = checkActionModule($iLoggedId, 'delete invites', $this->_sContentModule, false);
  58. if($aRow['author_profile_id'] != $iLoggedId && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  59. return $this->_bIsApi ? [] : '';
  60. return parent::_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  61. }
  62. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  63. {
  64. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `group_profile_id` = ?", (int)bx_get('profile_id'));
  65. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  66. }
  67. }
  68. /** @} */