From 5f66580100d871bd1295ff8feccc27ef24549f6f Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 16 Apr 2020 14:13:24 +0200 Subject: [PATCH] commentaire sur projecttask (ref #19) --- .../Controller/ProjectcommentController.php | 191 ++++++++++++++++++ .../PortalBundle/Entity/Projectcomment.php | 190 +++++++++++++++++ .../PortalBundle/Form/ProjectcommentType.php | 54 +++++ .../Repository/ProjectcommentRepository.php | 12 ++ .../views/Projectcomment/edit.html.twig | 53 +++++ 5 files changed, 500 insertions(+) create mode 100644 src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjectcommentController.php create mode 100644 src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projectcomment.php create mode 100644 src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjectcommentType.php create mode 100644 src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ProjectcommentRepository.php create mode 100644 src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Projectcomment/edit.html.twig diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjectcommentController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjectcommentController.php new file mode 100644 index 00000000..ee636b5d --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjectcommentController.php @@ -0,0 +1,191 @@ +routeprimary); + + if ($this->getDoctrine()->getManager()->contains($entity)) { + return $this->createForm(ProjectcommentType::class, $entity, [ + "mode" => "update", + "access" => $access, + "user" => $this->getUser() + ]); + } + else { + return $this->createForm(ProjectcommentType::class, $entity, [ + "mode" => "submit", + "access" => $access, + "user" => $this->getUser() + ]); + } + } + + public function submitAction(Request $request,$idtask,$access="config") + { + $em = $this->getDoctrine()->getManager(); + $entity = new Projectcomment(); + $projecttask=$em->getRepository("CadolesPortalBundle:Projecttask")->find($idtask); + if($projecttask) $entity->setProjecttask($projecttask); + $entity->setName("Commentaire"); + + $form = $this->entityForm($entity,$access); + $form->handleRequest($request); + + if ($form->isValid()) { + $entity->setUser($this->getUser()); + $entity->setSubmit(new \Datetime()); + + $em->persist($entity); + $em->flush(); + + foreach($entity->getProjecttask()->getProject()->getGroups() as $group) { + if($group->getFgcanshare()) { + $url=$this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$entity->getProjecttask()->getId()]); + $message="Création commentaire tâche
".$entity->getName().""; + $usergroup=$em->getRepository("CadolesCoreBundle:Usergroup")->findOneBy(["group"=>$group,"user"=>$this->getUser()]); + if($usergroup) { + $key=$usergroup->getKeyvalue(); + $websocket = $this->container->get('cadoles.websocket.pushmessage')->send($key,$this->getUser()->getId(),$group->getId(),$message); + } + } + } + + return $this->redirect($this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$entity->getProjecttask()->getId()])); + } + + return $this->render($this->labelentity.':edit.html.twig', [ + 'useheader' => ($access=="config"), + 'usemenu' => false, + 'usesidebar' => ($access=="config"), + 'maxwidth' => ($access=="user"), + 'entity' => $entity, + 'mode' => "submit", + 'access' => $access, + 'form' => $form->createView() + ]); + } + + public function updateAction(Request $request, $id,$access="config") + { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository($this->labelentity)->find($id); + if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + + // On s'assure que l'utilisateur à la permission de modifier + if($access=="user") { + $em->getRepository("CadolesPortalBundle:Project")->getPermission($this->getUser(),$entity->getProjecttask()->getProject(),$cansee,$canupdate,$canadd); + if(!$canadd&&$this->getUser()!=$entity->getUser()) throw $this->createNotFoundException('Permission denied'); + } + + // Création du formulaire + $form = $this->entityForm($entity,$access); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + foreach($entity->getProjecttask()->getProject()->getGroups() as $group) { + if($group->getFgcanshare()) { + $url=$this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$entity->getProjecttask()->getId()]); + $message="Modification commentaire tâche
".$entity->getProjecttask()->getName().""; + $usergroup=$em->getRepository("CadolesCoreBundle:Usergroup")->findOneBy(["group"=>$group,"user"=>$this->getUser()]); + if($usergroup) { + $key=$usergroup->getKeyvalue(); + $websocket = $this->container->get('cadoles.websocket.pushmessage')->send($key,$this->getUser()->getId(),$group->getId(),$message); + } + } + } + + return $this->redirect($this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$entity->getProjecttask()->getId()])); + } + + + return $this->render($this->labelentity.':edit.html.twig', [ + 'useheader' => ($access=="config"), + 'usemenu' => false, + 'usesidebar' => ($access=="config"), + 'maxwidth' => ($access=="user"), + 'entity' => $entity, + 'access' => $access, + 'mode' => "update", + 'form' => $form->createView(), + ]); + } + + public function deleteAction(Request $request, $id,$access="config") + { + $em = $this->getDoctrine()->getManager(); + $entity = $this->getDoctrine()->getRepository($this->labelentity)->find($id); + if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + + $idtask=$entity->getProjecttask()->getId(); + + // On s'assure que l'utilisateur à la permission de supprimer + if($access=="user") { + $em->getRepository("CadolesPortalBundle:Project")->getPermission($this->getUser(),$entity->getProjecttask()->getProject(),$cansee,$canupdate,$canadd); + if(!$canadd&&$this->getUser()!=$entity->getUser()) throw $this->createNotFoundException('Permission denied'); + } + + // Suppression + $em->remove($entity); + $em->flush(); + + // Retour + return $this->redirect($this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$idtask])); + } + + public function uploadAction(Request $request,$access=null) { + // Fichier temporaire uploadé + $tmpfile = $request->files->get('upload'); + $extention = $tmpfile->getClientOriginalExtension(); + + // Répertoire de Destination + $fs = new Filesystem(); + $rootdir = $this->get('kernel')->getRootDir()."/../web"; + $fs->mkdir($rootdir."/uploads/ckeditor"); + + // Fichier cible + $targetName = uniqid().".".$extention; + $targetFile = $rootdir."/uploads/ckeditor/".$targetName; + $targetUrl = "/".$this->getParameter('alias')."/uploads/ckeditor/".$targetName; + $message = ""; + + move_uploaded_file($tmpfile,$targetFile); + + $output["uploaded"]=1; + $output["fileName"]=$targetName; + $output["url"]=$targetUrl; + + return new Response(json_encode($output)); + + } + + public function imageAction($access="config") + { + return $this->render('CadolesPortalBundle:Projecttask:image.html.twig',[ + 'useheader' => false, + 'usemenu' => false, + 'usesidebar' => false, + 'access' => $access + ]); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projectcomment.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projectcomment.php new file mode 100644 index 00000000..ef0de907 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projectcomment.php @@ -0,0 +1,190 @@ +id; + } + + /** + * Set name + * + * @param string $name + * + * @return Projectcomment + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set description + * + * @param string $description + * + * @return Projectcomment + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set submit + * + * @param \DateTime $submit + * + * @return Projectcomment + */ + public function setSubmit($submit) + { + $this->submit = $submit; + + return $this; + } + + /** + * Get submit + * + * @return \DateTime + */ + public function getSubmit() + { + return $this->submit; + } + + /** + * Set user + * + * @param \Cadoles\CoreBundle\Entity\User $user + * + * @return Projectcomment + */ + public function setUser(\Cadoles\CoreBundle\Entity\User $user = null) + { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return \Cadoles\CoreBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } + + /** + * Set projecttask + * + * @param \Cadoles\PortalBundle\Entity\Projecttask $projecttask + * + * @return Projectcomment + */ + public function setProjecttask(\Cadoles\PortalBundle\Entity\Projecttask $projecttask) + { + $this->projecttask = $projecttask; + + return $this; + } + + /** + * Get projecttask + * + * @return \Cadoles\PortalBundle\Entity\Projecttask + */ + public function getProjecttask() + { + return $this->projecttask; + } +} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjectcommentType.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjectcommentType.php new file mode 100644 index 00000000..ea521f75 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/ProjectcommentType.php @@ -0,0 +1,54 @@ +add('submit', SubmitType::class, [ + "label" => ($options["mode"]=="delete"?"Confirmer la Suppression":"Valider"), + "attr" => ($options["mode"]=="delete"?array("class" => "btn btn-danger"):array("class" => "btn btn-success")) + ]) + + ->add('name', TextType::class, [ + 'label' => 'Titre' + ]) + + ->add("description",CKEditorType::class,[ + "config_name" => 'full_config', + "label" => 'Description', + "required" => false, + "disabled" => ($options["mode"]=="delete"?true:false), + "config" => ["height" => "500px",'filebrowserUploadRoute' => 'cadoles_portal_'.$options["access"].'_projectcomment_upload'] + ]); + + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'Cadoles\PortalBundle\Entity\Projectcomment', + 'mode' => 'string', + 'access' => 'string', + 'user' => 'Cadoles\CoreBundle\Entity\User' + ]); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ProjectcommentRepository.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ProjectcommentRepository.php new file mode 100644 index 00000000..5c10cf4a --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ProjectcommentRepository.php @@ -0,0 +1,12 @@ + + {% if mode=="update" %} + Modification Commentaire Tache + {% elseif mode=="submit" %} + Création Commentaire Tache + {% endif %} + + + {{ form_widget(form.submit) }} + Annuler + + {% if mode=="update" %} + + Supprimer + + {% endif %} + +

+ + {% if app.session.flashbag.has('error') %} +
+ Erreur
+ {% for flashMessage in app.session.flashbag.get('error') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + {% if app.session.flashbag.has('notice') %} +
+ Information
+ {% for flashMessage in app.session.flashbag.get('notice') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + +
+ {{ form_row(form.name) }} + {{ form_row(form.description) }} +
+ + +{{ form_end(form) }} +{% endblock %}