Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Feb 14, 2019
2 parents 384ae22 + 12838e5 commit aa3fcb5
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 10 deletions.
6 changes: 5 additions & 1 deletion dca/tl_calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
*/
$GLOBALS['TL_DCA']['tl_calendar']['palettes']['__selector__'][] = 'subscription_enable';
$GLOBALS['TL_DCA']['tl_calendar']['palettes']['__selector__'][] = 'subscription_waitingList';
$GLOBALS['TL_DCA']['tl_calendar']['palettes']['__selector__'][] = 'subscription_memberGroupsLimit';
$GLOBALS['TL_DCA']['tl_calendar']['palettes']['__selector__'][] = 'subscription_reminders';

\Haste\Dca\PaletteManipulator::create()
->addLegend('subscription_legend', 'title_legend', \Haste\Dca\PaletteManipulator::POSITION_AFTER, true)
->addField('subscription_enable', 'subscription_legend', \Haste\Dca\PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_calendar');

$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['subscription_enable'] = 'subscription_types,subscription_maximum,subscription_subscribeEndTime,subscription_unsubscribeEndTime,subscription_waitingList,subscription_reminders,subscription_unsubscribeLinkPage';
$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['subscription_enable'] = 'subscription_types,subscription_maximum,subscription_subscribeEndTime,subscription_unsubscribeEndTime,subscription_waitingList,subscription_memberGroupsLimit,subscription_reminders,subscription_unsubscribeLinkPage';
$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['subscription_waitingList'] = 'subscription_waitingListLimit';
$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['subscription_memberGroupsLimit'] = 'subscription_memberGroups';
$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['subscription_reminders'] = 'subscription_time,subscription_days,subscription_notification';

/**
Expand All @@ -49,6 +51,8 @@
$GLOBALS['TL_DCA']['tl_calendar']['fields']['subscription_unsubscribeEndTime'] = &$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_unsubscribeEndTime'];
$GLOBALS['TL_DCA']['tl_calendar']['fields']['subscription_waitingList'] = &$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_waitingList'];
$GLOBALS['TL_DCA']['tl_calendar']['fields']['subscription_waitingListLimit'] = &$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_waitingListLimit'];
$GLOBALS['TL_DCA']['tl_calendar']['fields']['subscription_memberGroupsLimit'] = &$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_memberGroupsLimit'];
$GLOBALS['TL_DCA']['tl_calendar']['fields']['subscription_memberGroups'] = &$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_memberGroups'];

$GLOBALS['TL_DCA']['tl_calendar']['fields']['subscription_reminders'] = [
'label' => &$GLOBALS['TL_LANG']['tl_calendar']['subscription_reminders'],
Expand Down
24 changes: 23 additions & 1 deletion dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
*/
$GLOBALS['TL_DCA']['tl_calendar_events']['palettes']['__selector__'][] = 'subscription_override';
$GLOBALS['TL_DCA']['tl_calendar_events']['palettes']['__selector__'][] = 'subscription_waitingList';
$GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes']['subscription_override'] = 'subscription_types,subscription_maximum,subscription_subscribeEndTime,subscription_unsubscribeEndTime,subscription_waitingList';
$GLOBALS['TL_DCA']['tl_calendar_events']['palettes']['__selector__'][] = 'subscription_memberGroupsLimit';
$GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes']['subscription_override'] = 'subscription_types,subscription_maximum,subscription_subscribeEndTime,subscription_unsubscribeEndTime,subscription_waitingList,subscription_memberGroupsLimit';
$GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes']['subscription_waitingList'] = 'subscription_waitingListLimit';
$GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes']['subscription_memberGroupsLimit'] = 'subscription_memberGroups';

/**
* Add fields
Expand All @@ -68,6 +70,26 @@
'sql' => "blob NULL",
];

$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_memberGroupsLimit'] = [
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['subscription_memberGroupsLimit'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => ['submitOnChange' => true],
'sql' => "char(1) NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_memberGroups'] = [
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['subscription_memberGroups'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'flag' => 1,
'foreignKey' => 'tl_member_group.name',
'eval' => ['mandatory' => true, 'multiple' => true, 'tl_class' => 'clr'],
'sql' => "blob NULL",
];

$GLOBALS['TL_DCA']['tl_calendar_events']['fields']['subscription_maximum'] = [
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['subscription_maximum'],
'exclude' => true,
Expand Down
16 changes: 12 additions & 4 deletions dca/tl_calendar_events_subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'disableGrouping' => true,
'fields' => ['dateCreated'],
'headerFields' => ['title', 'startDate', 'startTime', 'endDate', 'endTime', 'published'],
'panelLayout' => 'filter,limit',
'panelLayout' => 'filter;limit',
'child_record_callback' => [
'Codefog\EventsSubscriptions\DataContainer\SubscriptionContainer',
'generateLabel',
Expand Down Expand Up @@ -89,9 +89,9 @@
// Palettes
'palettes' => [
'__selector__' => ['type'],
'default' => '{type_legend},type,addedBy',
'guest' => '{type_legend},type,addedBy;{guest_legend},firstname,lastname,email',
'member' => '{type_legend},type,addedBy;{member_legend},member',
'default' => '{type_legend},type,addedBy,disableReminders',
'guest' => '{type_legend},type,addedBy,disableReminders;{guest_legend},firstname,lastname,email',
'member' => '{type_legend},type,addedBy,disableReminders;{member_legend},member',
],

// Fields
Expand Down Expand Up @@ -137,6 +137,14 @@
'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50'],
'sql' => "int(10) unsigned NOT NULL default '0'",
],
'disableReminders' => [
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['disableReminders'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'clr'],
'sql' => "char(1) NOT NULL default ''",
],
'member' => [
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['member'],
'exclude' => true,
Expand Down
3 changes: 3 additions & 0 deletions docs/03-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Additionally you have to create and specify the reminder notification in the Not

## Limit subscriptions per member and/or member group

In the calendar and event settings you can optionally restrict which member groups are allowed to subscribe to the
certain events. Simply select the `Member groups restriction` checkbox and choose the desired groups.

It is also possible to limit the amount of possible subscriptions per member and per member group.
You can enable that in the member group and/or member settings:

Expand Down
1 change: 1 addition & 0 deletions languages/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.subscribeNotAllowed'] = 'It is no longer possible to subscribe to this event.';
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.unsubscribeNotAllowed'] = 'It is no longer possible to unsubscribe from this event.';
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.onWaitingList'] = 'waiting list';
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.enableReminders'] = 'Enable reminders';
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.firstname'] = 'First name';
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.lastname'] = 'Last name';
$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.email'] = 'E-mail address';
Expand Down
8 changes: 8 additions & 0 deletions languages/en/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
'Waiting list limit',
'Please enter the waiting list limit. Enter 0 to allow unlimited subscriptions.',
];
$GLOBALS['TL_LANG']['tl_calendar_events']['subscription_memberGroupsLimit'] = [
'Member groups restriction',
'Restrict the subscription to certain member groups. This works only if you have enabled the Member subscription type!',
];
$GLOBALS['TL_LANG']['tl_calendar_events']['subscription_memberGroups'] = [
'Member groups',
'Please choose one or more member groups that are allowed to subscribe.',
];

/**
* Legends
Expand Down
4 changes: 4 additions & 0 deletions languages/en/tl_calendar_events_subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
'Added by',
'Here you can choose who subscribed this member.',
];
$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['disableReminders'] = [
'Disable reminders',
'Disable the event reminders for this subscriber.',
];
$GLOBALS['TL_LANG']['tl_calendar_events_subscription']['member'] = [
'Member',
'Please choose the member you want to subscribe to the event.',
Expand Down
2 changes: 1 addition & 1 deletion src/Codefog/EventsSubscriptions/Automator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function getEvents(CalendarModel $calendar)
$where = (count($where) ? " AND (".implode(" OR ", $where).")" : "");

return Database::getInstance()->prepare(
"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
"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
)
->execute($calendar->id)
->fetchAllAssoc();
Expand Down
30 changes: 30 additions & 0 deletions src/Codefog/EventsSubscriptions/EventConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public function canSubscribe()
return $this->calendar->subscription_enable ? true : false;
}

/**
* Return true if calendar has reminders
*
* @return bool
*/
public function hasReminders()
{
return $this->calendar->subscription_reminders ? true : false;
}

/**
* Get the allowed subscription types
*
Expand Down Expand Up @@ -142,6 +152,26 @@ public function getWaitingListLimit()
return (int)$this->get('subscription_waitingListLimit');
}

/**
* Return true if the event has a member groups limit
*
* @return bool
*/
public function hasMemberGroupsLimit()
{
return $this->get('subscription_memberGroupsLimit') ? true : false;
}

/**
* Get the allowed member groups
*
* @return array
*/
public function getMemberGroups()
{
return deserialize($this->get('subscription_memberGroups'), true);
}

/**
* Calculate the time offset
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function getSubscriptionTemplateData(EventConfig $config, array $modul
'subscribeEndTime' => $this->getSubscribeEndTime($config),
'unsubscribeEndTime' => $this->getUnsubscribeEndTime($config),
'subscribers' => $this->generateEventSubscribers($config),
'subscriptionMaximum' => $config->getMaximumSubscriptions(),
'subscriptionTypes' => [],
];

Expand Down
10 changes: 10 additions & 0 deletions src/Codefog/EventsSubscriptions/MemberConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public function getMember()
return $this->member;
}

/**
* Get the member groups
*
* @return array
*/
public function getMemberGroups()
{
return deserialize($this->member->groups, true);
}

/**
* Get the total subscription limit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ public function setUnsubscribeCriteria(EventConfig $event, array &$columns, arra
// Backwards compatibility
}

/**
* @inheritDoc
*/
public function writeToModel(EventConfig $event, SubscriptionModel $model)
{
if (($form = $this->getForm($event)) === null) {
return;
}

// Disable reminder if they are turned on and the user explicitly does not request them
if ($event->hasReminders() && !$this->form->fetch('enableReminders')) {
$model->disableReminders = 1;
}
}

/**
* Create the basic form
*
Expand All @@ -131,6 +146,14 @@ function ($haste) {

$form->addContaoHiddenFields();

if ($event->hasReminders()) {
$form->addFormField('enableReminders', [
'inputType' => 'checkbox',
'default' => 1,
'options' => [1 => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.enableReminders']],
]);
}

return $form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Codefog\EventsSubscriptions\EventConfig;
use Codefog\EventsSubscriptions\Model\SubscriptionModel;
use Haste\Form\Form;
use Haste\Util\ArrayPosition;

class GuestSubscription extends AbstractSubscription implements ExportAwareInterface, NotificationAwareInterface
{
Expand Down Expand Up @@ -41,6 +42,8 @@ public function writeToModel(EventConfig $event, SubscriptionModel $model)
return;
}

parent::writeToModel($event, $model);

$model->firstname = $form->fetch('firstname');
$model->lastname = $form->fetch('lastname');
$model->email = $form->fetch('email');
Expand All @@ -62,21 +65,24 @@ public function createForm(EventConfig $event)
'label' => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.firstname'],
'inputType' => 'text',
'eval' => ['mandatory' => true],
]
],
ArrayPosition::before('enableReminders')
)->addFormField(
'lastname',
[
'label' => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.lastname'],
'inputType' => 'text',
'eval' => ['mandatory' => true],
]
],
ArrayPosition::before('enableReminders')
)->addFormField(
'email',
[
'label' => &$GLOBALS['TL_LANG']['MSC']['events_subscriptions.guestForm.email'],
'inputType' => 'text',
'eval' => ['mandatory' => true, 'rgxp' => 'email'],
]
],
ArrayPosition::before('enableReminders')
);

return $form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function canSubscribe(EventConfig $event)
$member = MemberConfig::create($memberModel->id);

if ($validator->isMemberSubscribed($event, $member)
|| !$validator->validateMemberGroups($event, $member)
|| !$validator->validateMemberTotalLimit($member)
|| !$validator->validateMemberPeriodLimit($event, $member)
) {
Expand Down Expand Up @@ -119,6 +120,8 @@ public function writeToModel(EventConfig $event, SubscriptionModel $model)
throw new \RuntimeException('The member model cannot be null');
}

parent::writeToModel($event, $model);

$model->member = $memberModel->id;
}

Expand Down
24 changes: 24 additions & 0 deletions src/Codefog/EventsSubscriptions/SubscriptionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,28 @@ public function validateMemberPeriodLimit(EventConfig $event, MemberConfig $memb

return $limit['value'] > $subscriptions;
}

/**
* Validate the member groups
*
* @param EventConfig $event
* @param MemberConfig $member
*
* @return bool
*/
public function validateMemberGroups(EventConfig $event, MemberConfig $member)
{
if (!$event->hasMemberGroupsLimit()) {
return true;
}

$allowedGroups = $event->getMemberGroups();

// Return false if no groups were selected
if (count($allowedGroups) === 0) {
return false;
}

return count(array_intersect($allowedGroups, $member->getMemberGroups())) > 0;
}
}

0 comments on commit aa3fcb5

Please sign in to comment.