/** * @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(); }
/** * @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(); }
/** * @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(); }