| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Employees_Html_Admin_Controller_New |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
HC3_Post $post, |
| 8 |
|
| 9 |
SH4_Calendars_Query $calendarsQuery, |
| 10 |
SH4_Employees_Query $employeesQuery, |
| 11 |
SH4_App_Query $appQuery, |
| 12 |
SH4_App_Command $appCommand, |
| 13 |
SH4_Employees_Command $command |
| 14 |
) |
| 15 |
{ |
| 16 |
$this->post = $hooks->wrap($post); |
| 17 |
$this->command = $hooks->wrap($command); |
| 18 |
|
| 19 |
$this->employeesQuery = $hooks->wrap( $employeesQuery ); |
| 20 |
|
| 21 |
$this->appQuery = $hooks->wrap( $appQuery ); |
| 22 |
$this->appCommand = $hooks->wrap( $appCommand ); |
| 23 |
$this->calendarsQuery = $hooks->wrap( $calendarsQuery ); |
| 24 |
} |
| 25 |
|
| 26 |
public function execute() |
| 27 |
{ |
| 28 |
$title = $this->post->get('title'); |
| 29 |
$description = $this->post->get('description'); |
| 30 |
|
| 31 |
$calendarIds = $this->post->get('calendar'); |
| 32 |
if( ! $calendarIds ){ |
| 33 |
$calendarIds = array(); |
| 34 |
} |
| 35 |
|
| 36 |
$employeeId = $this->command->create( $title, $description ); |
| 37 |
|
| 38 |
if( $employeeId ){ |
| 39 |
if( ! $calendarIds ){ |
| 40 |
$calendarIds = array(); |
| 41 |
} |
| 42 |
$calendars = $calendarIds ? $this->calendarsQuery->findManyActiveById( $calendarIds ) : array(); |
| 43 |
|
| 44 |
if( $calendars ){ |
| 45 |
$employee = $this->employeesQuery->findById( $employeeId ); |
| 46 |
reset( $calendars ); |
| 47 |
foreach( $calendars as $calendar ){ |
| 48 |
$this->appCommand->addEmployeeToCalendar( $employee, $calendar ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
$return = array( 'admin/employees', '__New Employee Added__' ); |
| 54 |
return $return; |
| 55 |
} |
| 56 |
} |