예제 #1
0
 /**
  * As a manager, I want to be able to assign a shift, by changing the employee that will work a shift.
  */
 public function __invoke(array $input)
 {
     $shift = $this->entityManager->getRepository('Spark\\Project\\Entity\\Shift')->find($input['shift_id']);
     //make sure a manager with the given id exists
     if (false === $shift || false === parent::__invoke($input)) {
         return $this->payload->withStatus(PayloadInterface::INVALID);
     }
     $shift->setEmployee($this->entityManager->getReference('Spark\\Project\\Entity\\User\\Employee', $input['employee_id']));
     $this->entityManager->persist($shift);
     $this->entityManager->flush();
     return $this->payload->withStatus(PayloadInterface::OK);
 }
예제 #2
0
 /**
  * @inheritDoc
  *  As a manager, I want to see the schedule, by listing shifts within a specific time period
  */
 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);
     }
     $shifts = [];
     $qb = $this->entityManager->createQueryBuilder();
     $qb->select("s")->from('Spark\\Project\\Entity\\Shift', 's')->where('s.start_time between :start_time and :end_time')->orderBy("s.start_time", 'DESC')->setParameter('start_time', new \DateTime($input['start_date']))->setParameter('end_time', new \DateTime($input['end_date']));
     foreach ($qb->getQuery()->getResult() as $shift) {
         $shifts[] = ['id' => $shift->getId(), 'start_time' => $shift->getStart_time()->format(constant("DateTime::{$this->date_format}")), 'end_time' => $shift->getEnd_time()->format(constant("DateTime::{$this->date_format}")), 'employee' => $shift->getEmployee() ? ['id' => $shift->getEmployee()->getId(), 'name' => $shift->getEmployee()->getName(), 'phone' => $shift->getEmployee()->getPhone(), 'email' => $shift->getEmployee()->getEmail()] : null, 'manager' => $shift->getManager() ? ['id' => $shift->getManager()->getId(), 'name' => $shift->getManager()->getName(), 'phone' => $shift->getManager()->getPhone(), 'email' => $shift->getManager()->getEmail()] : null];
     }
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['shifts' => $shifts, 'input' => $input]);
 }
예제 #3
0
 /**
  * @inheritDoc
  * As a manager, I want to be able to change a shift, by updating the time details.
  */
 public function __invoke(array $input)
 {
     $shift = $this->entityManager->getRepository('Spark\\Project\\Entity\\Shift')->find($input['shift_id']);
     //make sure a manager with the given id exists
     if (false === $shift || false === parent::__invoke($input)) {
         return $this->payload->withStatus(PayloadInterface::INVALID);
     }
     $shift->setStart_Time(new \DateTime(urldecode($input['start_time'])));
     if (false !== $shift->setEnd_Time(new \DateTime(urldecode($input['end_time'])))) {
         $this->entityManager->persist($shift);
         $this->entityManager->flush();
         $status = PayloadInterface::OK;
     } else {
         $status = PayloadInterface::INVALID;
     }
     return $this->payload->withStatus($status);
 }
예제 #4
0
 /**
  * @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()]);
 }