PluginProbe
ShiftController Employee Shift Scheduling / 4.9.95
ShiftController Employee Shift Scheduling v4.9.95
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.95, at sh4/calendars/html/admin/controller/new.php

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