| ... | ... |
@@ -62,7 +62,7 @@ class SendBookingChangeNotificationJob |
| 62 | 62 |
$time = Date::floorToMinute(); |
| 63 | 63 |
|
| 64 | 64 |
// Do we have updateable items |
| 65 |
- $Bookings = $this->db->executeQuery("SELECT r.id, r.pid, r.uid, r.behaelter, r.sorten, r.lage, r.ernteart, r.upload, s.date as 'slot_date', s.time as 'slot_time', s.behaelter as 'slot_behaelter', s.sorten as 'slot_sorten', s.ernteart as 'slot_ernteart', s.lage as 'slot_lage', s.anmerkungen as 'slot_anmerkungen' FROM tl_vr_wa_reservation r INNER JOIN tl_vr_wa_slot s ON s.id = r.pid WHERE s.pid = ? AND r.nc_sent < r.tstamp AND s.published='1'",[$Location->id]);
|
|
| 65 |
+ $Bookings = $this->db->executeQuery("SELECT r.id, r.pid, r.uid, r.behaelter, r.sorten, r.lage, r.ernteart, r.upload, r.nc_sent, s.date as 'slot_date', s.time as 'slot_time', s.behaelter as 'slot_behaelter', s.sorten as 'slot_sorten', s.ernteart as 'slot_ernteart', s.lage as 'slot_lage', s.anmerkungen as 'slot_anmerkungen' FROM tl_vr_wa_reservation r INNER JOIN tl_vr_wa_slot s ON s.id = r.pid WHERE s.pid = ? AND r.nc_sent < r.tstamp AND s.published='1'",[$Location->id]);
|
|
| 66 | 66 |
|
| 67 | 67 |
// Load groups and notification models if we have news to share |
| 68 | 68 |
if ($Bookings->rowCount() && ($Notification = Notification::findByPk($Location->nc_notification)) !== null) |
| ... | ... |
@@ -134,6 +134,7 @@ class SendBookingChangeNotificationJob |
| 134 | 134 |
'slot_ernteart' => implode(', ',$arrErnteartAvailable),
|
| 135 | 135 |
'slot_lage' => implode(', ',$arrLageAvailable),
|
| 136 | 136 |
'slot_anmerkungen' => $Booking['slot_anmerkungen'], |
| 137 |
+ 'booking_ncsent' => $Booking['nc_sent'], |
|
| 137 | 138 |
'booking_behaelter' => $Booking['behaelter'], |
| 138 | 139 |
'booking_sorten' => implode(', ',$arrSortenBooked),
|
| 139 | 140 |
'booking_ernteart' => implode(', ',$arrErnteartBooked),
|
| ... | ... |
@@ -128,6 +128,7 @@ class SendBookingChangeNotificationJob |
| 128 | 128 |
'member_memberno' => $Member->memberno, |
| 129 | 129 |
'slot_date' => Date::parse(Date::getNumericDateFormat(),$Booking['slot_date']), |
| 130 | 130 |
'slot_time' => Date::parse(Date::getNumericTimeFormat(),$Booking['slot_time']), |
| 131 |
+ 'slot_standort' => $Location->title, |
|
| 131 | 132 |
'slot_behaelter' => $Booking['slot_behaelter'], |
| 132 | 133 |
'slot_sorten' => implode(', ',$arrSortenAvailable),
|
| 133 | 134 |
'slot_ernteart' => implode(', ',$arrErnteartAvailable),
|
| ... | ... |
@@ -47,7 +47,6 @@ class SendBookingChangeNotificationJob |
| 47 | 47 |
|
| 48 | 48 |
public function __invoke(string $scope) |
| 49 | 49 |
{
|
| 50 |
- $this->logger->log(LogLevel::INFO, 'WA notifications debug', array('contao' => new ContaoContext(__METHOD__, 'CRON')));
|
|
| 51 | 50 |
System::loadLanguageFile('default','de');
|
| 52 | 51 |
list($admin_name,$admin_email) = StringUtil::splitFriendlyEmail(Config::get('adminEmail'));
|
| 53 | 52 |
$intNotificationsCount = 0; |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,159 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+declare(strict_types=1); |
|
| 4 |
+ |
|
| 5 |
+/* |
|
| 6 |
+* This file is part of newsmailer bundle for Contao. |
|
| 7 |
+* |
|
| 8 |
+* (c) Benjamin Roth |
|
| 9 |
+* |
|
| 10 |
+* @license LGPL-3.0-or-later |
|
| 11 |
+*/ |
|
| 12 |
+ |
|
| 13 |
+namespace vonRotenberg\WeinanlieferungBundle\Cron; |
|
| 14 |
+ |
|
| 15 |
+use Contao\Config; |
|
| 16 |
+use Contao\CoreBundle\Monolog\ContaoContext; |
|
| 17 |
+use Contao\CoreBundle\ServiceAnnotation\CronJob; |
|
| 18 |
+use Contao\Date; |
|
| 19 |
+use Contao\MemberModel; |
|
| 20 |
+use Contao\StringUtil; |
|
| 21 |
+use Contao\System; |
|
| 22 |
+use Doctrine\DBAL\Connection; |
|
| 23 |
+use NotificationCenter\Model\Notification; |
|
| 24 |
+use Psr\Log\LoggerInterface; |
|
| 25 |
+use Psr\Log\LogLevel; |
|
| 26 |
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungLageModel; |
|
| 27 |
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungLeseartModel; |
|
| 28 |
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungRebsorteModel; |
|
| 29 |
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungStandortModel; |
|
| 30 |
+ |
|
| 31 |
+/** |
|
| 32 |
+ * @CronJob("*\/10 * * * *")
|
|
| 33 |
+ */ |
|
| 34 |
+class SendBookingChangeNotificationJob |
|
| 35 |
+{
|
|
| 36 |
+ /** @var LoggerInterface */ |
|
| 37 |
+ private $logger; |
|
| 38 |
+ |
|
| 39 |
+ /** @var Connection */ |
|
| 40 |
+ private $db; |
|
| 41 |
+ |
|
| 42 |
+ public function __construct(Connection $db, LoggerInterface $logger) |
|
| 43 |
+ {
|
|
| 44 |
+ $this->logger = $logger; |
|
| 45 |
+ $this->db = $db; |
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ public function __invoke(string $scope) |
|
| 49 |
+ {
|
|
| 50 |
+ $this->logger->log(LogLevel::INFO, 'WA notifications debug', array('contao' => new ContaoContext(__METHOD__, 'CRON')));
|
|
| 51 |
+ System::loadLanguageFile('default','de');
|
|
| 52 |
+ list($admin_name,$admin_email) = StringUtil::splitFriendlyEmail(Config::get('adminEmail'));
|
|
| 53 |
+ $intNotificationsCount = 0; |
|
| 54 |
+ |
|
| 55 |
+ // Get locations |
|
| 56 |
+ $Locations = WeinanlieferungStandortModel::findBy('nc_enable','1');
|
|
| 57 |
+ |
|
| 58 |
+ if ($Locations !== null) |
|
| 59 |
+ {
|
|
| 60 |
+ while ($Locations->next()) |
|
| 61 |
+ {
|
|
| 62 |
+ $Location = $Locations->current(); |
|
| 63 |
+ $time = Date::floorToMinute(); |
|
| 64 |
+ |
|
| 65 |
+ // Do we have updateable items |
|
| 66 |
+ $Bookings = $this->db->executeQuery("SELECT r.id, r.pid, r.uid, r.behaelter, r.sorten, r.lage, r.ernteart, r.upload, s.date as 'slot_date', s.time as 'slot_time', s.behaelter as 'slot_behaelter', s.sorten as 'slot_sorten', s.ernteart as 'slot_ernteart', s.lage as 'slot_lage', s.anmerkungen as 'slot_anmerkungen' FROM tl_vr_wa_reservation r INNER JOIN tl_vr_wa_slot s ON s.id = r.pid WHERE s.pid = ? AND r.nc_sent < r.tstamp AND s.published='1'",[$Location->id]);
|
|
| 67 |
+ |
|
| 68 |
+ // Load groups and notification models if we have news to share |
|
| 69 |
+ if ($Bookings->rowCount() && ($Notification = Notification::findByPk($Location->nc_notification)) !== null) |
|
| 70 |
+ {
|
|
| 71 |
+ foreach ($Bookings->iterateAssociative() as $Booking) |
|
| 72 |
+ {
|
|
| 73 |
+ // Get group members |
|
| 74 |
+ $Member = MemberModel::findOneBy(array("id = ?", "login='1' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND disable=''"), [$Booking['uid']]);
|
|
| 75 |
+ |
|
| 76 |
+ // Send notification to member |
|
| 77 |
+ if ($Member !== null) |
|
| 78 |
+ {
|
|
| 79 |
+ $arrSortenAvailable = []; |
|
| 80 |
+ $arrErnteartAvailable = []; |
|
| 81 |
+ $arrLageAvailable = []; |
|
| 82 |
+ $arrSortenBooked = []; |
|
| 83 |
+ $arrErnteartBooked = []; |
|
| 84 |
+ $arrLageBooked = []; |
|
| 85 |
+ |
|
| 86 |
+ $SortenLeseart = StringUtil::deserialize($Booking['slot_sorten'],true); |
|
| 87 |
+ foreach($SortenLeseart as $sorteLeseart) |
|
| 88 |
+ {
|
|
| 89 |
+ $objSorte = WeinanlieferungRebsorteModel::findByPk($sorteLeseart['sorte']); |
|
| 90 |
+ $objLeseart = WeinanlieferungLeseartModel::findByPk($sorteLeseart['leseart']); |
|
| 91 |
+ $arrSortenAvailable[$objSorte->id.','.$objLeseart->id] = ($objSorte !== null ? $objSorte->title : '') . ' ' . ($objLeseart !== null ? $objLeseart->title : ''); |
|
| 92 |
+ } |
|
| 93 |
+ $SortenLeseart = explode(';',$Booking['sorten']);
|
|
| 94 |
+ foreach($SortenLeseart as $sorteLeseart) |
|
| 95 |
+ {
|
|
| 96 |
+ list($sorte,$leseart) = explode(',',$sorteLeseart);
|
|
| 97 |
+ $objSorte = WeinanlieferungRebsorteModel::findByPk($sorte); |
|
| 98 |
+ $objLeseart = WeinanlieferungLeseartModel::findByPk($leseart); |
|
| 99 |
+ $arrSortenBooked[$objSorte->id.','.$objLeseart->id] = ($objSorte !== null ? $objSorte->title : '') . ' ' . ($objLeseart !== null ? $objLeseart->title : ''); |
|
| 100 |
+ } |
|
| 101 |
+ foreach (explode(',', $Booking['ernteart']) as $ernteart)
|
|
| 102 |
+ {
|
|
| 103 |
+ $arrErnteartBooked[$ernteart] = $GLOBALS['TL_LANG']['REF']['wa_ernteart'][$ernteart] ?? $ernteart; |
|
| 104 |
+ } |
|
| 105 |
+ foreach (explode(',', $Booking['slot_ernteart']) as $ernteart)
|
|
| 106 |
+ {
|
|
| 107 |
+ $arrErnteartAvailable[$ernteart] = $GLOBALS['TL_LANG']['REF']['wa_ernteart'][$ernteart] ?? $ernteart; |
|
| 108 |
+ } |
|
| 109 |
+ foreach (explode(',', $Booking['slot_lage']) as $lage)
|
|
| 110 |
+ {
|
|
| 111 |
+ if (($Lage = WeinanlieferungLageModel::findByPk($lage)) !== null) |
|
| 112 |
+ {
|
|
| 113 |
+ $arrLageAvailable[$Lage->id] = $Lage->title; |
|
| 114 |
+ } |
|
| 115 |
+ } |
|
| 116 |
+ foreach (explode(',', $Booking['lage']) as $lage)
|
|
| 117 |
+ {
|
|
| 118 |
+ if (($Lage = WeinanlieferungLageModel::findByPk($lage)) !== null) |
|
| 119 |
+ {
|
|
| 120 |
+ $arrLageBooked[$Lage->id] = $Lage->title; |
|
| 121 |
+ } |
|
| 122 |
+ } |
|
| 123 |
+ |
|
| 124 |
+ $Notification->send(array |
|
| 125 |
+ ( |
|
| 126 |
+ 'member_email' => $Member->email . ($Member->nc_news_additionalEmail ? ',' . $Member->nc_news_additionalEmail : ''), |
|
| 127 |
+ 'member_firstname' => $Member->firstname, |
|
| 128 |
+ 'member_lastname' => $Member->lastname, |
|
| 129 |
+ 'member_memberno' => $Member->memberno, |
|
| 130 |
+ 'slot_date' => Date::parse(Date::getNumericDateFormat(),$Booking['slot_date']), |
|
| 131 |
+ 'slot_time' => Date::parse(Date::getNumericTimeFormat(),$Booking['slot_time']), |
|
| 132 |
+ 'slot_behaelter' => $Booking['slot_behaelter'], |
|
| 133 |
+ 'slot_sorten' => implode(', ',$arrSortenAvailable),
|
|
| 134 |
+ 'slot_ernteart' => implode(', ',$arrErnteartAvailable),
|
|
| 135 |
+ 'slot_lage' => implode(', ',$arrLageAvailable),
|
|
| 136 |
+ 'slot_anmerkungen' => $Booking['slot_anmerkungen'], |
|
| 137 |
+ 'booking_behaelter' => $Booking['behaelter'], |
|
| 138 |
+ 'booking_sorten' => implode(', ',$arrSortenBooked),
|
|
| 139 |
+ 'booking_ernteart' => implode(', ',$arrErnteartBooked),
|
|
| 140 |
+ 'booking_lage' => implode(', ',$arrLageBooked),
|
|
| 141 |
+ 'admin_email' => $admin_email, |
|
| 142 |
+ ), |
|
| 143 |
+ $GLOBALS['TL_LANGUAGE']); |
|
| 144 |
+ |
|
| 145 |
+ $intNotificationsCount++; |
|
| 146 |
+ $this->db->executeStatement("UPDATE tl_vr_wa_reservation SET nc_sent = ? WHERE id = ?",[$time,$Booking['id']]);
|
|
| 147 |
+ } |
|
| 148 |
+ } |
|
| 149 |
+ } |
|
| 150 |
+ } |
|
| 151 |
+ |
|
| 152 |
+ // Flag news as sent |
|
| 153 |
+ if ($intNotificationsCount) |
|
| 154 |
+ {
|
|
| 155 |
+ $this->logger->log(LogLevel::INFO, sprintf('WA notifications(%s) has been sent',$intNotificationsCount), array('contao' => new ContaoContext(__METHOD__, 'CRON')));
|
|
| 156 |
+ } |
|
| 157 |
+ } |
|
| 158 |
+ } |
|
| 159 |
+} |