post = $hooks->wrap($post); $this->command = $hooks->wrap($command); $this->employeesQuery = $hooks->wrap( $employeesQuery ); $this->appQuery = $hooks->wrap( $appQuery ); $this->appCommand = $hooks->wrap( $appCommand ); $this->calendarsQuery = $hooks->wrap( $calendarsQuery ); } public function execute() { $title = $this->post->get('title'); $description = $this->post->get('description'); $calendarIds = $this->post->get('calendar'); if( ! $calendarIds ){ $calendarIds = array(); } $employeeId = $this->command->create( $title, $description ); if( $employeeId ){ if( ! $calendarIds ){ $calendarIds = array(); } $calendars = $calendarIds ? $this->calendarsQuery->findManyActiveById( $calendarIds ) : array(); if( $calendars ){ $employee = $this->employeesQuery->findById( $employeeId ); reset( $calendars ); foreach( $calendars as $calendar ){ $this->appCommand->addEmployeeToCalendar( $employee, $calendar ); } } } $return = array( 'admin/employees', '__New Employee Added__' ); return $return; } }