This commit is contained in:
afornerot 2024-10-30 18:00:45 +01:00
parent 8692adeae3
commit fefc4036fa
6 changed files with 394 additions and 293 deletions

View File

@ -1,262 +1,266 @@
#== Home ========================================================================================================
app_home:
path: /
defaults: { _controller: App\Controller\HomeController:home }
path: /
defaults: { _controller: App\Controller\HomeController:home }
app_feed:
path: /feed/{nb}
defaults: { _controller: App\Controller\HomeController:feed, nb: 0 }
path: /feed/{nb}
defaults: { _controller: App\Controller\HomeController:feed, nb: 0 }
app_admin:
path: /admin/home
defaults: { _controller: App\Controller\HomeController:admin }
path: /admin/home
defaults: { _controller: App\Controller\HomeController:admin }
app_ckeditor_upload:
path: /user/activity/upload
defaults: { _controller: App\Controller\HomeController:upload }
path: /user/activity/upload
defaults: { _controller: App\Controller\HomeController:upload }
#== Security ====================================================================================================
app_login:
path: /login
defaults: { _controller: App\Controller\SecurityController:login }
path: /login
defaults: { _controller: App\Controller\SecurityController:login }
app_logout:
path: /logout
defaults: { _controller: App\Controller\SecurityController:logout }
path: /logout
defaults: { _controller: App\Controller\SecurityController:logout }
app_logincas:
path: /logincas
defaults: { _controller: App\Controller\SecurityController:login }
path: /logincas
defaults: { _controller: App\Controller\SecurityController:login }
app_logoutcas:
path: /logoutcas
defaults: { _controller: App\Controller\SecurityController:logout }
path: /logoutcas
defaults: { _controller: App\Controller\SecurityController:logout }
#== Crop =========================================================================================================
app_crop01:
path: /user/crop01/{type}/{reportinput}
defaults: { _controller: App\Controller\CropController:crop01 }
path: /user/crop01/{type}/{reportinput}
defaults: { _controller: App\Controller\CropController:crop01 }
app_crop02:
path: /user/crop02/{type}/{reportinput}
defaults: { _controller: App\Controller\CropController:crop02 }
path: /user/crop02/{type}/{reportinput}
defaults: { _controller: App\Controller\CropController:crop02 }
oneup_uploader:
resource: .
type: uploader
resource: .
type: uploader
#== Cron ========================================================================================================
app_cron:
path: /admin/cron
defaults: { _controller: App\Controller\CronController:list }
path: /admin/cron
defaults: { _controller: App\Controller\CronController:list }
app_cron_ajax_list:
path: /admin/cron/ajax/list
defaults: { _controller: App\Controller\CronController:ajaxlist }
path: /admin/cron/ajax/list
defaults: { _controller: App\Controller\CronController:ajaxlist }
app_cron_update:
path: /admin/cron/update/{id}
defaults: { _controller: App\Controller\CronController:update }
path: /admin/cron/update/{id}
defaults: { _controller: App\Controller\CronController:update }
app_cron_exec:
path: /admin/cron/exec/{id}
defaults: { _controller: App\Controller\CronController:exec }
path: /admin/cron/exec/{id}
defaults: { _controller: App\Controller\CronController:exec }
app_cron_log:
path: /admin/cron/log
defaults: { _controller: App\Controller\CronController:log }
path: /admin/cron/log
defaults: { _controller: App\Controller\CronController:log }
app_cron_getlog:
path: /admin/cron/getlog/{id}
defaults: { _controller: App\Controller\CronController:getlog }
path: /admin/cron/getlog/{id}
defaults: { _controller: App\Controller\CronController:getlog }
#== Config ========================================================================================================
app_config:
path: /admin/config
defaults: { _controller: App\Controller\ConfigController:list }
app_admin_config:
path: /admin/config
defaults: { _controller: App\Controller\ConfigController:list }
app_config_render:
path: /admin/config/render/{mode}/{category}/{userid}
defaults: { _controller: App\Controller\ConfigController:listrender }
app_admin_config_render:
path: /admin/config/render/{by}/{category}/{userid}
defaults: { _controller: App\Controller\ConfigController:listrender }
app_config_user_render:
path: /user/config/render/{mode}/{category}
defaults: { _controller: App\Controller\ConfigController:listuserrender }
app_user_config_render:
path: /user/config/render/{by}/{category}
defaults: { _controller: App\Controller\ConfigController:listuserrender }
app_config_update:
path: /admin/config/update/{mode}/{id}/{userid}
defaults: { _controller: App\Controller\ConfigController:update }
app_admin_config_update:
path: /admin/config/update/{by}/{id}/{userid}
defaults: { _controller: App\Controller\ConfigController:update }
app_config_user_update:
path: /user/config/update/{mode}/{id}
defaults: { _controller: App\Controller\ConfigController:updateuser }
app_user_config_update:
path: /user/config/update/{by}/{id}
defaults: { _controller: App\Controller\ConfigController:updateuser }
app_config_delete:
path: /admin/config/delete/{mode}/{id}/{userid}
defaults: { _controller: App\Controller\ConfigController:delete }
app_admin_config_delete:
path: /admin/config/delete/{by}/{id}/{userid}
defaults: { _controller: App\Controller\ConfigController:delete }
app_config_user_delete:
path: /user/config/delete/{mode}/{id}
defaults: { _controller: App\Controller\ConfigController:deleteuser }
app_user_config_delete:
path: /user/config/delete/{by}/{id}
defaults: { _controller: App\Controller\ConfigController:deleteuser }
app_user_config_logo:
path: /admin/config/logo
defaults: { _controller: App\Controller\ConfigController:logo }
app_config_logo:
path: /admin/config/logo
defaults: { _controller: App\Controller\ConfigController:logo }
#== User ========================================================================================================
app_user:
path: /admin/user
defaults: { _controller: App\Controller\UserController:list }
path: /admin/user
defaults: { _controller: App\Controller\UserController:list }
app_user_submit:
path: /admin/user/submit
defaults: { _controller: App\Controller\UserController:submit }
path: /admin/user/submit
defaults: { _controller: App\Controller\UserController:submit }
app_user_update:
path: /admin/user/update/{id}
defaults: { _controller: App\Controller\UserController:update }
path: /admin/user/update/{id}
defaults: { _controller: App\Controller\UserController:update }
app_user_delete:
path: /admin/user/delete/{id}
defaults: { _controller: App\Controller\UserController:delete }
path: /admin/user/delete/{id}
defaults: { _controller: App\Controller\UserController:delete }
app_user_select:
path: /user/user/select
defaults: { _controller: App\Controller\UserController:select }
path: /user/user/select
defaults: { _controller: App\Controller\UserController:select }
app_user_info:
path: /user/info
defaults: { _controller: App\Controller\UserController:info }
path: /user/info
defaults: { _controller: App\Controller\UserController:info }
app_user_profil:
path: /user/profil
defaults: { _controller: App\Controller\UserController:profil }
path: /user/profil
defaults: { _controller: App\Controller\UserController:profil }
#== Group ========================================================================================================
app_group:
path: /admin/group
defaults: { _controller: App\Controller\GroupController:list }
path: /admin/group
defaults: { _controller: App\Controller\GroupController:list }
app_group_submit:
path: /admin/group/submit
defaults: { _controller: App\Controller\GroupController:submit }
path: /admin/group/submit
defaults: { _controller: App\Controller\GroupController:submit }
app_group_update:
path: /admin/group/update/{id}
defaults: { _controller: App\Controller\GroupController:update }
path: /admin/group/update/{id}
defaults: { _controller: App\Controller\GroupController:update }
app_group_delete:
path: /admin/group/delete/{id}
defaults: { _controller: App\Controller\GroupController:delete }
path: /admin/group/delete/{id}
defaults: { _controller: App\Controller\GroupController:delete }
app_group_select:
path: /user/group/select
defaults: { _controller: App\Controller\GroupController:select }
path: /user/group/select
defaults: { _controller: App\Controller\GroupController:select }
app_group_info:
path: /user/group/info
defaults: { _controller: App\Controller\GroupController:info }
path: /user/group/info
defaults: { _controller: App\Controller\GroupController:info }
#== Category ======================================================================================================
app_category:
path: /admin/category
defaults: { _controller: App\Controller\CategoryController:list }
path: /admin/category
defaults: { _controller: App\Controller\CategoryController:list }
app_category_submit:
path: /admin/category/submit
defaults: { _controller: App\Controller\CategoryController:submit }
path: /admin/category/submit
defaults: { _controller: App\Controller\CategoryController:submit }
app_category_update:
path: /admin/category/update/{id}
defaults: { _controller: App\Controller\CategoryController:update }
path: /admin/category/update/{id}
defaults: { _controller: App\Controller\CategoryController:update }
app_category_delete:
path: /admin/category/delete/{id}
defaults: { _controller: App\Controller\CategoryController:delete }
#== Link ===========================================================================================================
app_link:
path: /admin/link
defaults: { _controller: App\Controller\LinkController:list }
app_link_submit:
path: /admin/link/submit
defaults: { _controller: App\Controller\LinkController:submit }
app_link_update:
path: /admin/link/update/{id}
defaults: { _controller: App\Controller\LinkController:update }
app_link_delete:
path: /admin/link/delete/{id}
defaults: { _controller: App\Controller\LinkController:delete }
path: /admin/category/delete/{id}
defaults: { _controller: App\Controller\CategoryController:delete }
#== Illustration ==================================================================================================
app_illustration:
path: /admin/illustration/list/{by}
defaults: { _controller: App\Controller\IllustrationController:list, by: 'home' }
app_admin_illustration:
path: /admin/illustration/list/{by}/{userid}
defaults: { _controller: App\Controller\IllustrationController:list }
app_user_illustration:
path: /user/illustration/list
defaults: { _controller: App\Controller\IllustrationController:listuser }
app_illustration_submit:
path: /admin/illustration/submit/{by}
defaults: { _controller: App\Controller\IllustrationController:submit, by: 'home' }
path: /user/illustration/submit/{by}/{userid}
defaults: { _controller: App\Controller\IllustrationController:submit }
app_illustration_update:
path: /admin/illustration/update/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:update, by: 'home' }
path: /user/illustration/update/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:update }
app_illustration_delete:
path: /admin/illustration/delete/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:delete, by: 'home' }
app_illustration_view:
path: /illustration/view/{idcat}/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:view, by: 'home' }
path: /user/illustration/delete/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:delete }
app_illustration_crop:
path: /admin/illustration/crop/{type}/{reportinput}/{by}
defaults: { _controller: App\Controller\CropController:crop02, by: 'home' }
path: /user/illustration/crop/{type}/{reportinput}
defaults: { _controller: App\Controller\CropController:crop02 }
app_illustration_upload:
path: /admin/illustration/upload
defaults: { _controller: App\Controller\IllustrationController:upload }
path: /user/illustration/upload
defaults: { _controller: App\Controller\IllustrationController:upload }
app_illustration_view:
path: /illustration/view/{idcat}/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:view }
#== Webzine ==================================================================================================
app_webzine:
path: /admin/webzine/list/{by}
defaults: { _controller: App\Controller\WebzineController:list, by: 'home' }
path: /admin/webzine/list/{by}
defaults: { _controller: App\Controller\WebzineController:list }
app_webzine_submit:
path: /admin/webzine/submit/{by}
defaults: { _controller: App\Controller\WebzineController:submit, by: 'home' }
path: /admin/webzine/submit/{by}
defaults: { _controller: App\Controller\WebzineController:submit }
app_webzine_update:
path: /admin/webzine/update/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:update, by: 'home' }
path: /admin/webzine/update/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:update }
app_webzine_delete:
path: /admin/webzine/delete/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:delete, by: 'home' }
path: /admin/webzine/delete/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:delete }
app_webzine_view:
path: /webzine/view/{idcat}/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:view, by: 'home' }
path: /webzine/view/{idcat}/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:view }
app_webzine_crop:
path: /admin/webzine/crop/{type}/{reportinput}/{by}
defaults: { _controller: App\Controller\CropController:crop02, by: 'home' }
path: /admin/webzine/crop/{type}/{reportinput}/{by}
defaults: { _controller: App\Controller\CropController:crop02 }
app_webzine_upload:
path: /admin/webzine/upload
defaults: { _controller: App\Controller\WebzineController:upload }
path: /admin/webzine/upload
defaults: { _controller: App\Controller\WebzineController:upload }
#== Link ===========================================================================================================
app_link:
path: /admin/link
defaults: { _controller: App\Controller\LinkController:list }
app_link_submit:
path: /admin/link/submit
defaults: { _controller: App\Controller\LinkController:submit }
app_link_update:
path: /admin/link/update/{id}
defaults: { _controller: App\Controller\LinkController:update }
app_link_delete:
path: /admin/link/delete/{id}
defaults: { _controller: App\Controller\LinkController:delete }
#== Slide =====================================================================================================
app_slide:
path: /slide
defaults: { _controller: App\Controller\SlideController:slide }
path: /slide
defaults: { _controller: App\Controller\SlideController:slide }
#== Home USer==================================================================================================
app_home_user:
path: /{userpseudo}
defaults: { _controller: App\Controller\HomeController:user }
path: /{userpseudo}
defaults: { _controller: App\Controller\HomeController:user }

View File

@ -26,11 +26,11 @@ class ConfigController extends AbstractController
$this->data."s" => $datas,
"useheader" => true,
"usesidebar" => true,
"mode" => "config",
"by" => "admin",
]);
}
public function listrender($mode,$category,$userid)
public function listrender($by,$category,$userid)
{
$em = $this->getDoctrine()->getManager();
$user=null;
@ -41,12 +41,12 @@ class ConfigController extends AbstractController
$this->data."s" => $datas,
"useheader" => true,
"usesidebar" => true,
"mode" => $mode,
"by" => $by,
"userid" => $userid,
]);
}
public function listuserrender($mode,$category)
public function listuserrender($by,$category)
{
$em = $this->getDoctrine()->getManager();
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true,"category"=>$category,"user"=>$this->getUser()]);
@ -55,17 +55,17 @@ class ConfigController extends AbstractController
$this->data."s" => $datas,
"useheader" => true,
"usesidebar" => true,
"mode" => $mode,
"by" => $by,
]);
}
public function update($mode,$id,$userid,Request $request)
public function update($by,$id,$userid,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$user=null;
if($mode!="config") $user=$em->getRepository("App:User")->find($userid);
if($by!="admin") $user=$em->getRepository("App:User")->find($userid);
$data=$em->getRepository($this->entity)->findOneBy(["id"=>$id,"user"=>$user]);
// Création du formulaire
@ -84,7 +84,7 @@ class ConfigController extends AbstractController
$em->flush();
// Retour à la liste
if($mode!="config") {
if($by!="admin") {
return $this->redirectToRoute("app_user_update",["id"=>$userid]);
}
else {
@ -97,20 +97,20 @@ class ConfigController extends AbstractController
'useheader' => true,
'usesidebar' => true,
$this->data => $data,
'mode' => $mode,
'by' => $by,
'form' => $form->createView(),
'userid' => $userid,
]);
}
public function updateuser($mode,$id,Request $request)
public function updateuser($by,$id,Request $request)
{
// Initialisation de l'enregistrement
$em = $this->getDoctrine()->getManager();
$data=$em->getRepository($this->entity)->findOneBy(["id"=>$id,"user"=>$this->getUser()]);
// Création du formulaire
$form = $this->createForm(Form::class,$data,array("mode"=>"update","id"=>$data->getId(),"type"=>$data->getType(),"required"=>$data->getRequired()));
$form = $this->createForm(Form::class,$data,array("mode "=>"update","id"=>$data->getId(),"type"=>$data->getType(),"required"=>$data->getRequired()));
// Récupération des data du formulaire
$form->handleRequest($request);
@ -133,13 +133,13 @@ class ConfigController extends AbstractController
'useheader' => true,
'usesidebar' => false,
$this->data => $data,
'mode' => $mode,
'by' => $by,
'form' => $form->createView(),
'userid' => $this->getUser()->getId(),
]);
}
public function delete($mode,$id,$userid,Request $request)
public function delete($by,$id,$userid,Request $request)
{
// Récupération de l'enregistrement courant
$em = $this->getDoctrine()->getManager();
@ -149,7 +149,7 @@ class ConfigController extends AbstractController
$em->persist($config);
$em->flush();
// Retour à la liste
if($mode!="config") {
if($by!="admin") {
return $this->redirectToRoute("app_user_update",["id"=>$userid]);
}
else {

View File

@ -70,7 +70,7 @@ class CropController extends AbstractController
// Construction du formulaire
$submited=false;
$form = $this->createFormBuilder()
->add('submit',SubmitType::class,array("label" => "Valider","attr" => array("class" => "btn btn-success","onclick" => "reportThumb()")))
->add('submit',SubmitType::class,array("label" => "Valider","attr" => array("class" => "btn btn-success")))
->add('x',HiddenType::class)
->add('y',HiddenType::class)
->add('w',HiddenType::class)
@ -90,9 +90,15 @@ class CropController extends AbstractController
$data = $form->getData();
$thumb_image_location = "uploads/$type/thumb_".$file;
$cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location,$data["ws"],$data["hs"],$data["xs"],$data["ys"],$scale);
$submited=true;
}
return $this->render('Crop/crop03.html.twig', [
'useheader' => false,
'usesidebar' => false,
'type' => $type,
'file' => $file,
"reportinput" => $reportinput,
]);
}
return $this->render('Crop/crop02.html.twig', [
'useheader' => false,
'usesidebar' => false,
@ -184,7 +190,7 @@ class CropController extends AbstractController
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
$ok=imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
switch($imageType) {
case "image/gif":
imagegif($newImage,$thumb_image_name);
@ -199,7 +205,7 @@ class CropController extends AbstractController
imagepng($newImage,$thumb_image_name);
break;
}
chmod($thumb_image_name, 0640);
chmod($thumb_image_name, 0644);
return $thumb_image_name;
}

View File

@ -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();

View File

@ -10,6 +10,8 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
class IllustrationType extends AbstractType
{
@ -40,14 +42,33 @@ class IllustrationType extends AbstractType
]
);
$builder->add('category',
EntityType::class, [
"class" => "App:Category",
"label" => "Categorie",
"choice_label"=> "name",
]
);
if($options["by"]=="admin") {
$builder->add('category',
EntityType::class, [
"class" => "App:Category",
"label" => "Categorie",
"choice_label"=> function($category) {
return $category->getUser()->getUsername(). ' = ' . $category->getName();
},
"group_by" => function($category) {
return $category->getUser()->getUsername();
},
]
);
}
else {
$builder->add('category',
EntityType::class, [
"class" => "App:Category",
"label" => "Categorie",
"choice_label"=> "name",
'query_builder' => function (EntityRepository $er) use ($options): QueryBuilder {
return $er->createQueryBuilder('c')->where('c.user=:user')->setParameter('user',$options['user']->getId())->orderBy('c.order', 'ASC');
},
]
);
}
$builder->add('illustration',HiddenType::class);
$builder->add('width',HiddenType::class);
$builder->add('height',HiddenType::class);
@ -58,6 +79,8 @@ class IllustrationType extends AbstractType
$resolver->setDefaults(array(
'data_class' => 'App\Entity\Illustration',
'mode' => 'string',
'by' => 'string',
'user' => 'App\Entity\User'
));
}
}

View File

@ -3,6 +3,7 @@
namespace App\Repository;
use App\Entity\Illustration;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
@ -12,4 +13,19 @@ class IllustrationRepository extends ServiceEntityRepository
{
parent::__construct($registry, Illustration::class);
}
public function findByUser(User $user) {
$illustrations=[];
if($user) {
$illustrations=$this->createQueryBuilder('illustration')
->from('App\Entity\Category','category')
->andWhere('category.user = :user')
->andWhere('category.id = illustration.category')
->setParameter('user',$user)
->orderBy('illustration.submittime', 'DESC')
->getQuery()->getResult();
}
return $illustrations;
}
}