Exemple #1
0
 public function testCreateShifts()
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('count(s.id)');
     $qb->from('Spark\\Project\\Entity\\Shift', 's');
     $preCount = $qb->getQuery()->getSingleScalarResult();
     $managers = $this->em->getRepository('Spark\\Project\\Entity\\User\\Manager')->findAll(Doctrine\ORM\Query::HYDRATE_ARRAY);
     foreach (range(1, 10) as $i) {
         $shift = new Shift();
         $shift->setBreak(rand(0, 100));
         $start_time = time() + rand(1, 9999);
         $shift->setStart_Time(new \DateTime(date('Y-m-d H:i:s', $start_time)));
         $end_time = $start_time + 3600;
         $shift->setEnd_Time(new \DateTime(date('Y-m-d H:i:s', $end_time)));
         $shift->setManager($managers[rand(0, count($managers) - 1)]);
         $this->em->persist($shift);
     }
     $this->em->flush();
     $postCount = $qb->getQuery()->getSingleScalarResult();
     $this->assertEquals($preCount + $i, $postCount);
 }
Exemple #2
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()]);
 }