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

@ -71,35 +71,35 @@ app_cron_getlog:
defaults: { _controller: App\Controller\CronController:getlog }
#== Config ========================================================================================================
app_config:
app_admin_config:
path: /admin/config
defaults: { _controller: App\Controller\ConfigController:list }
app_config_render:
path: /admin/config/render/{mode}/{category}/{userid}
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}
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}
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}
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}
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}
app_user_config_delete:
path: /user/config/delete/{by}/{id}
defaults: { _controller: App\Controller\ConfigController:deleteuser }
app_config_logo:
app_user_config_logo:
path: /admin/config/logo
defaults: { _controller: App\Controller\ConfigController:logo }
@ -174,6 +174,68 @@ app_category_delete:
path: /admin/category/delete/{id}
defaults: { _controller: App\Controller\CategoryController:delete }
#== Illustration ==================================================================================================
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: /user/illustration/submit/{by}/{userid}
defaults: { _controller: App\Controller\IllustrationController:submit }
app_illustration_update:
path: /user/illustration/update/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:update }
app_illustration_delete:
path: /user/illustration/delete/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:delete }
app_illustration_crop:
path: /user/illustration/crop/{type}/{reportinput}
defaults: { _controller: App\Controller\CropController:crop02 }
app_illustration_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 }
app_webzine_submit:
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 }
app_webzine_delete:
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 }
app_webzine_crop:
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 }
#== Link ===========================================================================================================
app_link:
path: /admin/link
@ -191,64 +253,6 @@ app_link_delete:
path: /admin/link/delete/{id}
defaults: { _controller: App\Controller\LinkController:delete }
#== Illustration ==================================================================================================
app_illustration:
path: /admin/illustration/list/{by}
defaults: { _controller: App\Controller\IllustrationController:list, by: 'home' }
app_illustration_submit:
path: /admin/illustration/submit/{by}
defaults: { _controller: App\Controller\IllustrationController:submit, by: 'home' }
app_illustration_update:
path: /admin/illustration/update/{id}/{by}
defaults: { _controller: App\Controller\IllustrationController:update, by: 'home' }
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' }
app_illustration_crop:
path: /admin/illustration/crop/{type}/{reportinput}/{by}
defaults: { _controller: App\Controller\CropController:crop02, by: 'home' }
app_illustration_upload:
path: /admin/illustration/upload
defaults: { _controller: App\Controller\IllustrationController:upload }
#== Webzine ==================================================================================================
app_webzine:
path: /admin/webzine/list/{by}
defaults: { _controller: App\Controller\WebzineController:list, by: 'home' }
app_webzine_submit:
path: /admin/webzine/submit/{by}
defaults: { _controller: App\Controller\WebzineController:submit, by: 'home' }
app_webzine_update:
path: /admin/webzine/update/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:update, by: 'home' }
app_webzine_delete:
path: /admin/webzine/delete/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:delete, by: 'home' }
app_webzine_view:
path: /webzine/view/{idcat}/{id}/{by}
defaults: { _controller: App\Controller\WebzineController:view, by: 'home' }
app_webzine_crop:
path: /admin/webzine/crop/{type}/{reportinput}/{by}
defaults: { _controller: App\Controller\CropController:crop02, by: 'home' }
app_webzine_upload:
path: /admin/webzine/upload
defaults: { _controller: App\Controller\WebzineController:upload }
#== Slide =====================================================================================================
app_slide:

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,13 +97,13 @@ 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();
@ -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();
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));
public function view($idcat,$id,Request $request)
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();
// 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,13 +42,32 @@ class IllustrationType extends AbstractType
]
);
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);
@ -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;
}
}