Browse code

Add token for firstname and lastname of member

Benjamin Roth authored on22/06/2017 11:28:32
Showing1 changed files
... ...
@@ -67,6 +67,8 @@ class NewsNotifications extends \System
67 67
                 $Notification->send(array
68 68
                 (
69 69
                   'member_email'      => $Members->email,
70
+                  'member_firstname' => $Members->firstname,
71
+                  'member_lastname' => $Members->lastname,
70 72
                   'news_topics'       => implode("\n",$arrNews),
71 73
                   'news_topics_html'  => "<ul>\n<li>".implode("</li>\n<li>",$arrNews)."</li>\n</ul>"
72 74
                 ),
Browse code

Return unordered list instead of plain text with breaks

Benjamin Roth authored on22/06/2017 11:23:40
Showing1 changed files
... ...
@@ -41,6 +41,7 @@ class NewsNotifications extends \System
41 41
         // Load groups and notification models if we have news to share
42 42
         if ($News->numRows && ($Notification = \NotificationCenter\Model\Notification::findByPk($Archive->nc_notification)) !== null && ($Groups = \MemberGroupModel::findMultipleByIds($arrGroupIds)) !== null)
43 43
         {
44
+
44 45
           while ($Groups->next())
45 46
           {
46 47
             // Skip disabled groups
... ...
@@ -55,18 +56,19 @@ class NewsNotifications extends \System
55 56
             // Send notification to each member
56 57
             if ($Members !== null)
57 58
             {
58
-              $strNews = '';
59
+              $arrNews = array();
60
+              $News->reset();
59 61
               while ($News->next())
60 62
               {
61
-                $strNews .= date('d.m.Y',$News->date)." - ".$News->headline."\n";
63
+                $arrNews[] = date('d.m.Y',$News->date)." - ".$News->headline;
62 64
               }
63 65
               while ($Members->next())
64 66
               {
65 67
                 $Notification->send(array
66 68
                 (
67 69
                   'member_email'      => $Members->email,
68
-                  'news_topics'       => $strNews,
69
-                  'news_topics_html'  => nl2br($strNews)
70
+                  'news_topics'       => implode("\n",$arrNews),
71
+                  'news_topics_html'  => "<ul>\n<li>".implode("</li>\n<li>",$arrNews)."</li>\n</ul>"
70 72
                 ),
71 73
                 $GLOBALS['TL_LANGUAGE']);
72 74
               }
Browse code

Initial commit

Benjamin Roth authored on15/07/2016 13:35:34
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,83 @@
1
+<?php
2
+
3
+/**
4
+ * News notification extension for Contao
5
+ *
6
+ * Copyright (c) 2016 Benjamin Roth
7
+ *
8
+ * @link    http://www.esales-media.de
9
+ * @license commercial
10
+ */
11
+
12
+namespace eSM_nc_news;
13
+
14
+class NewsNotifications extends \System
15
+{
16
+  /**
17
+   * Make the constuctor public
18
+   */
19
+  public function __construct()
20
+  {
21
+    parent::__construct();
22
+  }
23
+
24
+  public function sendNotifications()
25
+  {
26
+    // Get archives with notifications enabled
27
+    $Archives = \NewsArchiveModel::findBy('nc_enable','1');
28
+
29
+    if ($Archives !== null)
30
+    {
31
+      while ($Archives->next())
32
+      {
33
+        $Archive = $Archives->current();
34
+        $arrGroupIds = deserialize($Archive->nc_notification_groups,true);
35
+        $time = \Date::floorToMinute();
36
+
37
+        // Do we have new news items
38
+        $News = \Database::getInstance()->prepare("SELECT id, headline, date FROM tl_news WHERE pid = ? AND nc_sent != '1' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY date DESC, time DESC")
39
+                                        ->execute($Archive->id);
40
+
41
+        // Load groups and notification models if we have news to share
42
+        if ($News->numRows && ($Notification = \NotificationCenter\Model\Notification::findByPk($Archive->nc_notification)) !== null && ($Groups = \MemberGroupModel::findMultipleByIds($arrGroupIds)) !== null)
43
+        {
44
+          while ($Groups->next())
45
+          {
46
+            // Skip disabled groups
47
+            if ($Groups->disable)
48
+            {
49
+              continue;
50
+            }
51
+
52
+            // Get group members
53
+            $Members = \MemberModel::findBy(array("groups LIKE '%\"".$Groups->id."\"%'","login='1' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND disable=''"),null);
54
+
55
+            // Send notification to each member
56
+            if ($Members !== null)
57
+            {
58
+              $strNews = '';
59
+              while ($News->next())
60
+              {
61
+                $strNews .= date('d.m.Y',$News->date)." - ".$News->headline."\n";
62
+              }
63
+              while ($Members->next())
64
+              {
65
+                $Notification->send(array
66
+                (
67
+                  'member_email'      => $Members->email,
68
+                  'news_topics'       => $strNews,
69
+                  'news_topics_html'  => nl2br($strNews)
70
+                ),
71
+                $GLOBALS['TL_LANGUAGE']);
72
+              }
73
+            }
74
+
75
+            // Flag news as sent
76
+            $arrNewsIds = $News->fetchEach('id');
77
+            \Database::getInstance()->execute("UPDATE tl_news SET nc_sent = '1' WHERE id IN (".implode(',',$arrNewsIds).")");
78
+          }
79
+        }
80
+      }
81
+    }
82
+  }
83
+}
0 84
\ No newline at end of file