BxInvGridRequests.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 Invites Invites
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModule');
  12. bx_import('BxTemplGrid');
  13. class BxInvGridRequests extends BxTemplGrid
  14. {
  15. protected $_sModule;
  16. protected $_oModule;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. parent::__construct ($aOptions, $oTemplate);
  20. $this->_sModule = 'bx_invites';
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. }
  23. public function performActionInvite($aParams = array())
  24. {
  25. $iProfileId = $this->_oModule->getProfileId();
  26. $mixedAllowed = $this->_oModule->isAllowedInvite($iProfileId);
  27. if($mixedAllowed !== true) {
  28. $this->_echoResultJson(array('msg' => $mixedAllowed));
  29. exit;
  30. }
  31. $iAffected = 0;
  32. $aIds = bx_get('ids');
  33. if(!$aIds || !is_array($aIds)) {
  34. $this->_echoResultJson(array());
  35. exit;
  36. }
  37. $sText = _t('_bx_invites_msg_invitation');
  38. $aIdsAffected = array ();
  39. foreach($aIds as $iId) {
  40. $aRequest = $this->_oModule->_oDb->getRequests(array('type' => 'by_id', 'value' => $iId));
  41. if(empty($aRequest) || !is_array($aRequest))
  42. continue;
  43. $mixedResult = $this->_oModule->invite($aRequest['email'], $sText);
  44. if($mixedResult === false)
  45. continue;
  46. $this->_oModule->isAllowedInvite($iProfileId, true);
  47. $aIdsAffected[] = $iId;
  48. $iAffected++;
  49. }
  50. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected, 'msg' => _t('_bx_invites_msg_invitation_sent', $iAffected)) : array('msg' => _t('_bx_invites_err_invite')));
  51. }
  52. public function performActionDelete($aParams = array())
  53. {
  54. $iProfileId = $this->_oModule->getProfileId();
  55. $mixedAllowed = $this->_oModule->isAllowedDeleteRequest($iProfileId);
  56. if($mixedAllowed !== true) {
  57. $this->_echoResultJson(array('msg' => $mixedAllowed));
  58. exit;
  59. }
  60. $iAffected = 0;
  61. $aIds = bx_get('ids');
  62. if(!$aIds || !is_array($aIds)) {
  63. $this->_echoResultJson(array());
  64. exit;
  65. }
  66. bx_import('BxDolForm');
  67. $oForm = BxDolForm::getObjectInstance($this->_oModule->_oConfig->getObject('form_request'), $this->_oModule->_oConfig->getObject('form_display_request_send'));
  68. $aIdsAffected = array ();
  69. foreach($aIds as $iId) {
  70. if(!$oForm->delete($iId))
  71. continue;
  72. $this->_oModule->isAllowedDeleteRequest($iProfileId, true);
  73. $aIdsAffected[] = $iId;
  74. $iAffected++;
  75. }
  76. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_bx_invites_err_delete_request')));
  77. }
  78. protected function _getCellNip($mixedValue, $sKey, $aField, $aRow)
  79. {
  80. return parent::_getCellDefault(long2ip($mixedValue), $sKey, $aField, $aRow);
  81. }
  82. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  83. {
  84. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  85. }
  86. }
  87. /** @} */