Преглед на файлове

#3560 - Attendant app improvements - add alerts

RomanL преди 4 години
родител
ревизия
ef536131ff

+ 7 - 2
modules/boonex/attendant/classes/BxAttendantAlertsResponse.php

@@ -18,10 +18,15 @@ class BxAttendantAlertsResponse extends BxDolAlertsResponse
     
     public function response($oAlert)
     {
+        $iObjectId  = $oAlert->iObject;
+        $iProfileId = bx_get_logged_profile_id();
+        
         if ($oAlert->sUnit == 'profile' && $oAlert->sAction == 'add'){
-            $oModule = BxDolModule::getInstance('bx_attendant');
-            $oModule->initPopupWithRecommendedOnProfileAdd($oAlert->iObject);
+            $iProfileId = $oAlert->iObject;
         }
+        
+        $oModule = BxDolModule::getInstance('bx_attendant');
+        $oModule->initPopupByEvent($iObjectId, $oAlert->sUnit, $oAlert->sAction, $iProfileId);
     }
 }
 

+ 4 - 2
modules/boonex/attendant/classes/BxAttendantConfig.php

@@ -22,11 +22,13 @@ class BxAttendantConfig extends BxBaseModGeneralConfig
             
              // database fields
             'FIELD_ID' => 'id',
-            'FIELD_METHOD' => 'method',
+            'FIELD_MODULE' => 'module',
             'FIELD_ACTION' => 'action',
+            'FIELD_EVENT' => 'event',
             'FIELD_ADDED' => 'added',
             'FIELD_PROCESSED' => 'processed',
-            'FIELD_OBJECT_ID' => 'object_id'
+            'FIELD_OBJECT_ID' => 'object_id',
+            'FIELD_PROFILE_ID' => 'profile_id'
         );
         $this->_aJsClasses = array(
            'main' => 'BxAttendant'

+ 12 - 8
modules/boonex/attendant/classes/BxAttendantDb.php

@@ -32,13 +32,13 @@ class BxAttendantDb extends BxBaseModGeneralDb
         $sSelectClause = "`{$this->_sTableEntries}`.*";
 
         switch($aParams['type']) {
-            case 'active_by_action_and_object_id':
+            case 'active_by_action_and_profile_id':
                 $aMethod['name'] = 'getAll';
                 $aMethod['params'][1] = array(
                     'action' => $aParams['action'],
-                    'object_id' => $aParams['object_id']
+                    'profile_id' => $aParams['profile_id']
                 );
-                $sWhereClause = "AND `{$this->_sTableEntries}`.`" . $CNF['FIELD_ACTION'] . "` =:action  AND `{$this->_sTableEntries}`.`" . $CNF['FIELD_OBJECT_ID'] . "` =:object_id AND `" . $CNF['FIELD_PROCESSED'] . "` IS NULL";
+                $sWhereClause = "AND `{$this->_sTableEntries}`.`" . $CNF['FIELD_ACTION'] . "` =:action  AND `{$this->_sTableEntries}`.`" . $CNF['FIELD_PROFILE_ID'] . "` =:profile_id AND `" . $CNF['FIELD_PROCESSED'] . "` IS NULL";
                 break;
             case 'all':
                 $aMethod['name'] = 'getAll';
@@ -62,16 +62,20 @@ class BxAttendantDb extends BxBaseModGeneralDb
         return array($aEntries, (int)call_user_func_array(array($this, $aMethod['name']), $aMethod['params']));
     }
     
-    public function addEvent($sMethod, $sAction, $iObjectId)
+    public function addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId)
     {
         $CNF = &$this->_oConfig->CNF;
         $aBindings = array(
-            'method' => $sMethod,
+            'module' => $sModule,
+            'event' => $sEvent,
             'action' => $sAction,
             'added' => time(),
-            'object_id' => $iObjectId
+            'object_id' => $iObjectId,
+            'profile_id' => $iProfileId,
+            'event' => $sEvent
         );
-        $this->query("INSERT INTO `" . $CNF['TABLE_ENTRIES'] . "` (`" . $CNF['FIELD_METHOD'] . "`, `" . $CNF['FIELD_ACTION'] . "`, `" . $CNF['FIELD_ADDED'] . "`, `" . $CNF['FIELD_OBJECT_ID'] . "`) values (:method, :action, :added, :object_id)", $aBindings);
+        
+        $this->query("INSERT INTO `" . $CNF['TABLE_ENTRIES'] . "` (`" . $CNF['FIELD_MODULE'] . "`, `" . $CNF['FIELD_EVENT'] . "`, `" . $CNF['FIELD_ACTION'] . "`, `" . $CNF['FIELD_ADDED'] . "`, `" . $CNF['FIELD_OBJECT_ID'] . "`, `" . $CNF['FIELD_PROFILE_ID'] . "`) values (:module, :event, :action, :added, :object_id, :profile_id)", $aBindings);
     }
     
     public function setEventProcessed($id)
@@ -80,7 +84,7 @@ class BxAttendantDb extends BxBaseModGeneralDb
         $aBindings = array(
             'processed' => time()
         );
-        $this->query("UPDATE `" . $CNF['TABLE_ENTRIES'] . "` SET   `" . $CNF['FIELD_PROCESSED'] . "` = :processed", $aBindings);
+       $this->query("UPDATE `" . $CNF['TABLE_ENTRIES'] . "` SET   `" . $CNF['FIELD_PROCESSED'] . "` = :processed", $aBindings);
     }
 }
 

+ 29 - 17
modules/boonex/attendant/classes/BxAttendantModule.php

@@ -20,23 +20,27 @@ class BxAttendantModule extends BxDolModule
     }
 
     
-    public function actionRecomendedPopup()
+    public function actionRecomendedPopup($sModule, $sEvent, $iObjectId)
     {
+        $sRv = '';
         $aModules = explode(',', getParam('bx_attendant_on_profile_creation_modules'));
-        $aModulteData = array();
+        $aModuleData = array();
         foreach($aModules as $sModuleName){
 
             if(BxDolRequest::serviceExists($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD)){
-                $aTmp = BxDolService::call($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD, array('unit_view' => 'showcase', 'empty_message' => false, "ajax_paginate" => false));
+                $aTmp = BxDolService::call($sModuleName, BX_ATTENDANT_ON_PROFILE_CREATION_METHOD, ['unit_view' => 'showcase', 'empty_message' => false, "ajax_paginate" => false]);
 
                 if (isset($aTmp['content'])){
                     $sTmp = $aTmp['content'];
                     $sTmp = str_replace('bx_conn_action', 'bx_attendant_conn_action', $sTmp);
-                    $aModulteData[$sModuleName] = $sTmp;
+                    $aModuleData[$sModuleName] = $sTmp;
                 }
             }
         }
-        $sRv = $this->_oTemplate->popupWithRecommendedOnProfileAdd($aModulteData);
+        if ($aModuleData)
+            $sRv = $this->_oTemplate->popup($aModuleData);
+        
+        bx_alert('bx_attendant', 'show_popup', bx_get_logged_profile_id(), 0, ['module' => $sModule, 'event' => $sEvent, 'object_id' => $iObjectId, 'result' => &$sRv]);
         
         echo $sRv;
     }
@@ -156,9 +160,10 @@ class BxAttendantModule extends BxDolModule
         if (!isLogged())
             return;
         
-        $aEvents = $this->_oDb->getEvents(array('type' => 'active_by_action_and_object_id', 'action' => 'view', 'object_id' => bx_get_logged_profile_id()));
+        $aEvents = $this->_oDb->getEvents(array('type' => 'active_by_action_and_profile_id', 'action' => 'view', 'profile_id' => bx_get_logged_profile_id()));
         foreach($aEvents as $aEvent){
-            $oRv = call_user_func_array(array($this, $aEvent['method']), array($aEvent['object_id']));
+            //$oRv = call_user_func_array(array($this, $aEvent['method']), array($aEvent['object_id']));
+            $oRv = $this->processPopupOnEvent($aEvent);
             if ($oRv !== false){
                 $sRv .= $oRv;
                 $this->_oDb->setEventProcessed($aEvent['id']);
@@ -173,28 +178,35 @@ class BxAttendantModule extends BxDolModule
        //for some other actions fex cron - not implemented
     }
     
-    public function addEvent($sMethod, $sAction, $iObjectId)
+    public function addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId)
     {
-        $this->_oDb->addEvent($sMethod, $sAction, $iObjectId);
+        $this->_oDb->addEvent($sAction, $iObjectId, $sModule, $sEvent, $iProfileId);
     }
     
-    public function initPopupWithRecommendedOnProfileAdd($iProfileId)
+    public function initPopupByEvent($iObjectId, $sModule, $sEvent, $iProfileId)
     {
-        $this->addEvent('processPopupWithRecommendedOnProfileAdd', 'view', $iProfileId);
+        $this->addEvent('view', $iObjectId, $sModule, $sEvent, $iProfileId);
     }
     
-    public function processPopupWithRecommendedOnProfileAdd($iProfileId)
+    public function processPopupOnEvent($aEvent)
     {
         $sRv = '';
-        $sEvent = getParam('bx_attendant_on_profile_event_list');
-        $oProfile = BxDolProfile::getInstance($iProfileId);
+        $sDefaultEvent = getParam('bx_attendant_on_profile_event_list');
+        $oProfile = BxDolProfile::getInstance($aEvent['profile_id']);
         $oAccount = $oProfile ? $oProfile->getAccountObject() : null;
-        if ($sEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION || ($sEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION  && $oAccount != null &&  $oAccount->isConfirmed())){
-            return '<script>oBxAttendant.showPopupWithRecommended()</script>';
+        $bNeedRaiseEvent = false;
+        if ($aEvent['event'] == 'add' && $aEvent['module'] == 'profile'){
+            if (getParam('bx_attendant_on_profile_creation_modules') != '' && ($sDefaultEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_REGISTRATION || ($sDefaultEvent == BX_ATTENDANT_ON_PROFILE_CREATION_EVENT_AFTER_CONFIRMATION  && $oAccount != null &&  $oAccount->isConfirmed()))){
+                $bNeedRaiseEvent = true;
+            }
         }
         else{
-            return false;
+            bx_alert('bx_attendant', 'before_show_popup', bx_get_logged_profile_id(), 0, ['module' => $aEvent['module'], 'event' => $aEvent['event'], 'object_id' => $aEvent['object_id'], 'result' => &$bNeedRaiseEvent]);
         }
+        if ($bNeedRaiseEvent)
+            return getParam('bx_attendant_on_profile_creation_modules').'<script>oBxAttendant.showPopup("' . $aEvent['module'] . '", "' . $aEvent['event'] . '", ' . $aEvent['object_id'] . ')</script>';
+        else
+            return false;
     }
 }
 

+ 1 - 1
modules/boonex/attendant/classes/BxAttendantTemplate.php

@@ -37,7 +37,7 @@ class BxAttendantTemplate extends BxBaseModGeneralTemplate
         return $this->getJsCode('main') . BxBaseFunctions::getInstance()->transBox($this->sContainerId, '', true, true);
     }
     
-    public function popupWithRecommendedOnProfileAdd($aModuleData)
+    public function popup($aModuleData)
     {
         $aVars = [];
         

+ 3 - 0
modules/boonex/attendant/install/sql/install.sql

@@ -4,10 +4,13 @@ SET @sName = 'bx_attendant';
 CREATE TABLE `bx_attendant_events` (
   `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
   `method` varchar(50) NOT NULL,
+  `event` varchar(50) NOT NULL,
   `added` int(11) DEFAULT NULL,
   `processed` int(11) DEFAULT NULL,
   `action` varchar(10) NOT NULL,
   `object_id` int(11) DEFAULT NULL,
+  `profile_id` int(11) DEFAULT NULL,
+  `module` varchar(50) NOT NULL,
   PRIMARY KEY (`id`),
   INDEX `object_id` (`object_id`),
   INDEX `action` (`action`)

+ 3 - 2
modules/boonex/attendant/js/main.js

@@ -15,11 +15,11 @@ function BxAttendant(oOptions) {
     var $this = this;
 }
 
-BxAttendant.prototype.showPopupWithRecommended = function () {
+BxAttendant.prototype.showPopup = function (sModule = '', sEvent = '', sObject = 0) {
     var $this = this;
     
     $(window).dolPopupAjax({
-        url: $this._sActionsUri + '/RecomendedPopup',
+        url: $this._sActionsUri + '/RecomendedPopup/' + sModule + '/' + sEvent + '/' + sObject + '/',
         closeOnOuterClick: true,
 		removeOnClose: true,
         onLoad: function(sPopupSelector){
@@ -37,6 +37,7 @@ BxAttendant.prototype.showPopupWithRecommended = function () {
                     }
                 }
             });
+            
         }
     });
 }