/** * @inheritDoc * As a manager, I want to schedule my employees, by creating shifts for any employee. */ public function __invoke(array $input) { //make sure an employee with the given id exists if (false === parent::__invoke($input)) { return $this->payload->withStatus(PayloadInterface::INVALID); } //var_dump($input); $shift = new Shift(); $shift->setStart_time(new \DateTime($input['start_time'])); if (false === $shift->setEnd_time(new \DateTime($input['end_time']))) { return $this->payload->withStatus(PayloadInterface::INVALID); } if (ctype_digit($input['employee_id'])) { //todo: make sure employee isn't already working shift $shift->setEmployee($this->entityManager->getReference('Spark\\Project\\Entity\\User\\Employee', $input['employee_id'])); } $manager_id = ctype_digit($input['shift_manager_id']) ? $input['shift_manager_id'] : $this->manager->getId(); $shift->setManager($this->entityManager->getReference('Spark\\Project\\Entity\\User\\Manager', $manager_id)); $shift->setBreak($input['break']); $this->entityManager->persist($shift); $this->entityManager->flush(); return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['shift' => $shift->getId()]); }