BxInvResponse.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Invites Invites
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxInvResponse extends BxDolAlertsResponse
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_sModule = 'bx_invites';
  19. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  20. }
  21. /**
  22. * Overwtire the method of parent class.
  23. *
  24. * @param BxDolAlerts $oAlert an instance of alert.
  25. */
  26. public function response($oAlert)
  27. {
  28. $sMethod = '_process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
  29. if(!method_exists($this, $sMethod))
  30. return;
  31. return $this->$sMethod($oAlert);
  32. }
  33. protected function _processAccountAddForm($oAlert)
  34. {
  35. $sCode = $this->_oModule->serviceAccountAddFormCheck();
  36. if($sCode)
  37. $oAlert->aExtras['form_code'] = $sCode;
  38. }
  39. protected function _processAccountAdded($oAlert)
  40. {
  41. if(!$this->_oModule->_oConfig->isRegistrationByInvitation())
  42. return;
  43. $sKeyCode = $this->_oModule->_oConfig->getKeyCode();
  44. $sKey = BxDolSession::getInstance()->getUnsetValue($sKeyCode);
  45. if($sKey === false)
  46. return;
  47. $this->_oModule->attachAccountIdToInvite($oAlert->iObject, $sKey);
  48. $sKeysToRemove = $this->_oModule->_oDb->getInvites(array('type' => 'invites_code_by_single', 'value' => $sKey));
  49. $aKeysToRemove = explode(',', $sKeysToRemove);
  50. $oKeys = BxDolKey::getInstance();
  51. if($oKeys){
  52. foreach($aKeysToRemove as $sKeyToRemove) {
  53. if($oKeys->isKeyExists($sKeyToRemove))
  54. $oKeys->removeKey($sKeyToRemove);
  55. }
  56. }
  57. return;
  58. }
  59. protected function _processProfileDelete($oAlert)
  60. {
  61. $this->_oModule->_oDb->deleteInvites(array('profile_id' => $oAlert->iObject));
  62. }
  63. }
  64. /** @} */