svg
This commit is contained in:
@ -13,23 +13,185 @@ use App\Form\IllustrationType as Form;
|
||||
class IllustrationController extends AbstractController
|
||||
{
|
||||
private $data = "illustration";
|
||||
private $route = "app_illustration";
|
||||
private $route = "app_admin_illustration";
|
||||
private $render = "Illustration/";
|
||||
private $entity = "App:Illustration";
|
||||
|
||||
public function list(Request $request)
|
||||
public function list($by,$userid)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
if($by=="admin") {
|
||||
$datas = $em->getRepository($this->entity)->findAll();
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$datas = $em->getRepository($this->entity)->findByUser($em->getRepository("App:User")->find($userid));
|
||||
|
||||
return $this->render($this->render.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"useheader" => true,
|
||||
"usesidebar" => true,
|
||||
]);
|
||||
return $this->render($this->render.'listrender.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"by" => $by,
|
||||
"userid" => $userid,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function listuser(Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$datas = $em->getRepository($this->entity)->findByUser($this->getUser());
|
||||
|
||||
return $this->render($this->render.'listrender.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"by" => "profil",
|
||||
"userid" => $this->getUser()->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit($by, $userid, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
public function view($idcat,$id,Request $request)
|
||||
// Création du formulaire
|
||||
if($by=="admin"||$by=="update") {
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$em->getRepository("App:User")->find($userid)));
|
||||
} else {
|
||||
$userid=$this->getUser()->getId();
|
||||
$form = $this->createForm(Form::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();
|
||||
$data->setSubmittime(new \DateTime());
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="admin")
|
||||
return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]);
|
||||
elseif($by=="update")
|
||||
return $this->redirectToRoute("app_user_update",["id"=>$data->getCategory()->getUser()->getId()]);
|
||||
elseif($by=="profil")
|
||||
return $this->redirectToRoute("app_user_profil");
|
||||
else
|
||||
return $this->redirectToRoute("app_illustration_view",["by"=>"user","idcat"=>$data->getCategory()->getId(),"id"=>$data->getId()]);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
'userid' => $userid,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
if($by!="admin"&&$by!="update") {
|
||||
if($this->getUser()!=$data->getCategory()->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN"))
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update","by"=>$by,"user"=>$this->getUser()));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à l'illustration
|
||||
// Retour à la liste
|
||||
if($by=="admin")
|
||||
return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]);
|
||||
elseif($by=="update")
|
||||
return $this->redirectToRoute("app_user_update",["id"=>$data->getCategory()->getUser()->getId()]);
|
||||
elseif($by=="profil")
|
||||
return $this->redirectToRoute("app_user_profil");
|
||||
elseif($by=="illustration")
|
||||
return $this->redirectToRoute("app_illustration_view",["by"=>"user","idcat"=>$data->getCategory()->getId(),"id"=>$data->getId()]);
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
'userid' => $data->getCategory()->getUser()->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
if($by!="admin"&&$by!="update") {
|
||||
if($this->getUser()!=$data->getCategory()->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN"))
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="admin")
|
||||
return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]);
|
||||
elseif($by=="update")
|
||||
return $this->redirectToRoute("app_user_update",["id"=>$data->getCategory()->getUser()->getId()]);
|
||||
elseif($by=="profil")
|
||||
return $this->redirectToRoute("app_user_profil");
|
||||
elseif($by=="illustration")
|
||||
return $this->redirectToRoute("app_home_user",["userpseudo"=>$data->getCategory()->getUser()->getSlug()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
return $this->render($this->render.'upload.html.twig');
|
||||
}
|
||||
|
||||
public function view($idcat,$id,$by,Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
@ -47,121 +209,11 @@ class IllustrationController extends AbstractController
|
||||
"next" => $datanext,
|
||||
"pathinfo" => $pathinfo,
|
||||
"usemonocolor" => true,
|
||||
"by" => $by,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function submit($by, Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data = new Entity();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
|
||||
// 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();
|
||||
$data->setSubmittime(new \DateTime());
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm($id,$form,$request,$data,"update");
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->persist($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à l'illustration
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute($this->route.'_view',array("idcat"=>$data->getCategory()->getId(),"id"=> $id));
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->render.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => false,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'by' => $by,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$by,Request $request)
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
|
||||
// Controle avant suppression
|
||||
$error=false;
|
||||
if($id<0) $error=true;
|
||||
|
||||
if($error)
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
else {
|
||||
$em->remove($data);
|
||||
$em->flush();
|
||||
|
||||
// Retour à la liste
|
||||
if($by=="console")
|
||||
return $this->redirectToRoute($this->route);
|
||||
else
|
||||
return $this->redirectToRoute("app_home");
|
||||
}
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
return $this->render($this->render.'upload.html.twig');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function getDataAllNext($idcat,$id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
Reference in New Issue
Block a user