Skip to content

Commit 36613d3

Browse files
committed
Allow to disable event reminders (#19)
1 parent ce07e80 commit 36613d3

File tree

8 files changed

+62
-8
lines changed

8 files changed

+62
-8
lines changed

dca/tl_calendar_events_subscription.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
'disableGrouping' => true,
4747
'fields' => ['dateCreated'],
4848
'headerFields' => ['title', 'startDate', 'startTime', 'endDate', 'endTime', 'published'],
49-
'panelLayout' => 'filter,limit',
49+
'panelLayout' => 'filter;limit',
5050
'child_record_callback' => [
5151
'Codefog\EventsSubscriptions\DataContainer\SubscriptionContainer',
5252
'generateLabel',
@@ -89,9 +89,9 @@
8989
// Palettes
9090
'palettes' => [
9191
'__selector__' => ['type'],
92-
'default' => '{type_legend},type,addedBy',
93-
'guest' => '{type_legend},type,addedBy;{guest_legend},firstname,lastname,email',
94-
'member' => '{type_legend},type,addedBy;{member_legend},member',
92+
'default' => '{type_legend},type,addedBy,disableReminders',
93+
'guest' => '{type_legend},type,addedBy,disableReminders;{guest_legend},firstname,lastname,email',
94+
'member' => '{type_legend},type,addedBy,disableReminders;{member_legend},member',
9595
],
9696

9797
// Fields
@@ -137,6 +137,14 @@
137137
'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50'],
138138
'sql' => "int(10) unsigned NOT NULL default '0'",
139139
],
140+
'disableReminders' => [
141+
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['disableReminders'],
142+
'exclude' => true,
143+
'filter' => true,
144+
'inputType' => 'checkbox',
145+
'eval' => ['tl_class' => 'clr'],
146+
'sql' => "char(1) NOT NULL default ''",
147+
],
140148
'member' => [
141149
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['member'],
142150
'exclude' => true,

languages/en/default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.subscribeNotAllowed'] = 'It is no longer possible to subscribe to this event.';
2020
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.unsubscribeNotAllowed'] = 'It is no longer possible to unsubscribe from this event.';
2121
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.onWaitingList'] = 'waiting list';
22+
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.enableReminders'] = 'Enable reminders';
2223
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.firstname'] = 'First name';
2324
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.lastname'] = 'Last name';
2425
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.email'] = 'E-mail address';

languages/en/tl_calendar_events_subscription.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
'Added by',
2121
'Here you can choose who subscribed this member.',
2222
];
23+
$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['disableReminders'] = [
24+
'Disable reminders',
25+
'Disable the event reminders for this subscriber.',
26+
];
2327
$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['member'] = [
2428
'Member',
2529
'Please choose the member you want to subscribe to the event.',

src/Codefog/EventsSubscriptions/Automator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function getEvents(CalendarModel $calendar)
145145
$where = (count($where) ? " AND (".implode(" OR ", $where).")" : "");
146146

147147
return Database::getInstance()->prepare(
148-
"SELECT e.*, es.id AS subscriptionId FROM tl_calendar_events_subscription es JOIN tl_calendar_events e ON e.id=es.pid WHERE e.pid=?".$where
148+
"SELECT e.*, es.id AS subscriptionId FROM tl_calendar_events_subscription es JOIN tl_calendar_events e ON e.id=es.pid WHERE e.pid=? AND es.disableReminders=''".$where
149149
)
150150
->execute($calendar->id)
151151
->fetchAllAssoc();

src/Codefog/EventsSubscriptions/EventConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ public function canSubscribe()
8282
return $this->calendar->subscription_enable ? true : false;
8383
}
8484

85+
/**
86+
* Return true if calendar has reminders
87+
*
88+
* @return bool
89+
*/
90+
public function hasReminders()
91+
{
92+
return $this->calendar->subscription_reminders ? true : false;
93+
}
94+
8595
/**
8696
* Get the allowed subscription types
8797
*

src/Codefog/EventsSubscriptions/Subscription/AbstractSubscription.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ public function setUnsubscribeCriteria(EventConfig $event, array &$columns, arra
108108
// Backwards compatibility
109109
}
110110

111+
/**
112+
* @inheritDoc
113+
*/
114+
public function writeToModel(EventConfig $event, SubscriptionModel $model)
115+
{
116+
if (($form = $this->getForm($event)) === null) {
117+
return;
118+
}
119+
120+
// Disable reminder if they are turned on and the user explicitly does not request them
121+
if ($event->hasReminders() && !$this->form->fetch('enableReminders')) {
122+
$model->disableReminders = 1;
123+
}
124+
}
125+
111126
/**
112127
* Create the basic form
113128
*
@@ -131,6 +146,14 @@ function ($haste) {
131146

132147
$form->addContaoHiddenFields();
133148

149+
if ($event->hasReminders()) {
150+
$form->addFormField('enableReminders', [
151+
'inputType' => 'checkbox',
152+
'default' => 1,
153+
'options' => [1 => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.enableReminders']],
154+
]);
155+
}
156+
134157
return $form;
135158
}
136159

src/Codefog/EventsSubscriptions/Subscription/GuestSubscription.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Codefog\EventsSubscriptions\EventConfig;
66
use Codefog\EventsSubscriptions\Model\SubscriptionModel;
77
use Haste\Form\Form;
8+
use Haste\Util\ArrayPosition;
89

910
class GuestSubscription extends AbstractSubscription implements ExportAwareInterface, NotificationAwareInterface
1011
{
@@ -41,6 +42,8 @@ public function writeToModel(EventConfig $event, SubscriptionModel $model)
4142
return;
4243
}
4344

45+
parent::writeToModel($event, $model);
46+
4447
$model->firstname = $form->fetch('firstname');
4548
$model->lastname = $form->fetch('lastname');
4649
$model->email = $form->fetch('email');
@@ -62,21 +65,24 @@ public function createForm(EventConfig $event)
6265
'label' => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.firstname'],
6366
'inputType' => 'text',
6467
'eval' => ['mandatory' => true],
65-
]
68+
],
69+
ArrayPosition::before('enableReminders')
6670
)->addFormField(
6771
'lastname',
6872
[
6973
'label' => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.lastname'],
7074
'inputType' => 'text',
7175
'eval' => ['mandatory' => true],
72-
]
76+
],
77+
ArrayPosition::before('enableReminders')
7378
)->addFormField(
7479
'email',
7580
[
7681
'label' => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.email'],
7782
'inputType' => 'text',
7883
'eval' => ['mandatory' => true, 'rgxp' => 'email'],
79-
]
84+
],
85+
ArrayPosition::before('enableReminders')
8086
);
8187

8288
return $form;

src/Codefog/EventsSubscriptions/Subscription/MemberSubscription.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public function writeToModel(EventConfig $event, SubscriptionModel $model)
120120
throw new \RuntimeException('The member model cannot be null');
121121
}
122122

123+
parent::writeToModel($event, $model);
124+
123125
$model->member = $memberModel->id;
124126
}
125127

0 commit comments

Comments
 (0)