/** * Permite iniciar un contador de tiempo para una tarea determinada * @author Cesar Giraldo <*****@*****.**> 06/04/2016 * @param Request $request * @return JsonResponse */ public function startTimeAction(Request $request) { $response = array('result' => '__KO__', 'msg' => ''); $em = $this->getDoctrine()->getManager(); $timeTrack = new Entity\TimeTracking(); $timeTrack->setUser($this->getUser()); $form = $this->createForm(TimeTrackType::class, $timeTrack); $form->handleRequest($request); if ($form->isSubmitted()) { $parameters = $request->request->get('backendbundle_time_track_type'); $item = null; if (isset($parameters['taskId']) && !empty($parameters['taskId'])) { $item = $em->getRepository('BackendBundle:Item')->find($parameters['taskId']); } if ($item instanceof Entity\Item && $this->container->get('access_control')->isAllowedProject($item->getProject()->getId())) { $timeTrack->setItem($item); $timeTrack->setProject($item->getProject()); $em->persist($timeTrack); $em->flush(); $response['result'] = '__OK__'; $response['timeId'] = $timeTrack->getId(); } elseif (!empty($timeTrack->getDescription())) { $em->persist($timeTrack); $em->flush(); $response['result'] = '__OK__'; $response['timeId'] = $timeTrack->getId(); } else { $response['msg'] = $this->get('translator')->trans('backend.item.not_found_message'); } } else { $response['msg'] = $this->get('translator')->trans('backend.global.unknown_error'); } return new JsonResponse($response); }
/** * Permite verificar si el usuario logueado tiene un registro de tiempo * @author Cesar Giraldo <*****@*****.**> May 25 2016 * @return \BackendBundle\Entity\TimeTracking */ public function getActiveTimeTrack() { $user = $this->tokenStorage->getToken()->getUser(); if ($user) { $searchActive = array('user' => $user->getId(), 'endTime' => null); $order = array('date' => 'DESC', 'startTime' => 'DESC'); $timeTrack = $this->em->getRepository('BackendBundle:TimeTracking')->findOneBy($searchActive, $order); if (!$timeTrack instanceof Entity\TimeTracking) { $timeTrack = new Entity\TimeTracking(); $timeTrack->setUser($user); } else { $workedTime = $this->getSecondsBetweenDates($timeTrack->getStartTime(), Util::getCurrentDate()); $timeTrack->setWorkedTime($workedTime); } return $timeTrack; } return null; }