submit illustration en masse
This commit is contained in:
@ -2,13 +2,14 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Category;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use App\Entity\Illustration as Entity;
|
||||
use App\Form\IllustrationType as Form;
|
||||
use App\Form\IllustrationCategoryType as FormCategory;
|
||||
use DateTime;
|
||||
|
||||
class IllustrationController extends AbstractController
|
||||
@ -109,7 +110,117 @@ class IllustrationController extends AbstractController
|
||||
'userid' => $userid,
|
||||
]);
|
||||
}
|
||||
|
||||
public function submits01($by, $userid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
$data->setSubmittime(new DateTime());
|
||||
|
||||
// Permission
|
||||
if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) {
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
if($by=="admin"||$by=="update") {
|
||||
$form = $this->createForm(FormCategory::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$em->getRepository("App:User")->find($userid)));
|
||||
} else {
|
||||
$form = $this->createForm(FormCategory::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$this->getUser()));
|
||||
}
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$categoryid=$data->getCategory()->getId();
|
||||
|
||||
return $this->redirectToRoute('app_illustration_submits02',["by"=>$by,"userid"=>$userid,"categoryid"=>$categoryid]);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'submits01.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => ($by=="admin" || $by=="update"),
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
'userid' => $userid,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function submits02($by, $userid, $categoryid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
$data->setSubmittime(new DateTime());
|
||||
|
||||
// Permission
|
||||
if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) {
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
if($by!="admin"&&$by!="update") {
|
||||
if($this->getUser()!=$em->getRepository(Category::class)->find($categoryid)->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN"))
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'submits02.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => ($by=="admin" || $by=="update"),
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'by' => $by,
|
||||
'userid' => $userid,
|
||||
'categoryid' => $categoryid,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function submits03($by, $userid, $categoryid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
$data->setSubmittime(new \DateTime());
|
||||
$data->setUpdatetime(new \DateTime());
|
||||
$category=$em->getRepository(Category::class)->find($categoryid);
|
||||
|
||||
// Permission
|
||||
if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) {
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
if($by!="admin"&&$by!="update") {
|
||||
if($this->getUser()!=$category->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN"))
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
$illustration=$request->request->get('illustration');
|
||||
$width=$request->request->get('width');
|
||||
$height=$request->request->get('height');
|
||||
$name=$request->request->get('name');
|
||||
|
||||
$data->setName($name);
|
||||
$data->setIllustration($illustration);
|
||||
$data->setWidth($width);
|
||||
$data->setHeight($height);
|
||||
$data->setCategory($category);
|
||||
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
return new JsonResponse();
|
||||
}
|
||||
|
||||
public function update($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
|
Reference in New Issue
Block a user