From dfdf3ff9f580606e9e8f81f9b9bbf9e852dcb1bd Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 16 Apr 2020 11:51:48 +0200 Subject: [PATCH] finalisation widget project (ref #19) --- .../CoreBundle/Controller/FileController.php | 2 +- .../src/Cadoles/CoreBundle/Entity/User.php | 42 ++++++++++++++++ .../EventListener/uploadListener.php | 23 ++++++++- .../Controller/ProjecttaskController.php | 32 +++++++++++- .../PortalBundle/Entity/Projecttask.php | 50 +++++++++++++++++++ .../PortalBundle/Resources/config/routing.yml | 38 ++++++++++++++ .../views/Blogcomment/edit.html.twig | 7 --- .../views/Projecttask/view.html.twig | 26 ++++++++-- .../WebsocketBundle/Topic/WebsocketTopic.php | 2 +- 9 files changed, 207 insertions(+), 15 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php index 7add7ac1..c1af414c 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/FileController.php @@ -181,7 +181,7 @@ class FileController extends Controller if(!$cansee) throw $this->createNotFoundException('Permission denied'); break; - case "taskproject": + case "projecttask": // Récupération de la tache $projecttask=$em->getRepository("CadolesPortalBundle:Projecttask")->find($id); if (!$projecttask) throw $this->createNotFoundException('Unable to find entity.'); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php index 7e975c37..aca42c5b 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php @@ -298,6 +298,14 @@ class User implements UserInterface, \Serializable */ private $projectownertasks; + /** + * @var ArrayCollection $projectcomment + * @var Projectcomment + * + * @ORM\OneToMany(targetEntity="Cadoles\PortalBundle\Entity\Projectcomment", mappedBy="user", cascade={"persist"}, orphanRemoval=true) + */ + private $projectcomments; + /** * @var ArrayCollection $icon * @var Icon @@ -1754,4 +1762,38 @@ class User implements UserInterface, \Serializable { return $this->projectownertasks; } + + /** + * Add projectcomment + * + * @param \Cadoles\PortalBundle\Entity\Projectcomment $projectcomment + * + * @return User + */ + public function addProjectcomment(\Cadoles\PortalBundle\Entity\Projectcomment $projectcomment) + { + $this->projectcomments[] = $projectcomment; + + return $this; + } + + /** + * Remove projectcomment + * + * @param \Cadoles\PortalBundle\Entity\Projectcomment $projectcomment + */ + public function removeProjectcomment(\Cadoles\PortalBundle\Entity\Projectcomment $projectcomment) + { + $this->projectcomments->removeElement($projectcomment); + } + + /** + * Get projectcomments + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getProjectcomments() + { + return $this->projectcomments; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/uploadListener.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/uploadListener.php index c3377623..aac87bcd 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/uploadListener.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/EventListener/uploadListener.php @@ -128,8 +128,7 @@ class uploadListener $fs->rename($pathname."/".$directory."/thumb/".$filename.".jpg", $pathname."/".$directory."/thumb/".$filename); } - $fgexit=$fs->exists($pathname."/".$directory."/thumb/".$filename); - if($fgexit) { + if($fs->exists($pathname."/".$directory."/thumb/".$filename)) { $fs->mkdir($pathname."/".$directory."/thumbmini"); $fs->copy($pathname."/".$directory."/thumb/".$filename,$pathname."/".$directory."/thumbmini/".$filename); $max_width=60; @@ -159,6 +158,26 @@ class uploadListener } } + if (strpos($directory, 'projecttask') === 0) { + $tmp=explode("-",$directory); + $projecttaskid=$tmp[1]; + $projecttask=$this->em->getRepository("CadolesPortalBundle:Projecttask")->find($projecttaskid); + if($projecttask) { + foreach($projecttask->getProject()->getGroups() as $group) { + if($group->getFgcanshare()) { + if($fgexit) $message="Modification fichier dans la tâche ".$projecttask->getName()."
".$filename; + else $message="Création fichier dans la tâche ".$projecttask->getName()."
".$filename; + + $usergroup=$this->em->getRepository("CadolesCoreBundle:Usergroup")->findOneBy(["group"=>$group,"user"=>$this->token->getToken()->getUser()]); + if($usergroup) { + $key=$usergroup->getKeyvalue(); + $websocket = $this->container->get('cadoles.websocket.pushmessage')->send($key,$this->token->getToken()->getUser()->getId(),$group->getId(),$message); + } + } + } + } + } + $response = $event->getResponse(); $response['file'] = $filename; break; diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php index 53b119f1..4bd41adf 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/ProjecttaskController.php @@ -9,6 +9,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpFoundation\File\File; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Cadoles\PortalBundle\Entity\Projecttask; use Cadoles\PortalBundle\Form\ProjecttaskType; @@ -59,6 +60,10 @@ class ProjecttaskController extends Controller $em->persist($entity); $em->flush(); + if($entity->getUser()&&$entity->getUser()!=$entity->getOwner()) { + $this->notifMail($entity); + } + foreach($entity->getProject()->getGroups() as $group) { if($group->getFgcanshare()) { $url=$this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$entity->getId()]); @@ -92,6 +97,7 @@ class ProjecttaskController extends Controller $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); $oldpercentage=$entity->getPercentage(); + $olduser=$entity->getUser(); // On s'assure que l'utilisateur à la permission de modifier if($access=="user") { @@ -111,6 +117,11 @@ class ProjecttaskController extends Controller $em->persist($entity); $em->flush(); + if($entity->getUser()&&$entity->getUser()!=$entity->getOwner()&&$entity->getUser()!=$olduser) { + $this->notifMail($entity); + } + + foreach($entity->getProject()->getGroups() as $group) { if($group->getFgcanshare()) { $url=$this->generateUrl('cadoles_portal_'.$access.'_projecttask_view',["id"=>$entity->getId()]); @@ -209,7 +220,7 @@ class ProjecttaskController extends Controller $em->getRepository("CadolesPortalBundle:Projecttask")->getProjectsTasks($projects,0,10,$count,$projecttasks); // Récupérer les fichiers de la tache - $directory=$this->get('kernel')->getRootDir()."/../uploads/file/taskproject-".$id; + $directory=$this->get('kernel')->getRootDir()."/../uploads/file/projecttask-".$id; $files=[]; $fs = new Filesystem(); @@ -400,4 +411,23 @@ class ProjecttaskController extends Controller return $response; } + private function notifMail($entity) { + $appname=$this->get('session')->get('appname'); + + $url=$this->generateUrl('cadoles_core_redirect', ['route'=>'cadoles_portal_user_projecttask_view','id'=>$entity->getId()], UrlGeneratorInterface::ABSOLUTE_URL); + $urltext=$url; + $urlhtml="".$url.""; + $bodytext="Une tâche vous a été affectée dans le groupe ".$entity->getProject()->getName()."\n".$entity->getName()."\n\nVous pouvez la consulter sur\n"; + $bodyhtml=nl2br($bodytext); + + $mail_params=array( + "subject" => $appname." : Affectation Tâche dans le groupe ".$entity->getProject()->getName(), + "body_html"=>$bodyhtml.$urlhtml, + "body_text"=>$bodytext.$urltext, + ); + + $message = $this->container->get('cadoles.core.service.mail'); + $message->sendEmail("template", $mail_params, $entity->getUser()->getEmail(), $this->getParameter("noreply"), $appname); + + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projecttask.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projecttask.php index 22c25834..67a40cd2 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projecttask.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Projecttask.php @@ -89,6 +89,15 @@ class Projecttask */ private $projecttaskstatus; + + /** + * @var ArrayCollection $projectcomment + * @var Projectcomment + * + * @ORM\OneToMany(targetEntity="Cadoles\PortalBundle\Entity\Projectcomment", mappedBy="projecttask", cascade={"persist"}, orphanRemoval=true) + */ + private $projectcomments; + /** * Get id * @@ -363,4 +372,45 @@ class Projecttask { return $this->percentage; } + /** + * Constructor + */ + public function __construct() + { + $this->projectcomments = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Add projectcomment + * + * @param \Cadoles\PortalBundle\Entity\Projectcomment $projectcomment + * + * @return Projecttask + */ + public function addProjectcomment(\Cadoles\PortalBundle\Entity\Projectcomment $projectcomment) + { + $this->projectcomments[] = $projectcomment; + + return $this; + } + + /** + * Remove projectcomment + * + * @param \Cadoles\PortalBundle\Entity\Projectcomment $projectcomment + */ + public function removeProjectcomment(\Cadoles\PortalBundle\Entity\Projectcomment $projectcomment) + { + $this->projectcomments->removeElement($projectcomment); + } + + /** + * Get projectcomments + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getProjectcomments() + { + return $this->projectcomments; + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml index 43d253ec..d5a07897 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml @@ -817,6 +817,44 @@ cadoles_portal_user_projecttask_percentage: path: /user/projecttask/percentage/{id} defaults: { _controller: CadolesPortalBundle:Projecttask:percentage, access: user } + +#== PROJECT COMMENT ========================================================================================================================================== + +#-- Access config +cadoles_portal_config_projectcomment_submit: + path: /config/projectcomment/submit/{idtask} + defaults: { _controller: CadolesPortalBundle:Projectcomment:submit, access: config} + +cadoles_portal_config_projectcomment_update: + path: /config/projectcomment/update/{id} + defaults: { _controller: CadolesPortalBundle:Projectcomment:update, access: config } + +cadoles_portal_config_projectcomment_delete: + path: /config/projectcomment/delete/{id} + defaults: { _controller: CadolesPortalBundle:Projectcomment:delete, access: config } + +cadoles_portal_config_projectcomment_upload: + path: /config/projectcomment/upload + defaults: { _controller: CadolesPortalBundle:Projectcomment:upload, access: config } + +#-- Access user +cadoles_portal_user_projectcomment_submit: + path: /user/projectcomment/submit/{idtask} + defaults: { _controller: CadolesPortalBundle:Projectcomment:submit, access: user } + +cadoles_portal_user_projectcomment_update: + path: /user/projectcomment/update/{id} + defaults: { _controller: CadolesPortalBundle:Projectcomment:update, access: user } + +cadoles_portal_user_projectcomment_delete: + path: /user/projectcomment/delete/{id} + defaults: { _controller: CadolesPortalBundle:Projectcomment:delete, access: user } + +cadoles_portal_user_projectcomment_upload: + path: /user/projectcomment/upload + defaults: { _controller: CadolesPortalBundle:Projectcomment:upload, access: user } + + #== FEED ================================================================================================================================================= cadoles_portal_user_feed_limesurvey: diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogcomment/edit.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogcomment/edit.html.twig index 188cf1a3..a0dca47c 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogcomment/edit.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogcomment/edit.html.twig @@ -51,10 +51,3 @@ {{ form_end(form) }} {% endblock %} - -{% block localjavascript %} - $('#mymodal').on('hidden.bs.modal', function () { - var imgSrc = $("#blogcomment_image_img").attr('src'); - $("#blogcomment_image_img").attr('src',imgSrc); - }); -{% endblock %} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Projecttask/view.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Projecttask/view.html.twig index dfb8aa5c..7a65c2c2 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Projecttask/view.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Projecttask/view.html.twig @@ -95,8 +95,28 @@
{{ entity.description | raw }}
+ +
+ Ajouter un commentaire + + {% if not entity.projectcomments is empty %} + {% for comment in entity.projectcomments|reverse %} +
+

{{comment.name}}

+ publié par {{ comment.user.username }} le {{ comment.submit|date("d/m/Y à H:i") }} + {% if canadd or app.user==comment.user%} + + {% endif %} +
+
+ {{ comment.description | raw }} +
+ {% endfor %} + {% endif %} + +
Réalisé à
{{ entity.percentage}}% @@ -115,12 +135,12 @@