Browse code

Initial commit

Benjamin Roth authored on15/07/2016 13:35:34
Showing9 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
1 85
new file mode 100644
... ...
@@ -0,0 +1,21 @@
1
+;;
2
+; List modules which are required to be loaded beforehand
3
+;;
4
+requires[] = "core"
5
+requires[] = "news"
6
+requires[] = "notification_center"
7
+
8
+;;
9
+; Configure what you want the autoload creator to register
10
+;;
11
+register_namespaces = true
12
+register_classes    = true
13
+register_templates  = true
14
+
15
+;;
16
+; Override the default configuration for certain sub directories
17
+;;
18
+[vendor/*]
19
+register_namespaces = false
20
+register_classes    = false
21
+register_templates  = false
0 22
new file mode 100644
... ...
@@ -0,0 +1,38 @@
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
+/**
13
+ * Register the namespaces
14
+ */
15
+ClassLoader::addNamespaces(array
16
+(
17
+	'eSM_nc_news',
18
+));
19
+
20
+/**
21
+ * Register the classes
22
+ */
23
+ClassLoader::addClasses(array
24
+(
25
+  /**
26
+   * Classes
27
+   */
28
+  'eSM_nc_news\NewsNotifications' => 'system/modules/eSM_nc_news/classes/NewsNotifications.php',
29
+
30
+));
31
+
32
+/**
33
+ * Register the templates
34
+ */
35
+TemplateLoader::addFiles(array
36
+(
37
+
38
+));
0 39
new file mode 100644
... ...
@@ -0,0 +1,31 @@
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
+$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['contao'] = array
13
+(
14
+  // Type
15
+  'news_submitted'   => array
16
+  (
17
+    'recipients'    => array
18
+    (
19
+      'member_email' // The email address of the recipient
20
+    ),
21
+    'email_text'    => array
22
+    (
23
+      'news_topics' // The titles of all new news
24
+    ),
25
+    'email_html'    => array
26
+    (
27
+      'news_topics_html', // The titles of all new news
28
+      'news_topics' // The titles of all new news
29
+    )
30
+  )
31
+);
0 32
\ No newline at end of file
1 33
new file mode 100644
... ...
@@ -0,0 +1,19 @@
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
+/**
13
+ * Fields
14
+ */
15
+
16
+$GLOBALS['TL_DCA']['tl_news']['fields']['nc_sent'] = array
17
+(
18
+  'sql'                     => "char(1) NOT NULL default ''"
19
+);
0 20
new file mode 100644
... ...
@@ -0,0 +1,88 @@
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
+/**
13
+ * Palettes
14
+ */
15
+
16
+$GLOBALS['TL_DCA']['tl_news_archive']['palettes']['__selector__'][] = 'nc_enable';
17
+$GLOBALS['TL_DCA']['tl_news_archive']['palettes']['default'] = str_replace('{protected_legend:hide}','{nc_legend:hide},nc_enable;{protected_legend:hide}',$GLOBALS['TL_DCA']['tl_news_archive']['palettes']['default']);
18
+
19
+/**
20
+ * Subpalettes
21
+ */
22
+
23
+$GLOBALS['TL_DCA']['tl_news_archive']['subpalettes']['nc_enable'] = 'nc_notification,nc_notification_groups';
24
+
25
+/**
26
+ * Fields
27
+ */
28
+
29
+$GLOBALS['TL_DCA']['tl_news_archive']['fields']['nc_enable'] = array
30
+(
31
+  'label'                   => &$GLOBALS['TL_LANG']['tl_news_archive']['nc_enable'],
32
+  'exclude'                 => true,
33
+  'inputType'               => 'checkbox',
34
+  'eval'                    => array('tl_class'=>'w50 m12','submitOnChange'=>true),
35
+  'sql'                     => "char(1) NOT NULL default ''"
36
+);
37
+
38
+$GLOBALS['TL_DCA']['tl_news_archive']['fields']['nc_notification_groups'] = array
39
+(
40
+  'label'                   => &$GLOBALS['TL_LANG']['tl_news_archive']['nc_notification_groups'],
41
+  'exclude'                 => true,
42
+  'inputType'               => 'checkbox',
43
+  'foreignKey'              => 'tl_member_group.name',
44
+  'eval'                    => array('mandatory'=>true, 'multiple'=>true,'tl_class'=>'clr'),
45
+  'sql'                     => "blob NULL",
46
+  'relation'                => array('type'=>'hasMany', 'load'=>'lazy')
47
+);
48
+
49
+$GLOBALS['TL_DCA']['tl_news_archive']['fields']['nc_notification'] = array
50
+(
51
+  'label'                     => &$GLOBALS['TL_LANG']['tl_news_archive']['nc_notification'],
52
+  'exclude'                   => true,
53
+  'inputType'                 => 'select',
54
+  'options_callback'          => array('tl_news_archive_eSM_nc_news', 'getNotificationChoices'),
55
+  'eval'                      => array('mandatory'=>true,'includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'),
56
+  'sql'                       => "int(10) unsigned NOT NULL default '0'"
57
+);
58
+
59
+/**
60
+ * Provide miscellaneous methods that are used by the data configuration array.
61
+ *
62
+ * @author Benjamin Roth <http://www.esales-media.de>
63
+ */
64
+class tl_news_archive_eSM_nc_news extends \Backend
65
+{
66
+
67
+  public function __construct()
68
+  {
69
+    parent::__construct();
70
+  }
71
+
72
+  /**
73
+   * Get notification choices
74
+   *
75
+   * @return array
76
+   */
77
+  public function getNotificationChoices()
78
+  {
79
+    $arrChoices = array();
80
+    $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='news_submitted' ORDER BY title");
81
+
82
+    while ($objNotifications->next()) {
83
+      $arrChoices[$objNotifications->id] = $objNotifications->title;
84
+    }
85
+
86
+    return $arrChoices;
87
+  }
88
+}
0 89
\ No newline at end of file
1 90
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+<?php
2
+/**
3
+ * News notification extension for Contao
4
+ *
5
+ * Copyright (c) 2016 Benjamin Roth
6
+ *
7
+ * @link    http://www.esales-media.de
8
+ * @license commercial
9
+ */
10
+
11
+$GLOBALS['TL_LANG']['tl_nc_notification']['type']['news'] = 'Nachrichten';
12
+$GLOBALS['TL_LANG']['tl_nc_notification']['type']['news_submitted']['0'] = 'Neue Nachricht';
13
+
0 14
new file mode 100644
... ...
@@ -0,0 +1,26 @@
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
+/**
13
+ * Fields
14
+ */
15
+
16
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_enable'][0] = 'Benachrichtigung senden';
17
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_enable'][1] = 'Sendet eine Benachrichtung über den Benachrichtigungscenter an ausgewählte Mitgliedergruppen';
18
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_notification'][0] = 'Benachrichtigung';
19
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_notification'][1] = 'Bitte wählen Sie eine Benachrichtigung aus.';
20
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_notification_groups'][0] = 'Gruppe';
21
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_notification_groups'][1] = 'Bitte wählen Sie eine oder mehrere Gruppen, an die eine Benachrichtigung versendet werden soll.';
22
+
23
+/**
24
+ * Legends
25
+ */
26
+$GLOBALS['TL_LANG']['tl_news_archive']['nc_legend'] = 'Benachrichtigungen';
0 27
new file mode 100644
... ...
@@ -0,0 +1,14 @@
1
+<?php
2
+/**
3
+ * News notification extension for Contao
4
+ *
5
+ * Copyright (c) 2016 Benjamin Roth
6
+ *
7
+ * @link    http://www.esales-media.de
8
+ * @license commercial
9
+ */
10
+
11
+$GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['news_submitted']['member_email'] = 'E-Mail-Adresse des Mitglieds.';
12
+$GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['news_submitted']['news_topics'] = 'Alle Titel von neuen News.';
13
+$GLOBALS['TL_LANG']['NOTIFICATION_CENTER_TOKEN']['news_submitted']['news_topics_html'] = 'Alle Titel von neuen News (HTML).';
14
+