/** * @Route("/documents/uploadprofiles/{id}/deactivate", name="documentBundle_uploadprofiles_deactivate", requirements={"id" = "\d+"}) * @Template() */ public function DeactivateUploadProfileAction(Request $request, $id) { /* * CHECK FOR PERMISSIONS * TODO: Check if the acting user has all needed permissions to perform this action. */ if ($this->get('security.authorization_checker')->isGranted('ROLE_SPC')) { /* * GET UPLOADPROFILE FROM DB */ $em = $this->getDoctrine()->getManager(); $updated_uploadprofile = $em->getRepository('DocumentBundle:UploadProfiles')->find($id); /* * IF UPLOADPROFILE IS ACTIVE */ if ($updated_uploadprofile->isActive()) { /***********************Mail-Service************************/ //Parameter: $subject = 'Document has been created.'; $toAdress = '*****@*****.**'; $content = 'A document has been deactivated'; //call: $this->get('MailSender')->sendMail($subject, $toAdress, $content); /***********************************************************/ // TODO: Send email with activation link to verify the user's email address! TODO: Create Event /* * GET CURRENT USER */ $user = $this->get('security.token_storage')->getToken()->getUser(); /* * DEACTIVATE UPLOADPROFILE */ $updated_uploadprofile->setActive(false); /* * ADD AN APPROVAL COMMENT */ $comment = new \CommentBundle\Entity\Comment(); $comment->setComment('<strong>Upload Profile was deactivated.</strong>'); $comment->setUploadProfile($updated_uploadprofile); $comment->setAuthor($user); /* * PERSIST DATA */ $em->persist($updated_uploadprofile); $em->persist($comment); $em->flush(); /* * DISPLAY SUCCESS MESSAGE */ return $this->render('DocumentBundle:Action/UploadProfiles:deactivated.html.twig', array('success' => true, 'updated_uploadprofile' => $updated_uploadprofile, 'menu' => array('top' => 'Document'))); } else { /* * DISPLAY ERROR MESSAGE */ return $this->render('DocumentBundle:Action/UploadProfiles:deactivated.html.twig', array('success' => false, 'updated_uploadprofile' => $updated_uploadprofile, 'menu' => array('top' => 'Document'))); } } else { /* * THROW ERROR * If the acting user is not allowed to perform this action */ $error_msg = 'error.access.action'; // Error message $reason = implode(', ', $this->get('security.token_storage')->getToken()->getUser()->getRoles()); return $this->render('UserBundle:Error:error.html.twig', array('error_msg' => $error_msg, 'reason' => $reason)); } }
/** * @Route("/documents/document/{id}/addAgency", name="documentBundle_document_addAgency", requirements={"id" = "\d+"}) * @Method("POST") * @Template() */ public function addAgencyAction(Request $request, $id) { /* * CHECK FOR PERMISSIONS * TODO: Check if the acting user has all needed permissions to perform this action. */ if ($this->get('security.authorization_checker')->isGranted('ROLE_CONTRACT_ADMIN')) { /* * GET DOCUMENT FROM DB */ $em = $this->getDoctrine()->getManager(); $document = $em->getRepository('DocumentBundle:Document')->find($id); //Get all UploadProfiles $allAgencies = $this->getDoctrine()->getRepository('AppBundle:Agency')->findAll(); /* * GET CURRENT USER */ $user = $this->get('security.token_storage')->getToken()->getUser(); if (isset($_POST['agSelectDistriList'])) { // \Doctrine\Common\Util\Debug::dump($_POST['agSelectDistriList']); // echo 'test'; $agencies = $_POST['agSelectDistriList']; // Add agencies to upload profiles $zl = 0; foreach ($agencies as $ag) { $ag = $em->getRepository('AppBundle:Agency')->find($ag); $document->addAgency($ag); ++$zl; } // Add comments to Log $zl1 = 0; foreach ($agencies as $ag) { /* * ADD AN COMMENT */ $comment = new \CommentBundle\Entity\Comment(); $ag = $em->getRepository('AppBundle:Agency')->find($ag); $comment->setComment('<strong>"' . $ag->getIataName() . '" was added to "' . $document->getName() . '" </strong>'); $comment->setDocument($document); $comment->setAuthor($user); $em->persist($comment); ++$zl1; } $document->setModifiedBy($this->get('security.token_storage')->getToken()->getUser()); $document->setModified(new \DateTime("now")); $em->persist($document); $em->flush(); } /* * REDERICT TO THE UPDATED PROFILE PROFILE */ $response = new RedirectResponse($this->get('router')->generate('documentBundle_show_document', array('id' => $document->getId()))); $response->send(); } else { /* * REDERICT TO THE UPDATED PROFILE PROFILE */ $response = new RedirectResponse($this->get('router')->generate('documentBundle_show_document', array('id' => $document->getId()))); $response->send(); } }