diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/PurgeFileCommand.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/PurgeFileCommand.php index ac2572df..b5a4c92c 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/PurgeFileCommand.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/PurgeFileCommand.php @@ -323,7 +323,7 @@ class PurgeFileCommand extends Command if($result) $find=true; } - // Si pas trouvé on la cherche dans les blogs + // Si pas trouvé on la cherche dans les blogarticle if(!$find) { $result = $this->em ->getRepository("CadolesPortalBundle:Blogarticle")->createQueryBuilder('blogarticle') @@ -333,6 +333,16 @@ class PurgeFileCommand extends Command if($result) $find=true; } + // Si pas trouvé on la cherche dans les blogcommentaire + if(!$find) { + $result = $this->em + ->getRepository("CadolesPortalBundle:Blogcommentaire")->createQueryBuilder('blogcommentaire') + ->where('blogarticle.description LIKE :tofind') + ->setParameter('tofind', '%'.$tofind.'%') + ->getQuery()->getResult(); + if($result) $find=true; + } + // Si pas trouvé on supprime if(!$find) { $this->writeln($name); 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 c41e0062..9fa0bd06 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php @@ -261,6 +261,14 @@ class User implements UserInterface, \Serializable */ private $blogarticles; + /** + * @var ArrayCollection $blogcomment + * @var Blogcomment + * + * @ORM\OneToMany(targetEntity="Cadoles\PortalBundle\Entity\Blogcomment", mappedBy="user", cascade={"persist"}, orphanRemoval=true) + */ + private $blogcomments; + /** * @var ArrayCollection $icon * @var Icon @@ -1547,4 +1555,38 @@ class User implements UserInterface, \Serializable { return $this->messagesees; } + + /** + * Add blogcomment + * + * @param \Cadoles\PortalBundle\Entity\Blogcomment $blogcomment + * + * @return User + */ + public function addBlogcomment(\Cadoles\PortalBundle\Entity\Blogcomment $blogcomment) + { + $this->blogcomments[] = $blogcomment; + + return $this; + } + + /** + * Remove blogcomment + * + * @param \Cadoles\PortalBundle\Entity\Blogcomment $blogcomment + */ + public function removeBlogcomment(\Cadoles\PortalBundle\Entity\Blogcomment $blogcomment) + { + $this->blogcomments->removeElement($blogcomment); + } + + /** + * Get blogcomments + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getBlogcomments() + { + return $this->blogcomments; + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/BlogcommentController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/BlogcommentController.php new file mode 100644 index 00000000..6e57146f --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/BlogcommentController.php @@ -0,0 +1,191 @@ +routeprimary); + + if ($this->getDoctrine()->getManager()->contains($entity)) { + return $this->createForm(BlogcommentType::class, $entity, [ + "mode" => "update", + "access" => $access, + "user" => $this->getUser() + ]); + } + else { + return $this->createForm(BlogcommentType::class, $entity, [ + "mode" => "submit", + "access" => $access, + "user" => $this->getUser() + ]); + } + } + + public function submitAction(Request $request,$idarticle,$access="config") + { + $em = $this->getDoctrine()->getManager(); + $entity = new Blogcomment(); + $blogarticle=$em->getRepository("CadolesPortalBundle:Blogarticle")->find($idarticle); + if($blogarticle) $entity->setBlogarticle($blogarticle); + $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->getBlogarticle()->getBlog()->getGroups() as $group) { + if($group->getFgcanshare()) { + $url=$this->generateUrl('cadoles_portal_'.$access.'_blogarticle_view',["id"=>$entity->getBlogarticle()->getId()]); + $message="Création commentaire article
".$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.'_blogarticle_view',["id"=>$entity->getBlogarticle()->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:Blog")->getPermission($this->getUser(),$entity->getBlogarticle()->getBlog(),$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->getBlogarticle()->getBlog()->getGroups() as $group) { + if($group->getFgcanshare()) { + $url=$this->generateUrl('cadoles_portal_'.$access.'_blogarticle_view',["id"=>$entity->getBlogarticle()->getId()]); + $message="Modification commentaire article
".$entity->getBlogarticle()->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.'_blogarticle_view',["id"=>$entity->getBlogarticle()->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.'); + + $idarticle=$entity->getBlogarticle()->getId(); + + // On s'assure que l'utilisateur à la permission de supprimer + if($access=="user") { + $em->getRepository("CadolesPortalBundle:Blog")->getPermission($this->getUser(),$entity->getBlogarticle()->getBlog(),$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.'_blogarticle_view',["id"=>$idarticle])); + } + + 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:Blogarticle:image.html.twig',[ + 'useheader' => false, + 'usemenu' => false, + 'usesidebar' => false, + 'access' => $access + ]); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogarticle.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogarticle.php index 07e0c04e..58d162c5 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogarticle.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogarticle.php @@ -49,6 +49,11 @@ class Blogarticle */ private $fgdraft; + /** + * @ORM\Column(name="fgcomment", type="boolean") + */ + private $fgcomment; + /** * @var string * @@ -68,6 +73,13 @@ class Blogarticle */ private $blog; + /** + * @var ArrayCollection $blogcomment + * @var Blogcomment + * + * @ORM\OneToMany(targetEntity="Cadoles\PortalBundle\Entity\Blogcomment", mappedBy="blogarticle", cascade={"persist"}, orphanRemoval=true) + */ + private $blogcomments; @@ -248,4 +260,69 @@ class Blogarticle { return $this->blog; } + + /** + * Set fgcomment + * + * @param boolean $fgcomment + * + * @return Blogarticle + */ + public function setFgcomment($fgcomment) + { + $this->fgcomment = $fgcomment; + + return $this; + } + + /** + * Get fgcomment + * + * @return boolean + */ + public function getFgcomment() + { + return $this->fgcomment; + } + /** + * Constructor + */ + public function __construct() + { + $this->blogcomments = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Add blogcomment + * + * @param \Cadoles\PortalBundle\Entity\Blogcomment $blogcomment + * + * @return Blogarticle + */ + public function addBlogcomment(\Cadoles\PortalBundle\Entity\Blogcomment $blogcomment) + { + $this->blogcomments[] = $blogcomment; + + return $this; + } + + /** + * Remove blogcomment + * + * @param \Cadoles\PortalBundle\Entity\Blogcomment $blogcomment + */ + public function removeBlogcomment(\Cadoles\PortalBundle\Entity\Blogcomment $blogcomment) + { + $this->blogcomments->removeElement($blogcomment); + } + + /** + * Get blogcomments + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getBlogcomments() + { + return $this->blogcomments; + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogcomment.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogcomment.php new file mode 100644 index 00000000..0280a481 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Blogcomment.php @@ -0,0 +1,191 @@ +id; + } + + /** + * Set name + * + * @param string $name + * + * @return Blogcomment + */ + 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 Blogcomment + */ + 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 Blogcomment + */ + 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 Blogcomment + */ + 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 blogarticle + * + * @param \Cadoles\PortalBundle\Entity\Blogarticle $blogarticle + * + * @return Blogcomment + */ + public function setBlogarticle(\Cadoles\PortalBundle\Entity\Blogarticle $blogarticle) + { + $this->blogarticle = $blogarticle; + + return $this; + } + + /** + * Get blogarticle + * + * @return \Cadoles\PortalBundle\Entity\Blogarticle + */ + public function getBlogarticle() + { + return $this->blogarticle; + } +} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogarticleType.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogarticleType.php index 91a5cf06..1cd5a8a9 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogarticleType.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogarticleType.php @@ -39,6 +39,11 @@ class BlogarticleType extends AbstractType "disabled" => ($options["mode"]=="delete"?true:false), "config" => ["height" => "500px",'filebrowserUploadRoute' => 'cadoles_portal_'.$options["access"].'_blogarticle_upload'] ]) + + ->add("fgcomment",ChoiceType::class,[ + "label" =>"Permettre les commentaires", + "choices" => ["non"=>"0","oui"=>"1"] + ]) ->add('image',HiddenType::class, [ "label" =>"image", diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogcommentType.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogcommentType.php new file mode 100644 index 00000000..c8395d7e --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/BlogcommentType.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"].'_blogcomment_upload'] + ]); + + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'Cadoles\PortalBundle\Entity\Blogcomment', + 'mode' => 'string', + 'access' => 'string', + 'user' => 'Cadoles\CoreBundle\Entity\User' + ]); + } +} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/BlogcommentRepository.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/BlogcommentRepository.php new file mode 100644 index 00000000..f57d944c --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/BlogcommentRepository.php @@ -0,0 +1,12 @@ + {{ form_row(form.name) }} {{ form_row(form.blog) }} - {{ form_row(form.description) }} + {{ form_row(form.fgcomment) }} + {{ form_row(form.description) }}
diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogarticle/view.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogarticle/view.html.twig index cbd13d39..796d5b8e 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogarticle/view.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogarticle/view.html.twig @@ -28,7 +28,7 @@ {% block pagewrapper %} {% if access=="config" %} {% else %}
@@ -71,6 +71,25 @@
{{ entity.description | raw }}
+ + {% if entity.fgcomment %} +
+ Ajouter un commentaire + {% endif %} + {% if not entity.blogcomments is empty %} + {% for comment in entity.blogcomments|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 %}
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 new file mode 100644 index 00000000..f6ae60f6 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Blogcomment/edit.html.twig @@ -0,0 +1,60 @@ +{% extends '@CadolesCore/base.html.twig' %} + +{% block pagewrapper %} +{{ form_start(form) }} +

+ {% if mode=="update" %} + Modification Commentaire Article de Blog + {% elseif mode=="submit" %} + Création Commentaire Article de Blog + {% 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 %} + +{% block localjavascript %} + $('#mymodal').on('hidden.bs.modal', function () { + var imgSrc = $("#blogcomment_image_img").attr('src'); + $("#blogcomment_image_img").attr('src',imgSrc); + }); +{% endblock %}