Browse code

Change looping order to fix the news only being sent to the first selected group

Benjamin Roth authored on05/08/2024 13:41:03
Showing1 changed files
... ...
@@ -68,57 +68,58 @@ class SendNewsNotificationJob
68 68
                 // Load groups and notification models if we have news to share
69 69
                 if ($News->rowCount() && ($Notification = Notification::findByPk($Archive->nc_notification)) !== null && ($Groups = MemberGroupModel::findMultipleByIds($arrGroupIds)) !== null)
70 70
                 {
71
-                    while ($Groups->next())
71
+                    foreach ($News->iterateAssociative() as $item)
72 72
                     {
73
-                        // Skip disabled groups
74
-                        if ($Groups->disable)
75
-                        {
76
-                            continue;
77
-                        }
73
+                        $arrNewsIds[] = $item['id'];
78 74
 
79
-                        // Get group members
80
-                        $Members = MemberModel::findBy(array("`groups` LIKE '%\"".$Groups->id."\"%'","(start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND disable=''"),null);
81
-
82
-                        // Send notification to each member
83 75
                         $arrNews = array();
84 76
                         $arrNewsPlain = array();
85
-                        foreach ($News->iterateAssociative() as $item)
86
-                        {
87
-                            $arrNewsIds[] = $item['id'];
88 77
 
89
-                            if ($Members !== null)
78
+                        $strText = '';
79
+                        $objContentElement = ContentModel::findPublishedByPidAndTable($item['id'], 'tl_news');
80
+
81
+                        if ($objContentElement !== null)
82
+                        {
83
+                            while ($objContentElement->next())
90 84
                             {
91
-                                $strText = '';
92
-                                $objContentElement = ContentModel::findPublishedByPidAndTable($item['id'], 'tl_news');
85
+                                $strText .= Controller::getContentElement($objContentElement->current());
86
+                            }
87
+                        }
88
+                        $arrRow = array(
89
+                            'date' => date('d.m.Y',$item['date']),
90
+                            'headline' => $item['headline'],
91
+                            'teaser' => $item['teaser'] ? StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])),128) : '',
92
+                            'text_plain' => $strText ? strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$strText)) : ($item['teaser'] ? strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])) : ''),
93
+                            'text_html' => $strText ?: $item['teaser']
94
+                        );
95
+
96
+                        if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null)
97
+                        {
98
+                            //                                    $arrRow['url'] = $objJumpTo->getAbsoluteUrl(sprintf((Config::get('useAutoItem') ? '/%s' : '/items/%s'),$item['alias'])).'?ltoken=%%_TOKEN_%%';
99
+                            $arrRow['url'] = $objJumpTo->getAbsoluteUrl(sprintf((Config::get('useAutoItem') ? '/%s' : '/items/%s'),$item['alias']));
100
+                        }
93 101
 
94
-                                if ($objContentElement !== null)
95
-                                {
96
-                                    while ($objContentElement->next())
97
-                                    {
98
-                                        $strText .= Controller::getContentElement($objContentElement->current());
99
-                                    }
100
-                                }
101
-                                $arrRow = array(
102
-                                    'date' => date('d.m.Y',$item['date']),
103
-                                    'headline' => $item['headline'],
104
-                                    'teaser' => $item['teaser'] ? StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])),128) : '',
105
-                                    'text_plain' => $strText ? strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$strText)) : ($item['teaser'] ? strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])) : ''),
106
-                                    'text_html' => $strText ?: $item['teaser']
107
-                                );
108
-
109
-                                if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null)
110
-                                {
111
-    //                                    $arrRow['url'] = $objJumpTo->getAbsoluteUrl(sprintf((Config::get('useAutoItem') ? '/%s' : '/items/%s'),$item['alias'])).'?ltoken=%%_TOKEN_%%';
112
-                                    $arrRow['url'] = $objJumpTo->getAbsoluteUrl(sprintf((Config::get('useAutoItem') ? '/%s' : '/items/%s'),$item['alias']));
113
-                                }
102
+                        $arrNews[] = $arrRow;
103
+
104
+                        $arrNewsPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline'];
105
+                        $arrNewsHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3><p>'.$arrRow['teaser'].'</p>'. ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
106
+                        $arrNewsFullPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline'] . "\n" . $arrRow['text_plain'];
107
+                        $arrNewsFullHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3>' . $arrRow['text_html'] . ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
114 108
 
115
-                                $arrNews[] = $arrRow;
109
+                        while ($Groups->next())
110
+                        {
111
+                            // Skip disabled groups
112
+                            if ($Groups->disable)
113
+                            {
114
+                                continue;
115
+                            }
116 116
 
117
-                                $arrNewsPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline'];
118
-                                $arrNewsHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3><p>'.$arrRow['teaser'].'</p>'. ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
119
-                                $arrNewsFullPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline'] . "\n" . $arrRow['text_plain'];
120
-                                $arrNewsFullHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3>' . $arrRow['text_html'] . ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
117
+                            // Get group members
118
+                            $Members = MemberModel::findBy(array("`groups` LIKE '%\"".$Groups->id."\"%'","(start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND disable=''"),null);
121 119
 
120
+                            // Send notification to each member
121
+                            if ($Members !== null)
122
+                            {
122 123
                                 while ($Members->next())
123 124
                                 {
124 125
                                     if (!$Members->nc_news_subscribe)
... ...
@@ -145,9 +146,9 @@ class SendNewsNotificationJob
145 146
                                 }
146 147
                             }
147 148
                         }
148
-
149 149
                     }
150 150
 
151
+
151 152
                     // Flag news as sent
152 153
                     if (count($arrNewsIds))
153 154
                     {