Преглед изворни кода

Ticket #4039 - Events: Remake event Reminders.

AntonLV пре 4 година
родитељ
комит
093b2fee0a

+ 2 - 6
modules/base/groups/classes/BxBaseModGroupsAlertsResponse.php

@@ -15,16 +15,12 @@ class BxBaseModGroupsAlertsResponse extends BxBaseModProfileAlertsResponse
      * Use Internal Notifications.
      */
     protected $_bUseIn;
-    
+
     public function __construct()
     {
         parent::__construct();
 
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        $this->_bUseIn = true;
-        if(isset($CNF['PARAM_USE_IN']))
-            $this->_bUseIn = getParam($CNF['PARAM_USE_IN']) == 'on';
+        $this->_bUseIn = $this->_oModule->_oConfig->isInternalNotifications();
     }
 
     public function response($oAlert)

+ 5 - 0
modules/base/groups/classes/BxBaseModGroupsConfig.php

@@ -71,6 +71,11 @@ class BxBaseModGroupsConfig extends BxBaseModProfileConfig
         return isset($this->CNF['PARAM_PAID_JOIN_ENABLED']) && $this->CNF['PARAM_PAID_JOIN_ENABLED'] === true;
     }
 
+    public function isInternalNotifications()
+    {
+        return !isset($this->CNF['PARAM_USE_IN']) || getParam($this->CNF['PARAM_USE_IN']) == 'on';
+    }
+
     public function getPriceName($sName)
     {
         return uriGenerate($sName, $this->CNF['TABLE_PRICES'], $this->CNF['FIELD_PRICE_NAME'], ['lowercase' => false]);

+ 9 - 4
modules/boonex/events/classes/BxEventsFormEntry.php

@@ -15,7 +15,7 @@
 class BxEventsFormEntry extends BxBaseModGroupsFormEntry
 {
     protected static $_isCssJsEventsAdded = false;
-    
+
     protected $_iContentId = 0;
 
     public function __construct($aInfo, $oTemplate = false)
@@ -23,6 +23,8 @@ class BxEventsFormEntry extends BxBaseModGroupsFormEntry
         $this->MODULE = 'bx_events';
         parent::__construct($aInfo, $oTemplate);
 
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
         if (isset($this->aInputs['reoccurring'])) {
             $this->aInputs['reoccurring']['ghost_template'] = array (
                 
@@ -107,9 +109,12 @@ class BxEventsFormEntry extends BxBaseModGroupsFormEntry
             );
         }
 
-        if (isset($this->aInputs['timezone']) && !$this->aParams['view_mode']) {
-            $this->aInputs['timezone']['values'] = array_combine(timezone_identifiers_list(), timezone_identifiers_list());
-        }        
+        if (isset($this->aInputs[$CNF['FIELD_TIMEZONE']]) && !$this->aParams['view_mode']) {
+            $this->aInputs[$CNF['FIELD_TIMEZONE']]['values'] = array_combine(timezone_identifiers_list(), timezone_identifiers_list());
+        }
+
+        if(isset($this->aInputs[$CNF['FIELD_REMINDER']]) && !$this->_oModule->_oConfig->isInternalNotifications())
+            unset($this->aInputs[$CNF['FIELD_REMINDER']]);
     }
 
     function getCode($bDynamicMode = false)

+ 93 - 5
modules/boonex/events/classes/BxEventsModule.php

@@ -303,18 +303,106 @@ class BxEventsModule extends BxBaseModGroupsModule implements iBxDolCalendarServ
      */
     public function serviceProcessReminders()
     {
+        $CNF = &$this->_oConfig->CNF;
+
         $iNow = time();
+        $bUseIn = $this->_oConfig->isInternalNotifications();
+        $sModule = $this->getName();
 
         // get all events for today and tomorrow, since the max reminder is 24 hours
         $aEntries = $this->_oDb->getEntriesByDate('@' . time(), '@' . (time() + 3600 * getParam('bx_events_reminder_interval')));
 
-        foreach ($aEntries as $a) {
-            if (!$a['reminder'])
+        foreach($aEntries as $aEntry) {
+            $aReminders = $bUseIn ? [$aEntry['reminder']] : [24, 1];
+            if(!$aReminders)
                 continue;
-            $iTimestamp = $a['start_utc'] - (3600 * $a['reminder']);
-            if ($iNow > ($iTimestamp - 3600) && $iNow < $iTimestamp)
-                $this->sendReminders($a);
+
+            $oEventProfile = BxDolProfile::getInstanceByContentAndType($aEntry[$CNF['FIELD_ID']], $sModule);
+            if(!$oEventProfile)
+                continue;
+
+            $iEventProfileId = $oEventProfile->id();
+            foreach($aReminders as $iReminder) {
+                $iTimestamp = $aEntry['start_utc'] - (3600 * $iReminder);
+                if($iNow <= ($iTimestamp - 3600) || $iNow >= $iTimestamp)
+                    continue;
+
+                if($bUseIn)
+                    $this->sendReminders($aEntry);
+
+                bx_alert($sModule, 'reminder', $aEntry[$CNF['FIELD_ID']], $iEventProfileId, array(
+                    'object_author_id' => $iEventProfileId,
+                    'reminder' => $iReminder
+                ));
+            }
+        }
+    }
+
+    public function serviceGetNotificationsData()
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aResults = parent::serviceGetNotificationsData();
+        
+        $sModule = $this->_aModule['name'];
+        $aSettingsTypes = ['follow_context'];
+
+        $aResults['handlers'] = array_merge($aResults['handlers'], [
+            ['group' => $sModule . '_reminder', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'reminder', 'module_name' => $sModule, 'module_method' => 'get_notifications_reminder', 'module_class' => 'Module', 'module_event_privacy' => $CNF['OBJECT_PRIVACY_VIEW_NOTIFICATION_EVENT']],
+        ]);
+
+        $aResults['settings'] = array_merge($aResults['settings'], [
+            ['group' => 'reminder', 'unit' => $sModule, 'action' => 'reminder', 'types' => $aSettingsTypes],
+        ]);
+
+        $aResults['alerts'] = array_merge($aResults['alerts'], [
+            ['unit' => $sModule, 'action' => 'reminder'],
+        ]);
+
+        return $aResults;
+    }
+
+    public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
+    {
+        if($oAlert->sAction != 'reminder' || empty($aDataItems) || !is_array($aDataItems) || empty($oAlert->aExtras['reminder']))
+            return $aDataItems;
+
+        foreach($aDataItems as $iIndex => $aDataItem) {
+            $aContent = [];
+            if(!empty($aDataItem['content']))
+                $aContent = unserialize($aDataItem['content']);
+
+            $aContent['reminder'] = (int)$oAlert->aExtras['reminder'];
+
+            $aDataItems[$iIndex]['content'] = serialize($aContent);
         }
+
+        return $aDataItems;
+    }
+
+    public function serviceGetNotificationsReminder($aEvent)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!isset($aEvent['content']['reminder']))
+            return [];
+
+        $iContentId = (int)$aEvent['object_id'];
+        $oEventProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
+        if(!$oEventProfile)
+            return [];
+
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo) || !is_array($aContentInfo))
+            return [];
+
+        return [
+            'entry_sample' => $CNF['T']['txt_sample_single'],
+            'entry_url' => str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oEventProfile->getUrl()),
+            'entry_caption' => $oEventProfile->getDisplayName(),
+            'entry_author' => $oEventProfile->id(),
+            'lang_key' => '_bx_events_txt_ntfs_reminder_' . $aEvent['content']['reminder']
+        ];
     }
 
     /**

+ 5 - 1
modules/boonex/events/install/langs/en.xml

@@ -76,7 +76,7 @@
     <string name="_bx_events_form_profile_input_timezone"><![CDATA[Timezone]]></string>
     <string name="_bx_events_form_profile_input_sys_time"><![CDATA[Time]]></string>
     <string name="_bx_events_form_profile_input_time"><![CDATA[Time]]></string>
-    <string name="_bx_events_form_profile_input_sys_reminder"><![CDATA[Reminder]]></string>
+    <string name="_bx_events_form_profile_input_sys_reminder"><![CDATA[Reminder (part of Internal Notifications)]]></string>
     <string name="_bx_events_form_profile_input_reminder"><![CDATA[Reminder]]></string>
 
     <string name="_bx_events_form_input_repeat_year"><![CDATA[Repeat year]]></string>
@@ -442,8 +442,12 @@
     <string name="_bx_events_txt_ntfs_fan_added"><![CDATA[Event <b class="bx-ntfs-content-profile">{owner_name}</b> has got a member <b class="bx-ntfs-content-entry">{subentry_sample}</b>]]></string>
     <string name="_bx_events_alert_action_join_invitation_notif"><![CDATA[join invitation]]></string>
     <string name="_bx_events_alert_action_join_request"><![CDATA[join request]]></string>
+    <string name="_bx_events_alert_action_reminder"><![CDATA[reminder]]></string>
+    <string name="_bx_events_alert_action_reminder_follow_context"><![CDATA[New reminders]]></string>
     <string name="_bx_events_txt_ntfs_join_invitation"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> event's representative invites <b class="bx-ntfs-content-entry">{subentry_sample}</b> to join event]]></string>
     <string name="_bx_events_txt_ntfs_join_request"><![CDATA[Event <b class="bx-ntfs-content-profile">{owner_name}</b> has a join request from <b class="bx-ntfs-content-entry">{subentry_sample}</b>]]></string>
+    <string name="_bx_events_txt_ntfs_reminder_1"><![CDATA[Event <b class="bx-ntfs-content-profile">{owner_name}</b> starts in an hour]]></string>
+    <string name="_bx_events_txt_ntfs_reminder_24"><![CDATA[Event <b class="bx-ntfs-content-profile">{owner_name}</b> starts in 24 hours]]></string>
     <string name="_bx_events_txt_ntfs_timeline_post_common"><![CDATA[New post <b class="bx-ntfs-content-entry">{subentry_sample}</b> in <b class="bx-ntfs-content-profile">{owner_name}</b> event timeline]]></string>
 
     <string name="_bx_events_privacy_group_closed"><![CDATA[Closed]]></string>

+ 5 - 1
modules/boonex/russian/data/langs/bx_events/ru.xml

@@ -75,7 +75,7 @@
     <string name="_bx_events_form_profile_input_timezone"><![CDATA[Часовой пояс]]></string>
     <string name="_bx_events_form_profile_input_sys_time"><![CDATA[Время]]></string>
     <string name="_bx_events_form_profile_input_time"><![CDATA[Время]]></string>
-    <string name="_bx_events_form_profile_input_sys_reminder"><![CDATA[Напоминание]]></string>
+    <string name="_bx_events_form_profile_input_sys_reminder"><![CDATA[Напоминание (часть встроенних нотификаций)]]></string>
     <string name="_bx_events_form_profile_input_reminder"><![CDATA[Напоминание]]></string>
     <string name="_bx_events_form_profile_input_allow_view_favorite_list"><![CDATA[Видимость]]></string>
     
@@ -384,8 +384,12 @@
     <string name="_bx_events_txt_ntfs_fan_added"><![CDATA[У события <b class="bx-ntfs-content-profile">{owner_name}</b> новый участник <b class="bx-ntfs-content-entry">{subentry_sample}</b>]]></string>
     <string name="_bx_events_alert_action_join_invitation_notif"><![CDATA[приглашение вступить в группу]]></string>
     <string name="_bx_events_alert_action_join_request"><![CDATA[запрос на присоединение к событию]]></string>
+    <string name="_bx_events_alert_action_reminder"><![CDATA[напоминание]]></string>
+    <string name="_bx_events_alert_action_reminder_follow_context"><![CDATA[Новые напоминания]]></string>
     <string name="_bx_events_txt_ntfs_join_invitation"><![CDATA[Представитель события <b class="bx-ntfs-content-profile">{owner_name}</b> пригласил <b class="bx-ntfs-content-entry">{subentry_sample}</b> присоединиться к событию]]></string>
     <string name="_bx_events_txt_ntfs_join_request"><![CDATA[У события <b class="bx-ntfs-content-profile">{owner_name}</b> новый запрос на присоединение от <b class="bx-ntfs-content-entry">{subentry_sample}</b>]]></string>
+    <string name="_bx_events_txt_ntfs_reminder_1"><![CDATA[Событие <b class="bx-ntfs-content-profile">{owner_name}</b> начнется через час]]></string>
+    <string name="_bx_events_txt_ntfs_reminder_24"><![CDATA[Событие <b class="bx-ntfs-content-profile">{owner_name}</b> начнется через 24 часа]]></string>
     <string name="_bx_events_txt_ntfs_timeline_post_common"><![CDATA[В событии <b class="bx-ntfs-content-profile">{owner_name}</b> новая публикация <b class="bx-ntfs-content-entry">{subentry_sample}</b>]]></string>
 
     <string name="_bx_events_privacy_group_closed"><![CDATA[Закрытое событие]]></string>