/** * Add action of issue controller. * * This action is called if the user creates a new issue. * * This is only callable as an ajax request. * * @return \Symfony\Component\HttpFoundation\Response */ public function addAction() { $request = $this->getRequest(); // Get request data $columnId = intval($request->request->get('column')); $postIssueData = $request->request->get('issue'); // If it is not a ajax request OR // if the user is not allowed to edit this column // exit here and send a HTTP header 403 Forbidden $user = $this->get('security.context')->getToken()->getUser(); $boardColumnController = new BoardColumnController(); $entityManager = $this->getDoctrine()->getEntityManager(); if ($request->isXmlHttpRequest() === FALSE || $boardColumnController->isUserAllowedToEditThisColumn($user, $columnId, $entityManager) === FALSE) { return new Response(NULL, 403); } // Get the highest sorting of a single issue at this column // This is necessary, because the new created issue will be inserted as last item $highestSorting = $this->getHighestSortingOfAColumn($columnId, $entityManager); // Get specific BoardColumn by request data column id from database $column = $entityManager->getRepository('DigitalKanbanBaseBundle:BoardColumn')->findOneById($columnId); // If there is no column with submitted column id // exit here with an error if ($column === NULL) { // It would be better, if we throw an '422 Unprocessable Entity' // but this code is an HTTP extension by WebDAV :( // With this code we want to say 'Hey, wrong ID' return new Response(NULL, 400); } // Create new issue and store it $issue = new Issue(); $issue->setName($postIssueData['title']); $issue->setSorting($highestSorting + 10); $issue->setBoardColumn($column); $issue->setCreatedUser($user); $issue->setLastEditedUser($user); $entityManager->persist($issue); $entityManager->flush(); // Build JSON response data $responseData = array('id' => $issue->getId(), 'name' => $issue->getName(), 'rotation' => $issue->getRandomRotation(), 'userIsAdmin' => $user->isAdmin()); $response = new Response(json_encode($responseData), 200); $response->headers->set('Content-Type', 'application/json'); return $response; }
/** * Update action of board controller. * * This method is called, if a user moved an issue on a kanban board to another place like another column. * * This is only callable as an ajax request. * * @return \Symfony\Component\HttpFoundation\Response */ public function updateAction() { $request = $this->getRequest(); // Get request data $columnId = intval($request->request->get('column')); $issueIds = explode(',', $request->request->get('issues')); // If it is not a ajax request OR // if the user is not allowed to edit this column // exit here and send a HTTP header 403 Forbidden $user = $this->get('security.context')->getToken()->getUser(); $boardColumnController = new BoardColumnController(); $entityManager = $this->getDoctrine()->getEntityManager(); if ($request->isXmlHttpRequest() === FALSE || $boardColumnController->isUserAllowedToEditThisColumn($user, $columnId, $entityManager) === FALSE) { return new Response(NULL, 403); } // Get specific BoardColumn by request data column id from database $column = $entityManager->getRepository('DigitalKanbanBaseBundle:BoardColumn')->findOneById($columnId); // If there is no BoardColumn with submitted id // exit here with an error if ($column instanceof BoardColumn === FALSE) { // It would be better, if we throw an '422 Unprocessable Entity' // but this code is an HTTP extension by WebDAV :( // With this code we want to say 'Hey, wrong ID' return new Response(NULL, 400); } // Get unsorted issues by issue id list from database $unsortedIssues = $entityManager->getRepository('DigitalKanbanBaseBundle:Issue')->findById($issueIds); // Sort issues from database like issues from request data ($issueIds) // It is necessary that the issues have the correct order, because in the next step // we will correct the sorting of _ALL_ issues from this board. Why? // Because one issue was moved and we want clean sorting data in database! $sortedIssues = array(); foreach ($issueIds as $issueId) { foreach ($unsortedIssues as $issue) { if ($issue->getId() == $issueId) { array_push($sortedIssues, $issue); } } } // @todo last edited user!!! // Correct sorting of sorted issues :) and store them back $sorting = 0; foreach ($sortedIssues as $issue) { $sorting += 10; $issue->setBoardColumn($column); $issue->setSorting($sorting); } $entityManager->flush(); return new Response(NULL, 200); }