BxInvResponse.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. $sKeyCode = $this->_oModule->_oConfig->getKeyCode();
  42. $sKey = BxDolSession::getInstance()->getUnsetValue($sKeyCode);
  43. if($sKey === false)
  44. return;
  45. $this->_oModule->attachAccountIdToInvite($oAlert->iObject, $sKey);
  46. $sKeysToRemove = $this->_oModule->_oDb->getInvites(array('type' => 'invites_code_by_single', 'value' => $sKey));
  47. $aKeysToRemove = explode(',', $sKeysToRemove);
  48. $oKeys = BxDolKey::getInstance();
  49. if($oKeys){
  50. foreach($aKeysToRemove as $sKeyToRemove) {
  51. if($oKeys->isKeyExists($sKeyToRemove))
  52. $oKeys->removeKey($sKeyToRemove);
  53. }
  54. }
  55. return;
  56. }
  57. protected function _processProfileAdd($oAlert)
  58. {
  59. if (getParam('bx_invites_automatically_befriend') != 'on')
  60. return;
  61. $oProfile = BxDolProfile::getInstanceMagic($oAlert->iObject);
  62. if ($oProfile && $oProfile->isActAsProfile()){
  63. $iProfileInvitor = $this->_oModule->_oDb->getInvites(array('type' => 'profile_id_by_joined_account_id', 'value' => $oProfile->getAccountId()));
  64. if ($iProfileInvitor){
  65. $oConnFrinds = BxDolConnection::getObjectInstance('sys_profiles_friends');
  66. $oConnFrinds->addConnection($oAlert->iObject, $iProfileInvitor);
  67. $oConnFrinds->addConnection($iProfileInvitor, $oAlert->iObject);
  68. }
  69. }
  70. }
  71. protected function _processProfileDelete($oAlert)
  72. {
  73. $this->_oModule->_oDb->deleteInvites(array('profile_id' => $oAlert->iObject));
  74. }
  75. protected function _processAccountDelete($oAlert)
  76. {
  77. $this->_oModule->_oDb->deleteInvitesByAccount(array('joined_account_id' => $oAlert->iObject));
  78. }
  79. protected function _processBxAnalyticsGetModules($oAlert)
  80. {
  81. $oAlert->aExtras['list'][$this->_oModule->_aModule['name']] = $this->_oModule->_aModule['title'];
  82. }
  83. protected function _processBxAnalyticsGetReports($oAlert)
  84. {
  85. if ($this->_oModule->_aModule['name'] == $oAlert->aExtras['module']){
  86. $oAlert->aExtras['list'] = array();
  87. $oAlert->aExtras['list']['content_total_invited'] = _t('_bx_invites_reports_for_analytics_invited_total');
  88. $oAlert->aExtras['list']['content_speed_invited'] = _t('_bx_invites_reports_for_analytics_invited_speed_grows');
  89. $oAlert->aExtras['list']['content_total_invitation'] = _t('_bx_invites_reports_for_analytics_invitation_total');
  90. $oAlert->aExtras['list']['content_speed_invitation'] = _t('_bx_invites_reports_for_analytics_invitation_speed_grows');
  91. }
  92. }
  93. protected function _processBxAnalyticsGetChartDataLine($oAlert)
  94. {
  95. if ($this->_oModule->_aModule['name'] == $oAlert->aExtras['module']){
  96. $bIsInvited = false;
  97. if (substr_count($oAlert->aExtras['report_name'], '_invited') > 0)
  98. $bIsInvited = true;
  99. if (substr_count($oAlert->aExtras['report_name'], '_total_') > 0)
  100. $oAlert->aExtras['report_type'] = BX_ANALYTICS_CONTENT_TOTAL;
  101. $oAlert->aExtras['data'] = $this->_oModule->_oDb->getDataForCharts($oAlert->aExtras['date_from'], $oAlert->aExtras['date_to'], $bIsInvited);
  102. $oAlert->aExtras['prev_value'] = $this->_oModule->_oDb->getInitValueForCharts($oAlert->aExtras['date_from'], $bIsInvited);
  103. }
  104. }
  105. }
  106. /** @} */