PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / reminders / command.php

command.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/reminders/command.php

114 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 interface SH4_Reminders_Command_
3 {
4 public function send( SH4_Reminders_Model $model );
5 }
6
7 class SH4_Reminders_Command implements SH4_Reminders_Command_
8 {
9 public function __construct(
10 HC3_Settings $settings,
11 HC3_Time $t,
12
13 SH4_Reminders_QueryLog $remindersQueryLog,
14 SH4_Reminders_CommandLog $remindersCommandLog,
15
16 HC3_Notificator $notificator,
17 SH4_Notifications_Service $notificationsService,
18 SH4_Notifications_Template $notificationsTemplate,
19 HC3_Hooks $hooks
20 )
21 {
22 $this->t = $t;
23 $this->settings = $hooks->wrap( $settings );
24
25 $this->remindersQueryLog = $hooks->wrap( $remindersQueryLog );
26 $this->remindersCommandLog = $hooks->wrap( $remindersCommandLog );
27
28 $this->notificationsService = $hooks->wrap( $notificationsService );
29 $this->notificationsTemplate = $hooks->wrap( $notificationsTemplate );
30 $this->notificator = $notificator;
31 }
32
33 public function send( SH4_Reminders_Model $model )
34 {
35 // already sent?
36 if( $model->log ) return;
37
38 $user = $model->user;
39 $shifts = $model->shifts;
40
41 // do send
42 $wasOff = $this->notificator->isOn() ? FALSE : TRUE;
43 if( $wasOff ){
44 $this->notificator->setOn();
45 }
46
47 $templateSubjectDaily = $this->settings->get( 'reminders_template_subject_daily' );
48 $templateSubjectWeekly = $this->settings->get( 'reminders_template_subject_weekly' );
49 $templateSubjectMonthly = $this->settings->get( 'reminders_template_subject_monthly' );
50
51 $templateSubject = NULL;
52
53 if( $model::RANGE_DAILY == $model->range ){
54 $templateSubject = $templateSubjectDaily;
55 $dateLabel = $this->t->setDateDb( $model->date )->formatDateWithWeekday();
56 }
57
58 if( $model::RANGE_WEEKLY == $model->range ){
59 $templateSubject = $templateSubjectWeekly;
60 $startDate = $this->t->setDateDb( $model->date )->setStartWeek()->formatDateDb();
61 $endDate = $this->t->modify('+1 week')->modify('-1 day')->formatDateDb();
62 $dateLabel = $this->t->formatDateRange( $startDate, $endDate );
63 }
64
65 if( $model::RANGE_MONTHLY == $model->range ){
66 $templateSubject = $templateSubjectMonthly;
67 $startDate = $this->t->setDateDb( $model->date )->setStartMonth()->formatDateDb();
68 $endDate = $this->t->modify('+1 month')->modify('-1 day')->formatDateDb();
69 $dateLabel = $this->t->formatDateRange( $startDate, $endDate );
70 }
71
72 $templateSubject = str_ireplace( '{DATELABEL}', $dateLabel, $templateSubject );
73
74 $employeeId = $model->employee->getId();
75 $employeeTitle = $model->employee->getTitle();
76
77 $templateSubject = str_ireplace( '{EMPLOYEE_ID}', $employeeId, $templateSubject );
78 $templateSubject = str_ireplace( '{EMPLOYEE_NAME}', $employeeTitle, $templateSubject );
79
80 $msg = array();
81 $msg[] = $templateSubject;
82
83 foreach( $shifts as $shift ){
84 $calendar = $shift->getCalendar();
85 $oneTemplate = $this->notificationsService->getTemplate( $calendar, 'email_employee_publish' );
86
87 // remove subject
88 $oneTemplate = explode( "\n", $oneTemplate );
89 array_shift( $oneTemplate );
90 $oneTemplate = join( "\n", $oneTemplate );
91
92 $msg[] = $this->notificationsTemplate->parse( $oneTemplate, $shift );
93 $msg[] = '';
94 }
95 $msg = join( "\n", $msg );
96
97 $this->notificator
98 ->queue( $user, 'email_employee_reminder', $msg )
99 ;
100
101 $this->notificator->send();
102
103 if( $wasOff ){
104 $this->notificator->setOff();
105 }
106
107 $modelLog = new SH4_Reminders_ModelLog;
108 $modelLog->range = $model->range;
109 $modelLog->date = $model->date;
110 $modelLog->employee_id = $model->employee->getId();
111
112 $this->remindersCommandLog->create( $modelLog );
113 }
114 }