/**
  * @param int $id
  * @return StandardResponse
  */
 public function getUser($id)
 {
     $response = new StandardResponse();
     $response->setMessage('User not found');
     $queryString = 'SELECT user FROM \\App\\Entity\\User user WHERE user.id = :id';
     $user = $this->em->createQuery($queryString)->setParameter('id', (int) $id)->getArrayResult();
     if (isset($user[0])) {
         $response->setSuccess(true);
         $response->setMessage('Here is the user.');
         $response->setData($user[0]);
     }
     return $response->getObjectVars();
 }
 /**
  * @return array
  */
 public function getAllEmployees()
 {
     $response = new StandardResponse();
     $queryString = "SELECT user.id, user.name, user.role, user.email, user.phone, user.created_at, user.updated_at " . "FROM \\App\\Entity\\User user WHERE user.role = 'employee'";
     $query = $this->em->createQuery($queryString);
     $results = $query->getArrayResult();
     if ($results) {
         $response->setSuccess(true);
         $response->setMessage('Here are the employees.');
         $response->setData($results);
     }
     return $response->getObjectVars();
 }
Beispiel #3
0
 /**
  * @param Request $request
  * @param int $type
  * @param bool $catch
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $em = DoctrineAdapter::getEntityManager();
     if (isset($_COOKIE['token'])) {
         $token = unserialize($_COOKIE['token']);
         $key = $token['key'];
         $user = $em->find('App\\Entity\\User', $token['id']);
         $this->app->user = $user;
         $role = $user->getRole();
     } else {
         $key = null;
         $role = null;
     }
     $route = $request->getPathInfo();
     $protectedRoutes = ['/shifts' => ['access' => ['manager']]];
     if (array_key_exists($route, $protectedRoutes) && (!$key || $key !== AccountApi::$secretKey || !in_array($role, $protectedRoutes[$route]['access']))) {
         header('Content-Type', 'application/json');
         $response = new StandardResponse();
         $response->setMessage('You are not authorized to access this route.');
         echo json_encode($response->getObjectVars());
     } else {
         return $this->app->handle($request);
     }
 }
 /**
  * @param array $data
  * @return bool
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  */
 public function save(array $data)
 {
     $response = new StandardResponse();
     if (isset($data['id'])) {
         $shift = $this->em->find('App\\Entity\\Shift', (int) $data['id']);
     } else {
         $shift = new Shift();
         $shift->setCreatedAt(new \DateTime());
     }
     $shift->setManagerId($data['manager_id']);
     $shift->setEmployeeId($data['employee_id']);
     $shift->setBreak($data['break']);
     $shift->setStartTime($data['start_time']);
     $shift->setEndTime($data['end_time']);
     $shift->setUpdatedAt(new \DateTime());
     $this->em->persist($shift);
     try {
         $response->setSuccess(true);
         $response->setMessage('You have successfully saved the shift.');
         $this->flush();
     } catch (\Exception $e) {
     }
     return $response->getObjectVars();
 }