/**
  * 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;
 }
 public function load(ObjectManager $manager)
 {
     /**
      * ROLES
      */
     // Create the ROLE_ADMIN role
     $adminRole = new Role();
     $adminRole->setName('ROLE_ADMIN');
     $adminRole->setDescription('Administration. This group is focused on system management.');
     $manager->persist($adminRole);
     // Create the ROLE_USER role
     $userRole = new Role();
     $userRole->setName('ROLE_USER');
     $userRole->setDescription("Normal usergroup. For example employees.");
     $manager->persist($userRole);
     /**
      * BOARDS
      */
     // Create board 'Team E-Commerce'
     $board1 = new Board();
     $board1->setName('Team E-Commerce');
     $board1->setDescription('Kanban-board of e-commerce-team. Displays issues from topics online-shopping, electronic trading/commerce and development of websites like online shops. Systems which are used are for example Magento, Oxid or Terrashop.');
     $manager->persist($board1);
     // Create board 'Team Human Resources'
     $board2 = new Board();
     $board2->setName('Team Human Resources');
     $board2->setDescription('Kanban-board of staff department. Working and managing at issues for human resources. For example different topics of employees, payment of them, hiring new people, organize travel for team events and ask for working feedback.');
     $manager->persist($board2);
     // Create board 'Team Backend-Development'
     $board3 = new Board();
     $board3->setName('Team Backend-Development');
     $board3->setDescription('Kanban-board of backend-development-team. Tasks for connection different websites with third party systems like ERP or CRM.');
     $manager->persist($board3);
     /**
      * USER
      */
     // Create a admin user 'John Doe'
     $adminUser = new User();
     $adminUser->setFirstName('John');
     $adminUser->setLastName('Doe');
     $adminUser->setUsername('john');
     $adminUser->setEmail('*****@*****.**');
     $adminUser->getBoards()->add($board1);
     $adminUser->getBoards()->add($board3);
     $adminUser->setSalt(md5(uniqid(microtime())));
     $adminUser->setPassword('admin');
     $adminUser->addRole($adminRole);
     $manager->persist($adminUser);
     // Create a normal user 'Max Mustermann'
     $normalUser = new User();
     $normalUser->setFirstName('Max');
     $normalUser->setLastName('Mustermann');
     $normalUser->setUsername('max');
     $normalUser->setEmail('*****@*****.**');
     $normalUser->getBoards()->add($board2);
     $normalUser->getBoards()->add($board3);
     $normalUser->setSalt(md5(uniqid(microtime())));
     $normalUser->setPassword('user');
     $normalUser->addRole($userRole);
     $manager->persist($normalUser);
     // Create a deactivated normal user 'Dieter Müller'
     $deactivatedNormalUser = new User();
     $deactivatedNormalUser->setFirstName('Dieter');
     $deactivatedNormalUser->setLastName('Müller');
     $deactivatedNormalUser->setUsername('dieter');
     $deactivatedNormalUser->setEmail('*****@*****.**');
     $deactivatedNormalUser->getBoards()->add($board2);
     $deactivatedNormalUser->getBoards()->add($board3);
     $deactivatedNormalUser->setSalt(md5(uniqid(microtime())));
     $deactivatedNormalUser->setPassword('user');
     $deactivatedNormalUser->setDisabled(TRUE);
     $deactivatedNormalUser->addRole($userRole);
     $manager->persist($deactivatedNormalUser);
     // Create a admin user 'Markus Ele'
     $anotherAdminUser = new User();
     $anotherAdminUser->setFirstName('Markus');
     $anotherAdminUser->setLastName('Ele');
     $anotherAdminUser->setUsername('markus');
     $anotherAdminUser->setEmail('*****@*****.**');
     $anotherAdminUser->getBoards()->add($board1);
     $anotherAdminUser->getBoards()->add($board2);
     $anotherAdminUser->getBoards()->add($board3);
     $anotherAdminUser->setSalt(md5(uniqid(microtime())));
     $anotherAdminUser->setPassword('user');
     $anotherAdminUser->setDisabled(FALSE);
     $anotherAdminUser->addRole($adminRole);
     $manager->persist($anotherAdminUser);
     // Create a normal user 'Daniel Schmi'
     $anotherNormalUser = new User();
     $anotherNormalUser->setFirstName('Daniel');
     $anotherNormalUser->setLastName('Schmi');
     $anotherNormalUser->setUsername('daniel');
     $anotherNormalUser->setEmail('*****@*****.**');
     $anotherNormalUser->getBoards()->add($board1);
     $anotherNormalUser->setSalt(md5(uniqid(microtime())));
     $anotherNormalUser->setPassword('user');
     $anotherNormalUser->setDisabled(FALSE);
     $anotherNormalUser->addRole($userRole);
     $manager->persist($anotherNormalUser);
     /**
      * BOARD COLUMNS
      */
     // Create first board column 'Backlog' for board 'Team E-Commerce'
     $board1Column1 = new BoardColumn();
     $board1Column1->setName('Backlog');
     $board1Column1->setMaxIssues(0);
     $board1Column1->setSorting(10);
     $board1Column1->setBoard($board1);
     $manager->persist($board1Column1);
     // Create second board column 'ToDo' for board 'Team E-Commerce'
     $board1Column2 = new BoardColumn();
     $board1Column2->setName('ToDo');
     $board1Column2->setMaxIssues(10);
     $board1Column2->setSorting(20);
     $board1Column2->setBoard($board1);
     $manager->persist($board1Column2);
     // Create third board column 'Analysis' for board 'Team E-Commerce'
     $board1Column3 = new BoardColumn();
     $board1Column3->setName('Analysis');
     $board1Column3->setMaxIssues(4);
     $board1Column3->setSorting(30);
     $board1Column3->setBoard($board1);
     $manager->persist($board1Column3);
     // Create fourth board column 'Development' for board 'Team E-Commerce'
     $board1Column4 = new BoardColumn();
     $board1Column4->setName('Development');
     $board1Column4->setMaxIssues(2);
     $board1Column4->setSorting(40);
     $board1Column4->setBoard($board1);
     $manager->persist($board1Column4);
     // Create fifth board column 'Approval' for board 'Team E-Commerce'
     $board1Column5 = new BoardColumn();
     $board1Column5->setName('Approval');
     $board1Column5->setMaxIssues(0);
     $board1Column5->setSorting(50);
     $board1Column5->setBoard($board1);
     $manager->persist($board1Column5);
     // Create sixth board column 'Deploy' for board 'Team E-Commerce'
     $board1Column6 = new BoardColumn();
     $board1Column6->setName('Deploy');
     $board1Column6->setMaxIssues(3);
     $board1Column6->setSorting(60);
     $board1Column6->setBoard($board1);
     $manager->persist($board1Column6);
     // Create seventh board column 'Done' for board 'Team E-Commerce'
     $board1Column7 = new BoardColumn();
     $board1Column7->setName('Done');
     $board1Column7->setMaxIssues(0);
     $board1Column7->setSorting(70);
     $board1Column7->setBoard($board1);
     $manager->persist($board1Column7);
     // Create first board column 'Job requests' for board 'Team Human Resources'
     $board2Column1 = new BoardColumn();
     $board2Column1->setName('Job requests');
     $board2Column1->setMaxIssues(15);
     $board2Column1->setSorting(10);
     $board2Column1->setBoard($board2);
     $manager->persist($board2Column1);
     // Create second board column 'Job meeting' for board 'Team Human Resources'
     $board2Column2 = new BoardColumn();
     $board2Column2->setName('Job meeting');
     $board2Column2->setMaxIssues(2);
     $board2Column2->setSorting(20);
     $board2Column2->setBoard($board2);
     $manager->persist($board2Column2);
     // Create third board column 'Done' for board 'Team Human Resources'
     $board2Column3 = new BoardColumn();
     $board2Column3->setName('Done');
     $board2Column3->setMaxIssues(0);
     $board2Column3->setSorting(30);
     $board2Column3->setBoard($board2);
     $manager->persist($board2Column3);
     /**
      * ISSUES
      */
     // Create first issue for column 'Backlog'
     $issue1 = new Issue();
     $issue1->setName('Evaluate Paypal module for Magento');
     $issue1->setSorting(30);
     $issue1->setBoardColumn($board1Column1);
     $issue1->setCreatedUser($adminUser);
     $issue1->setLastEditedUser($adminUser);
     $manager->persist($issue1);
     // Create second issue for column 'Backlog'
     $issue2 = new Issue();
     $issue2->setName('Evaluate Paypal module for Oxid');
     $issue2->setSorting(20);
     $issue2->setBoardColumn($board1Column1);
     $issue2->setCreatedUser($normalUser);
     $issue2->setLastEditedUser($normalUser);
     $manager->persist($issue2);
     // Create third issue for column 'Backlog'
     $issue3 = new Issue();
     $issue3->setName('Insert new design collection to Karl Lagerfelds onlineshop');
     $issue3->setSorting(10);
     $issue3->setBoardColumn($board1Column1);
     $issue3->setCreatedUser($adminUser);
     $issue3->setLastEditedUser($adminUser);
     $manager->persist($issue3);
     // Create first issue for column 'Analysis'
     $issue4 = new Issue();
     $issue4->setName('Hash user passwords in database for more security');
     $issue4->setSorting(10);
     $issue4->setBoardColumn($board1Column3);
     $issue4->setCreatedUser($deactivatedNormalUser);
     $issue4->setLastEditedUser($deactivatedNormalUser);
     $manager->persist($issue4);
     // Create fourth issue for column 'Backlog'
     $issue5 = new Issue();
     $issue5->setName('Write a new magento module to take A/B usability tests');
     $issue5->setSorting(40);
     $issue5->setBoardColumn($board1Column1);
     $issue5->setCreatedUser($normalUser);
     $issue5->setLastEditedUser($adminUser);
     $manager->persist($issue5);
     // Create first issue for column 'Development'
     $issue6 = new Issue();
     $issue6->setName('"Sign up" function for newsletter at Levis online shop');
     $issue6->setSorting(10);
     $issue6->setBoardColumn($board1Column4);
     $issue6->setCreatedUser($adminUser);
     $issue6->setLastEditedUser($normalUser);
     $manager->persist($issue6);
     // Create first issue for column 'Job requests'
     $issue7 = new Issue();
     $issue7->setName('Dennis Putta requested via Linked.in');
     $issue7->setSorting(10);
     $issue7->setBoardColumn($board2Column1);
     $issue7->setCreatedUser($adminUser);
     $issue7->setLastEditedUser($adminUser);
     $manager->persist($issue7);
     // Create first issue for column 'Done'
     $issue8 = new Issue();
     $issue8->setName('Hire a new java developer');
     $issue8->setSorting(10);
     $issue8->setBoardColumn($board2Column3);
     $issue8->setCreatedUser($adminUser);
     $issue8->setLastEditedUser($adminUser);
     $manager->persist($issue8);
     $manager->flush();
 }