réponse sur commentaire d'article de blog (ref #157)
This commit is contained in:
parent
c0517eb238
commit
9f6024049b
|
@ -83,6 +83,59 @@ class BlogcommentController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function replyAction(Request $request,$idarticle,$idcomment,$access="config")
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entity = new Blogcomment();
|
||||
|
||||
// Recherche de l'article associé
|
||||
$blogarticle=$em->getRepository("CadolesPortalBundle:Blogarticle")->find($idarticle);
|
||||
if($blogarticle) $entity->setBlogarticle($blogarticle);
|
||||
|
||||
// Recherche du commentaire parent
|
||||
$parent=$em->getRepository("CadolesPortalBundle:Blogcomment")->find($idcomment);
|
||||
if($parent) $entity->setParent($parent);
|
||||
|
||||
$entity->setName("Réponse");
|
||||
|
||||
$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_core_redirect', ['route'=>'cadoles_portal_user_blogarticle_view','id'=>$entity->getBlogarticle()->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$message="Création commentaire article<br><a href='$url' target='_top'>".$entity->getName()."</a>";
|
||||
$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();
|
||||
|
|
|
@ -56,7 +56,15 @@ class Blogcomment
|
|||
*/
|
||||
private $blogarticle;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Cadoles\PortalBundle\Entity\Blogcomment", inversedBy="childs")
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Cadoles\PortalBundle\Entity\Blogcomment", mappedBy="parent", cascade={"persist"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $childs;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
|
@ -188,4 +196,69 @@ class Blogcomment
|
|||
{
|
||||
return $this->blogarticle;
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->childs = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent
|
||||
*
|
||||
* @param \Cadoles\PortalBundle\Entity\Blogcomment $parent
|
||||
*
|
||||
* @return Blogcomment
|
||||
*/
|
||||
public function setParent(\Cadoles\PortalBundle\Entity\Blogcomment $parent = null)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent
|
||||
*
|
||||
* @return \Cadoles\PortalBundle\Entity\Blogcomment
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add child
|
||||
*
|
||||
* @param \Cadoles\PortalBundle\Entity\Blogcomment $child
|
||||
*
|
||||
* @return Blogcomment
|
||||
*/
|
||||
public function addChild(\Cadoles\PortalBundle\Entity\Blogcomment $child)
|
||||
{
|
||||
$this->childs[] = $child;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove child
|
||||
*
|
||||
* @param \Cadoles\PortalBundle\Entity\Blogcomment $child
|
||||
*/
|
||||
public function removeChild(\Cadoles\PortalBundle\Entity\Blogcomment $child)
|
||||
{
|
||||
$this->childs->removeElement($child);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get childs
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getChilds()
|
||||
{
|
||||
return $this->childs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -566,6 +566,10 @@ cadoles_portal_config_blogcomment_submit:
|
|||
path: /config/blogcomment/submit/{idarticle}
|
||||
defaults: { _controller: CadolesPortalBundle:Blogcomment:submit, access: config}
|
||||
|
||||
cadoles_portal_config_blogcomment_reply:
|
||||
path: /config/blogcomment/reply/{idarticle}/{idcomment}
|
||||
defaults: { _controller: CadolesPortalBundle:Blogcomment:reply, access: config}
|
||||
|
||||
cadoles_portal_config_blogcomment_update:
|
||||
path: /config/blogcomment/update/{id}
|
||||
defaults: { _controller: CadolesPortalBundle:Blogcomment:update, access: config }
|
||||
|
@ -583,6 +587,10 @@ cadoles_portal_user_blogcomment_submit:
|
|||
path: /user/blogcomment/submit/{idarticle}
|
||||
defaults: { _controller: CadolesPortalBundle:Blogcomment:submit, access: user }
|
||||
|
||||
cadoles_portal_user_blogcomment_reply:
|
||||
path: /user/blogcomment/reply/{idarticle}/{idcomment}
|
||||
defaults: { _controller: CadolesPortalBundle:Blogcomment:reply, access: user}
|
||||
|
||||
cadoles_portal_user_blogcomment_update:
|
||||
path: /user/blogcomment/update/{id}
|
||||
defaults: { _controller: CadolesPortalBundle:Blogcomment:update, access: user }
|
||||
|
|
|
@ -78,16 +78,37 @@
|
|||
{% endif %}
|
||||
{% if not entity.blogcomments is empty %}
|
||||
{% for comment in entity.blogcomments|reverse %}
|
||||
<div class="blogtitle">
|
||||
<legend><h2>{{comment.name}}</h2></legend>
|
||||
<small>publié par {{ comment.user.username }} le {{ comment.submit|date("d/m/Y à H:i") }}</small>
|
||||
{% if canadd or app.user==comment.user%}
|
||||
<a href="{{ path("cadoles_portal_"~access~"_blogcomment_update",{'id':comment.id}) }}"><i class="fa fa-file"></i></a>
|
||||
{% if comment.parent is empty %}
|
||||
<div class="blogtitle">
|
||||
<legend><h2>{{comment.name}}</h2></legend>
|
||||
<small>publié par {{ comment.user.username }} le {{ comment.submit|date("d/m/Y à H:i") }}</small>
|
||||
{% if canadd or app.user==comment.user%}
|
||||
<a href="{{ path("cadoles_portal_"~access~"_blogcomment_update",{'id':comment.id}) }}"><i class="fa fa-file"></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="blogbody">
|
||||
{{ comment.description | raw }}
|
||||
</div>
|
||||
|
||||
<div class="blogreply" style="width:80%; margin:auto">
|
||||
{% for reply in comment.childs|reverse %}
|
||||
<div class="blogtitle">
|
||||
<legend><h2 style="font-size:85%">{{reply.name}}</h2></legend>
|
||||
<small>publié par {{ reply.user.username }} le {{ reply.submit|date("d/m/Y à H:i") }}</small>
|
||||
{% if canadd or app.user==reply.user%}
|
||||
<a href="{{ path("cadoles_portal_"~access~"_blogcomment_update",{'id':reply.id}) }}"><i class="fa fa-file"></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="blogbody" style="font-size:85%">
|
||||
{{ reply.description | raw }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if entity.fgcomment %}
|
||||
<a href="{{path('cadoles_portal_'~access~'_blogcomment_reply',{"idarticle":entity.id,"idcomment":comment.id}) }}" class="btn btn-success">Répondre</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="blogbody">
|
||||
{{ comment.description | raw }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue