Skip to content

Commit

Permalink
Merge pull request #26 from symbiote/feature-broadcast-link
Browse files Browse the repository at this point in the history
new(BroadcastNotification) Added a new Link field for a broadcast notification
  • Loading branch information
stephenmcm authored Apr 10, 2019
2 parents 13e8bc0 + 09be549 commit c7ff2ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
31 changes: 20 additions & 11 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 @@ -20,6 +19,7 @@ class BroadcastNotification extends DataObject implements NotifiedOn
'Content' => 'Text',
'SendNow' => 'Boolean',
'IsPublic' => 'Boolean',
'Context' => 'MultiValueField'
];

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

$fields->dataFieldByName('IsPublic')->setRightTitle('Indicate whether this can be displayed to public users');

if ($this->ID) {
$fields->dataFieldByName('SendNow')->setRightTitle('If selected, this notification will be broadcast to all users in groups selected below');

$fields->removeByName('Groups');

$fields->addFieldToTab('Root.Main', ListboxField::create('Groups', 'Groups', Group::get()));

} else {
$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'
];
$fields = $this->getNotificationTemplateData();
return array_keys($fields);
}

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

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

public function Link()
{
$context = $this->Context->getValues();
return isset($context['Link']) ? $context['Link'] : null;
}
}
10 changes: 9 additions & 1 deletion src/Model/InternalNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use Symbiote\MultiValueField\ORM\FieldType\MultiValueField;

use Symbiote\MultiValueField\Fields\KeyValueField;

class InternalNotification extends DataObject {
private static $table_name = 'InternalNotification';
Expand All @@ -31,6 +31,14 @@ class InternalNotification extends DataObject {

private static $default_sort = 'ID DESC';

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->replaceField('Context', KeyValueField::create('Context'));
return $fields;
}

public function canView($member = null) {
$member = $member ?: Security::getCurrentUser();
if (!$member) {
Expand Down

0 comments on commit c7ff2ac

Please sign in to comment.