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 / calendars / html / admin / controller / new.php

new.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/calendars/html/admin/controller/new.php

99 lines 2.9 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 class SH4_Calendars_Html_Admin_Controller_New
3 {
4 public function __construct(
5 HC3_Post $post,
6
7 SH4_App_Query $appQuery,
8 SH4_App_Command $appCommand,
9
10 SH4_Calendars_Command $command,
11 SH4_Calendars_Query $query,
12 SH4_Calendars_Permissions $calendarPermissions,
13 SH4_Notifications_Service $notificationService,
14
15 HC3_Hooks $hooks
16 )
17 {
18 $this->post = $hooks->wrap($post);
19 $this->command = $hooks->wrap($command);
20 $this->query = $hooks->wrap($query);
21
22 $this->appQuery = $hooks->wrap($appQuery);
23 $this->appCommand = $hooks->wrap($appCommand);
24 $this->calendarPermissions = $hooks->wrap( $calendarPermissions );
25 $this->notificationService = $hooks->wrap( $notificationService );
26 }
27
28 public function execute()
29 {
30 $title = $this->post->get('title');
31 $color = $this->post->get('color');
32 $description = $this->post->get('description');
33 $type = $this->post->get('calendar_type');
34
35 $copyFromId = $this->post->get('copy');
36
37 $newId = $this->command->create( $title, $color, $description, $type );
38
39 if( ! $copyFromId ){
40 $to = 'admin/calendars/' . $newId . '/shifttypes/new';
41 }
42 else {
43 $to = 'admin/calendars';
44
45 $copyFrom = $this->query->findById( $copyFromId );
46 $model = $this->query->findById( $newId );
47
48 // employees
49 $employees = $this->appQuery->findEmployeesForCalendar( $copyFrom );
50 foreach( $employees as $e ){
51 $this->appCommand->addEmployeeToCalendar( $e, $model );
52 }
53
54 // managers
55 $managers = $this->appQuery->findManagersForCalendar( $copyFrom );
56 foreach( $managers as $e ){
57 $this->appCommand->addManagerToCalendar( $e, $model );
58 }
59
60 // viewers
61 $viewers = $this->appQuery->findViewersForCalendar( $copyFrom );
62 foreach( $viewers as $e ){
63 $this->appCommand->addViewerToCalendar( $e, $model );
64 }
65
66 // shifttypes
67 $shifTypes = $this->appQuery->findShiftTypesForCalendar( $copyFrom );
68 foreach( $shifTypes as $e ){
69 $this->appCommand->addShiftTypeToCalendar( $e, $model );
70 }
71
72 // permissions
73 $permissions = $this->calendarPermissions->getAll( $copyFrom );
74 foreach( $permissions as $k => $v ){
75 $this->calendarPermissions->set( $model, $k, $v );
76 }
77
78 // notifications
79 $notifications = $this->notificationService->findAll();
80 foreach( $notifications as $notificationId => $notification ){
81 if( $this->notificationService->isOn($copyFrom, $notificationId) ){
82 $this->notificationService->setOn( $model, $notificationId );
83 }
84 else {
85 $this->notificationService->setOff( $model, $notificationId );
86 }
87
88 $template = $this->notificationService->getTemplate( $copyFrom, $notificationId );
89 $template2 = $this->notificationService->getTemplate( $model, $notificationId );
90 if( $template2 != $template ){
91 $this->notificationService->setTemplate( $model, $notificationId, $template );
92 }
93 }
94 }
95
96 $ret = array( $to, array('__New Calendar Added__') );
97 return $ret;
98 }
99 }