submit illustration en masse
This commit is contained in:
parent
a6ef2a4d7b
commit
eba2e1c745
@ -196,6 +196,18 @@ app_illustration_submit:
|
||||
path: /user/illustration/submit/{by}/{userid}
|
||||
defaults: { _controller: App\Controller\IllustrationController:submit }
|
||||
|
||||
app_illustration_submits01:
|
||||
path: /user/illustration/submits01/{by}/{userid}
|
||||
defaults: { _controller: App\Controller\IllustrationController:submits01 }
|
||||
|
||||
app_illustration_submits02:
|
||||
path: /user/illustration/submits02/{by}/{userid}/{categoryid}
|
||||
defaults: { _controller: App\Controller\IllustrationController:submits02 }
|
||||
|
||||
app_illustration_submits03:
|
||||
path: /user/illustration/submits03/{by}/{userid}/{categoryid}
|
||||
defaults: { _controller: App\Controller\IllustrationController:submits03 }
|
||||
|
||||
app_illustration_update:
|
||||
path: /user/illustration/update/{id}/{by}
|
||||
defaults: { _controller: App\Controller\IllustrationController:update }
|
||||
|
@ -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
|
||||
|
65
src/Form/IllustrationCategoryType.php
Normal file
65
src/Form/IllustrationCategoryType.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
class IllustrationCategoryType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
"label" => "Valider",
|
||||
"attr" => ["class" => "btn btn-success no-print"],
|
||||
]
|
||||
);
|
||||
|
||||
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');
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'App\Entity\Illustration',
|
||||
'mode' => 'string',
|
||||
'by' => 'string',
|
||||
'user' => 'App\Entity\User'
|
||||
));
|
||||
}
|
||||
}
|
@ -55,6 +55,9 @@ class uploadListener
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
case 'image/webp':
|
||||
$source = imagecreatefromwebp($image);
|
||||
break;
|
||||
}
|
||||
|
||||
$newImage = imagecreatetruecolor( $newImageWidth, $newImageHeight );
|
||||
@ -75,6 +78,8 @@ class uploadListener
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
case 'image/webp':
|
||||
imagewebp($newImage, $image, 90);
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
|
@ -416,6 +416,10 @@
|
||||
Ajouter une Illustration
|
||||
</a>
|
||||
|
||||
<a href={{ path("app_illustration_submits01",{"by":"user","userid":app.user.id}) }} class="btn btn-link" style="font-size:30px;" title="Créer une Illustration">
|
||||
Ajouter des Illustrations en masse
|
||||
</a>
|
||||
|
||||
<a href={{ path("app_webzine_submit",{"by":"user","userid":app.user.id}) }} class="btn btn-link" style="font-size:30px;" title="Créer un Webzine">
|
||||
Ajouter un Webzine
|
||||
</a>
|
||||
|
@ -416,6 +416,11 @@
|
||||
Ajouter une Illustration
|
||||
</a>
|
||||
|
||||
|
||||
<a href={{ path("app_illustration_submits01",{"by":"user","userid":app.user.id}) }} class="btn btn-link" style="font-size:30px;" title="Créer une Illustration">
|
||||
Ajouter des Illustrations en masse
|
||||
</a>
|
||||
|
||||
<a href={{ path("app_webzine_submit",{"by":"user","userid":app.user.id}) }} class="btn btn-link" style="font-size:30px;" title="Créer un Webzine">
|
||||
Ajouter un Webzine
|
||||
</a>
|
||||
|
64
templates/Illustration/submits01.html.twig
Executable file
64
templates/Illustration/submits01.html.twig
Executable file
@ -0,0 +1,64 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
{{ form_start(form) }}
|
||||
<h1 class="page-header">
|
||||
Création ILLUSTRATIONS EN MASSE
|
||||
</h1>
|
||||
|
||||
{{ form_widget(form.submit) }}
|
||||
{% if by=="admin" %}
|
||||
<a class="btn btn-secondary" href={{ path('app_admin_illustration',{'by':by,'userid':-1}) }}>Annuler</a>
|
||||
{% elseif by=="update" %}
|
||||
<a class="btn btn-secondary" href={{ path('app_user_update',{id:userid}) }}>Annuler</a>
|
||||
{% elseif by=="profil" %}
|
||||
<a class="btn btn-secondary" href={{ path('app_user_profil') }}>Annuler</a>
|
||||
{% elseif by=="illustration" %}
|
||||
<a class="btn btn-secondary" href={{ path('app_illustration_view',{'by':"user","idcat":illustration.category.id,"id":illustration.id}) }}>Annuler</a>
|
||||
{% else %}
|
||||
<a class="btn btn-secondary" href={{ path('app_home_user',{'userpseudo':app.user.pseudo}) }}>Annuler</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="row">
|
||||
<div class="col-md-6 m-auto">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="fa fa-pencil-alt fa-fw"></i> Informations
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
{{ form_row(form.category) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block localjavascript %}
|
||||
$(document).ready(function() {
|
||||
$("#illustration_category").focus();
|
||||
});
|
||||
{% endblock %}
|
73
templates/Illustration/submits02.html.twig
Normal file
73
templates/Illustration/submits02.html.twig
Normal file
@ -0,0 +1,73 @@
|
||||
{% extends "base.html.twig" %}
|
||||
|
||||
{% block encorelinktags %}
|
||||
{{ encore_entry_link_tags('dropzone') }}
|
||||
{% endblock encorelinktags %}
|
||||
|
||||
{% block body %}
|
||||
<h1 class="page-header">
|
||||
Téléchargez vos Illustrations
|
||||
</h3>
|
||||
<a class="btn btn-secondary"href="{{path('app_home')}}">Annuler</a>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 m-auto">
|
||||
<form
|
||||
action="{{ oneup_uploader_endpoint('illustration') }}"
|
||||
class="dropzone"
|
||||
id="mydropzone"
|
||||
data-acceptedMimeTypes="image/*"
|
||||
data-resizeWidth:2500,
|
||||
style="margin-top:10px">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block encorescripttags %}
|
||||
{{ encore_entry_script_tags('dropzone') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block localjavascript %}
|
||||
function dropzoneinit( elt ) {
|
||||
}
|
||||
|
||||
function dropzonesuccess( file, response ) {
|
||||
parent.$("#illustration_illustration").val(response["file"]);
|
||||
parent.$("#illustration_width").val(response["width"]);
|
||||
parent.$("#illustration_height").val(response["height"]);
|
||||
parent.$("#illustration_name").val(response["originalname"]);
|
||||
parent.$("#illustration_illustration_img").attr("src","/{{ appAlias }}/uploads/illustration/"+response["file"]);
|
||||
|
||||
console.log('here');
|
||||
console.log(response["file"]);
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "{{ path('app_illustration_submits03',{"by":by,"userid":userid,"categoryid":categoryid}) }}",
|
||||
data: {
|
||||
illustration:response["file"],
|
||||
width:response["width"],
|
||||
height:response["height"],
|
||||
name:response["originalname"]
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
function dropzonequeuecomplete(file) {
|
||||
{% if by=="admin" %}
|
||||
url='{{ path('app_admin_illustration',{'by':by,'userid':-1}) }}';
|
||||
{% elseif by=="update" %}
|
||||
url='{{ path('app_user_update',{id:userid}) }}';
|
||||
{% elseif by=="profil" %}
|
||||
url='{{ path('app_user_profil') }}';
|
||||
{% elseif by=="illustration" %}
|
||||
url='{{ path('app_illustration_view',{'by':"user","idcat":illustration.category.id,"id":illustration.id}) }}';
|
||||
{% else %}
|
||||
url='{{ path('app_home_user',{'userpseudo':app.user.slug}) }}';
|
||||
{% endif %}
|
||||
|
||||
window.location.href=url;
|
||||
}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user