Comments (7)
Registering event listeners for the plugin in Plugin.php -> boot():
\RainLab\Notify\Classes\Notifier::bindEvents([
'captive.xm.shifts.staffmember.add' => \Captive\XM\Classes\Notify\Events\StaffAdded::class,
'captive.xm.shifts.staffmember.remove' => \Captive\XM\Classes\Notify\Events\StaffRemoved::class
]);
Registering the custom plugin's support for the notify plugin in custom plugin's Plugin.php:
public function registerNotificationRules()
{
return [
'events' => [
\Captive\XM\Classes\Notify\Events\StaffAdded::class,
\Captive\XM\Classes\Notify\Events\StaffRemoved::class,
],
'actions' => [
\Captive\XM\Classes\Notify\Actions\SendEmail::class,
\Captive\XM\Classes\Notify\Actions\SendSMS::class,
],
'conditions' => [],
'groups' => [
'shifts' => [
'label' => 'Shifts',
'icon' => 'icon-calendar'
],
],
'presets' => '$/captive/xm/classes/notify/presets.yaml',
];
}
presets.yaml
# ===================================
# Event Presets
# ===================================
member_added:
name: Member has been added to a shift
event: Captive\XM\Classes\Notify\Events\StaffAdded
items:
- action: Captive\XM\Classes\Notify\Actions\SendSMS
template: 'You are assigned to {{ shiftName }} - {{ eventName }} as a {{ role }} for {{ date }}. Details at {{ url }}'
- action: Captive\XM\Classes\Notify\Actions\SendEmail
mail_template: captive.xm::mail.shift.member_added
file_name: myshift.ics
conditions:
- condition: RainLab\Notify\NotifyRules\ExecutionContextCondition
subcondition: environment
operator: is
value: prod
condition_text: Application environment <span class="operator">is</span> prod
member_removed:
name: Member has been removed from a shift
event: Captive\XM\Classes\Notify\Events\StaffRemoved
items:
- action: Captive\XM\Classes\Notify\Actions\SendSMS
template: You have been removed from {{ shiftName }} - {{ eventName }} for {{ date }}.
- action: Captive\XM\Classes\Notify\Actions\SendEmail
mail_template: captive.xm::mail.shift.member_removed
conditions:
- condition: RainLab\Notify\NotifyRules\ExecutionContextCondition
subcondition: environment
operator: is
value: prod
condition_text: Application environment <span class="operator">is</span> prod
SendEmail.php action:
<?php namespace Captive\XM\Classes\Notify\Actions;
use Mail;
use System\Models\MailTemplate;
class SendEmail extends \RainLab\Notify\Classes\ActionBase
{
/**
* Returns information about this event, including name and description.
*/
public function actionDetails()
{
return [
'name' => 'Send an email',
'description' => 'Send an email to a staff member',
'icon' => 'icon-envelope-o'
];
}
/**
* Field configuration for the action.
*/
public function defineFormFields()
{
return 'fields.yaml';
}
public function getText()
{
$template = $this->host->mail_template;
return 'Send a message using template: ' . $template;
}
public function getMailTemplateOptions()
{
$codes = array_keys(MailTemplate::listAllTemplates());
return array_combine($codes, $codes);;
}
/**
* Triggers this action.
* @param array $params
* @return void
*/
public function triggerAction($params)
{
$emailCode = $this->host->mail_template;
$fileName = $this->host->file_name;
$staffMember = $params['staffmember'];
$mailData = $params['mailData'];
$fileData = $params['fileData'];
Mail::queue($emailCode, $mailData, function ($message) use ($staffMember, $fileData, $fileName) {
$message->to($staffMember->email, $staffMember->full_name);
if (!empty($fileData)) {
$message->attachData($fileData, $fileName);
}
});
}
}
SendEmail.php fields.yaml:
fields:
mail_template:
label: Mail template
type: dropdown
placeholder: Select template
file_name:
label: File Name
type: text
placeholder: The attached file name
StaffRemoved.php Event:
<?php namespace Captive\XM\Classes\Notify\Events;
class StaffRemoved extends \RainLab\Notify\Classes\EventBase
{
/**
* Returns information about this event, including name and description.
*/
public function eventDetails()
{
return [
'name' => 'Staff member removed',
'description' => 'Fired when a staff member has been removed from a shift',
'group' => 'shifts'
];
}
/**
* Defines the usable parameters provided by this class.
*/
public function defineParams()
{
return [
'name' => [
'title' => 'Name',
'label' => 'Name of the staff member',
],
'shiftName' => [
'title' => 'Shift',
'label' => 'Name of the shift',
],
'eventName' => [
'title' => 'Event',
'label' => 'Name of the event',
],
'role' => [
'title' => 'Role',
'label' => 'Name of the role',
],
'date' => [
'title' => 'Start time',
'label' => "The shift's start time",
],
'url' => [
'title' => 'URL',
'label' => 'The URL for the shift',
],
];
}
public static function makeParamsFromEvent(array $args, $eventName = null)
{
return [
'shiftslot' => array_get($args, 0),
'staffmember' => array_get($args, 1),
'mailData' => array_get($args, 2),
'fileData' => null,
];
}
}
captive.xm.shifts.staffmember.remove
event fired in the ShiftSlot model:
Event::fire('captive.xm.shifts.staffmember.remove', [$this, $member, $data]);
from notify-plugin.
Thank you, Luke :-)
Almost got it.
Answer 2 more questions, please.
- How do I send mail to all employees of the company so that they do not see each other?
- How can I make a record in my own database table?
from notify-plugin.
If the content of all the emails is the same then add each address as a BCC recipient.
How can I make a record in my own database table?
No idea what you mean by that and it seems like such a basic question that this isn't the right place to ask it.
from notify-plugin.
I will outline the situation.
I have a job site. The vacancy has a button "Respond to the vacancy".
I need to save vacancy ID and CV ID to a database. Then, send letters to the job seeker (URL of the vacancy) and to all employees of the company (URL of the resume of the job seeker).
How can I do this? Maybe you can give me a hint?
from notify-plugin.
Take a look at existing plugins for managing job listings: https://octobercms.com/plugins?search=job. It's also not that difficult to just create your own using the Builder plugin if you're comfortable doing some custom development as well.
from notify-plugin.
Thank you, Luke. You always help me out :-)
from notify-plugin.
This plugin is probably not a good fit for what you're trying to do, custom development or those other plugins would be a better fit. This is a plugin that other developers can integrate their plugins with to offload the responsibility of notification management onto, not really a plugin meant to handle the notification rules for one-off site-specific plugins, since that's usually much easier to handle just by writing a small amount of custom code to handle whatever notifications you need directly.
Thank you, Luke. You always help me out :-)
Consider supporting me by sponsoring me through GitHub 😉
from notify-plugin.
Related Issues (20)
- Notification rule is missing a root condition - Improve error message HOT 20
- QUESTION - Help with Event::fire and sending email HOT 4
- Conditions not saving the value field HOT 3
- I cannot save notification, i get "The mail template field is required" HOT 19
- Plugin interface not showing up in the settings area HOT 3
- ActionBuilder widget does not remember state of previous actions HOT 1
- How set host type in SaveDatabaseAction HOT 1
- Action class with repeater type field HOT 3
- Creates duplicates every time you view settings HOT 2
- [Feature Request] October Backend channel HOT 1
- Can't "Compose an email message" when "A user is registered" HOT 2
- The ModelAttributesConditionBase file may have errors on line 315 HOT 1
- Error on create notification condition HOT 4
- Can't create new notification, "Add Notification Rule" form is empty HOT 2
- Validation error when saving a notification with action with validation HOT 2
- Error on new notification rule creation HOT 1
- ExecutionContextCondition not evaluating 'theme' and 'context' conditions? HOT 1
- MIT License? HOT 2
- Manage timing of notifications HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notify-plugin.