Example #1
0
 public function createShortAction()
 {
     /** @var Request $request */
     $request = $this->container->get('request_stack')->getCurrentRequest();
     $action = new Action();
     $user = $this->container->get('security.context')->getToken()->getUser();
     $action->setUser($user);
     $form = $this->createForm(new ActionCreateShortFormType(), $action, array('em' => $this->getDoctrine()->getManager()));
     $form->handleRequest($request);
     $success = false;
     if ($form->isValid()) {
         $userAction = new UserAction();
         $userAction->setUser($user);
         $userAction->setIsDeleted(false);
         $action->addUserAction($userAction);
         $em = $this->getDoctrine()->getManager();
         $em->persist($action);
         $em->flush();
         $success = true;
     }
     if ($success) {
         if ($request->isXmlHttpRequest()) {
             return new JsonResponse(['success' => true, 'text' => $this->renderView('AcmeEdelaBundle:Actions:_one_block.html.twig', array('action' => $action, 'progress' => null))]);
         } else {
             return new RedirectResponse($this->container->get('router')->generate('tasks_edit', array('task_id' => $action->getId())));
         }
     } else {
         return new JsonResponse(['success' => false]);
     }
 }
Example #2
0
 /**
  * Add userActions
  *
  * @param \Acme\EdelaBundle\Entity\UserAction $userActions
  * @return Action
  */
 public function addUserAction(\Acme\EdelaBundle\Entity\UserAction $userActions)
 {
     $userActions->setAction($this);
     $this->userActions[] = $userActions;
     return $this;
 }
Example #3
0
 /**
  * @Rest\View
  * @Rest\Post("/samples/{id}")
  */
 public function addFromSamplesAction(Request $request, $id)
 {
     $sample = $this->getDoctrine()->getManager()->find('AcmeEdelaBundle:Sample', $id);
     if (!$sample) {
         return $this->createNotFoundException();
     }
     $action = new Action();
     $user = $this->container->get('security.context')->getToken()->getUser();
     $action->setUser($user);
     $action->setTitle($sample->getTitle());
     $em = $this->getDoctrine()->getManager();
     if ($request->get('goal') && ($goal = $em->find('AcmeEdelaBundle:Goal', $request->get('goal')))) {
         $action->setGoal($goal);
     }
     $userAction = new UserAction();
     $userAction->setUser($user);
     $userAction->setStartAt(new \DateTime());
     $actionType = $em->getRepository('AcmeEdelaBundle:ActionType')->findOneBy(['tkey' => 'done']);
     $action->setActionType($actionType);
     $dynamicType = $em->getRepository('AcmeEdelaBundle:ActionDynamicType')->findOneBy(['tkey' => 'up']);
     $action->setActionDynamicType($dynamicType);
     $action->addUserAction($userAction);
     $em = $this->getDoctrine()->getManager();
     $em->persist($action);
     $em->flush();
     return ['id' => $action->getId(), 'title' => $action->getTitle(), 'progress' => false];
 }