Skip to content

Commit

Permalink
Event updates now send out an email to all subscribers
Browse files Browse the repository at this point in the history
Updates #144
  • Loading branch information
inghamn committed Apr 30, 2018
1 parent 5fc22b3 commit c273eb5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
9 changes: 9 additions & 0 deletions blocks/txt/events/notification.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* @copyright 2018 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @param Event $this->event
*/
declare (strict_types=1);
$this->_include('events/partials/emailHeader.inc');
$this->_include('events/info.inc');
5 changes: 5 additions & 0 deletions blocks/txt/events/partials/emailHeader.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This is an automated email message from inRoads.

inRoads is a digital service of the City of Bloomington to publish planned
and future road closings, lane reductions, parking reservations and more.
inRoads can be accessed online at http://bloomington.in.gov/inroads.
6 changes: 1 addition & 5 deletions blocks/txt/events/summary.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
* @param array $eventList
*/
use Blossom\Classes\Block;
$this->_include('events/partials/emailHeader.inc');
?>
This is an automated email message from inRoads.

inRoads is a digital service of the City of Bloomington to publish planned
and future road closings, lane reductions, parking reservations and more.
inRoads can be accessed online at http://bloomington.in.gov/inroads.

Here are the upcoming road related events for next week, <?= $this->start->format(DATE_FORMAT); ?> to <?= $this->end->format(DATE_FORMAT); ?>:

Expand Down
9 changes: 3 additions & 6 deletions language/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en_US\n"

msgid "signed_in_as"
msgstr "Signed in as %s"

msgid "departmentContactInfo"
msgstr "If you have any problems with this project, please contact %s %s"

msgid "title_help"
msgstr "Enter the title for the event"

Expand All @@ -33,3 +27,6 @@ msgstr "Smooth driving ahead!"

msgid "noEventsReturned.message"
msgstr "Either you've found the perfect day to travel, or your query returned no results (it's probably more the second thing)."

msgid "notification_subject"
msgstr "%s Notification"
15 changes: 7 additions & 8 deletions scripts/postWeeklyEvents.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/local/bin/php
<?php
/**
* @copyright 2015 City of Bloomington, Indiana
* @copyright 2015-2018 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <[email protected]>
*/
use Application\Models\EventType;
use Application\Models\GoogleGateway;
Expand All @@ -22,14 +21,14 @@
$filters['eventTypes'][] = $type->getCode();
}
}
$list = GoogleGateway::getEvents(GOOGLE_CALENDAR_ID, $start, $end, $filters);
$block = new Block('events/summary.inc', [
$list = GoogleGateway::getEvents(GOOGLE_CALENDAR_ID, $start, $end, $filters);
$block = new Block('events/summary.inc', [
'start' => $start,
'end' => $end,
'eventList' => $list
]);

$message = $block->render('txt');
$subject = 'Road closings for the week: '.$start->format(DATE_FORMAT).' to '.$end->format(DATE_FORMAT);
$from = 'From: '.ADMINISTRATOR_EMAIL;
$template = new Template('default', 'txt');
$message = $block->render('txt', $template);
$subject = 'Road closings for the week: '.$start->format(DATE_FORMAT).' to '.$end->format(DATE_FORMAT);
$from = 'From: '.ADMINISTRATOR_EMAIL;
mail(GOOGLE_GROUP, $subject, $message, $from);
28 changes: 27 additions & 1 deletion src/Controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Blossom\Classes\ActiveRecord;
use Blossom\Classes\Block;
use Blossom\Classes\Controller;
use Blossom\Classes\Template;

class EventsController extends Controller
{
Expand Down Expand Up @@ -89,7 +90,6 @@ public function index()
else {
$this->template->blocks[] = $eventListBlock;
}

}

public function view()
Expand Down Expand Up @@ -147,6 +147,12 @@ public function update()
$event->handleUpdate($_POST);
$event->save();

$table = new PeopleTable();
$list = $table->find(['notifications'=>true]);
if (count($list)) {
self::sendNotifications($event, $list);
}

$url = $existingEventId
? BASE_URL.'/events/view?id=' .$event->getId()
: BASE_URL.'/segments?event_id='.$event->getId();
Expand Down Expand Up @@ -181,4 +187,24 @@ public function delete()
header('Location: '.BASE_URL.'/events');
exit();
}

public static function sendNotifications(Event $event, array $people)
{
$template = new Template('default', 'txt');
$block = new Block('events/notification.inc', ['event'=>$event]);

$message = $block->render('txt', $template);
$subject = sprintf($template->_('notification_subject', 'messages'), APPLICATION_NAME);
$name = preg_replace('/[^a-zA-Z0-9]+/','_',APPLICATION_NAME);
$fromEmail = "$name@". BASE_HOST;
$fromFullname = APPLICATION_NAME;

foreach ($people as $p) {
$to = $p->getEmail();
if ($to) {
$from = "From: $fromFullname <$fromEmail>\r\nReply-to: ".ADMINISTRATOR_EMAIL;
mail($to, $subject, $message, $from, '-f'.ADMINISTRATOR_EMAIL);
}
}
}
}

0 comments on commit c273eb5

Please sign in to comment.