commentaire sur projecttask (ref #19)

This commit is contained in:
afornerot 2020-04-16 14:13:24 +02:00
parent dfdf3ff9f5
commit 5f66580100
5 changed files with 500 additions and 0 deletions

View File

@ -0,0 +1,191 @@
<?php
namespace Cadoles\PortalBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Filesystem\Filesystem;
use Cadoles\PortalBundle\Entity\Projectcomment;
use Cadoles\PortalBundle\Form\ProjectcommentType;
use Cadoles\CoreBundle\Entity\Usergroup;
class ProjectcommentController extends Controller
{
private $labelentity="CadolesPortalBundle:Projectcomment";
private $routeprimary="cadoles_portal_config_projectcomment";
private function entityForm(Projectcomment $entity,$access="config")
{
$route=str_replace("_config_","_".$access."_",$this->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<br><a href='$url'>".$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.'_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<br><a href='$url'>".$entity->getProjecttask()->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.'_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
]);
}
}

View File

@ -0,0 +1,190 @@
<?php
namespace Cadoles\PortalBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Projectcomment
*
* @ORM\Entity
* @ORM\Table(name="projectcomment")
* @ORM\Entity(repositoryClass="Cadoles\PortalBundle\Repository\ProjectcommentRepository")
* @ORM\HasLifecycleCallbacks
*/
class Projectcomment
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(name="submit", type="datetime")
*/
private $submit;
/**
* @ORM\ManyToOne(targetEntity="Cadoles\CoreBundle\Entity\User", inversedBy="Projectcomments")
* @ORM\JoinColumn(nullable=true)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="Cadoles\PortalBundle\Entity\Projecttask", inversedBy="projectcomments")
* @ORM\JoinColumn(nullable=false)
*/
private $projecttask;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->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;
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Cadoles\PortalBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\EntityManager;
class ProjectcommentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$user=$options['user'];
$builder
->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'
]);
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace Cadoles\PortalBundle\Repository;
use Doctrine\ORM\EntityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Cadoles\PortalBundle\Entity\Blog;
class ProjectcommentRepository extends EntityRepository
{
}

View File

@ -0,0 +1,53 @@
{% extends '@CadolesCore/base.html.twig' %}
{% block pagewrapper %}
{{ form_start(form) }}
<h1 class="page-header">
{% if mode=="update" %}
Modification Commentaire Tache
{% elseif mode=="submit" %}
Création Commentaire Tache
{% endif %}
</h1>
{{ form_widget(form.submit) }}
<a class="btn btn-default" href='{{ path('cadoles_portal_'~access~'_projecttask_view',{'id':entity.projecttask.id}) }}'>Annuler</a>
{% if mode=="update" %}
<a href={{ path('cadoles_portal_'~access~'_projectcomment_delete',{'id':entity.id}) }}
class="btn btn-danger pull-right"
data-method="delete" data-csrf="_token:{{ 'csrf' }}"
data-confirm="Êtes-vous sûr de vouloir supprimer ce commentaire ?">
Supprimer
</a>
{% endif %}
<br><br>
{% if app.session.flashbag.has('error') %}
<div class='alert alert-danger' style='margin: 5px 0px'>
<strong>Erreur</strong><br>
{% for flashMessage in app.session.flashbag.get('error') %}
{{ flashMessage }}<br>
{% endfor %}
</div>
{% endif %}
{% if app.session.flashbag.has('notice') %}
<div class='alert alert-info' style='margin: 5px 0px'>
<strong>Information</strong><br>
{% for flashMessage in app.session.flashbag.get('notice') %}
{{ flashMessage }}<br>
{% endfor %}
</div>
{% endif %}
<div class="form-group clearfix">
{{ form_row(form.name) }}
{{ form_row(form.description) }}
</div>
{{ form_end(form) }}
{% endblock %}