Skip to content

Commit

Permalink
new(BroadcastNotification) As per IRL discussion, swapped to use a 'c…
Browse files Browse the repository at this point in the history
…ontext' hash to capture extra data about the broadcast
  • Loading branch information
nyeholt committed Apr 9, 2019
1 parent be0b2f9 commit 09be549
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Model/BroadcastNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use SilverStripe\Core\Injector\Injector;
use Symbiote\Notifications\Service\NotificationService;
use SilverStripe\Forms\ListboxField;


use Symbiote\MultiValueField\Fields\KeyValueField;

class BroadcastNotification extends DataObject implements NotifiedOn
{
Expand All @@ -18,9 +17,9 @@ class BroadcastNotification extends DataObject implements NotifiedOn
private static $db = [
'Title' => 'Varchar(255)',
'Content' => 'Text',
'Link' => 'Varchar(255)',
'SendNow' => 'Boolean',
'IsPublic' => 'Boolean',
'Context' => 'MultiValueField'
];

private static $many_many = [
Expand All @@ -44,7 +43,6 @@ public function getCMSFields()
$fields = parent::getCMSFields();

$fields->dataFieldByName('IsPublic')->setRightTitle('Indicate whether this can be displayed to public users');
$fields->dataFieldByName('Link')->setRightTitle('An optional link to attach to this message');

if ($this->ID) {
$fields->dataFieldByName('SendNow')->setRightTitle('If selected, this notification will be broadcast to all users in groups selected below');
Expand All @@ -56,17 +54,17 @@ public function getCMSFields()
$fields->removeByName('SendNow');
}

$context = KeyValueField::create('Context')->setRightTitle('Add a Link and Title field here to provide context for this message');

$fields->replaceField('Context', $context);

return $fields;
}

public function getAvailableKeywords()
{
return [
'Content',
'Link'
];
$fields = $this->getNotificationTemplateData();
return array_keys($fields);
}

/**
Expand All @@ -76,10 +74,12 @@ public function getAvailableKeywords()
*/
public function getNotificationTemplateData()
{
return [
'Content' => $this->Content,
'Link' => $this->Link,
];
$fields = $this->Context->getValues();
if (!is_array($fields)) {
$fields = [];
}
$fields['Content'] = $this->Content;
return $fields;
}

/**
Expand All @@ -97,4 +97,10 @@ public function getRecipients($event)
}
return [];
}

public function Link()
{
$context = $this->Context->getValues();
return isset($context['Link']) ? $context['Link'] : null;
}
}

0 comments on commit 09be549

Please sign in to comment.