Commit 01cea9a9 authored by f00wl's avatar f00wl 🦉

fix stuff

parent 6e3a49eb
......@@ -13,6 +13,7 @@ use Doctrine\ORM\EntityRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use App\Service\FileUploader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
......@@ -50,7 +51,7 @@ class SpectacleController extends AbstractController
* @param EntityManagerInterface $manager
* @return Response
*/
public function new(Request $request, EntityManagerInterface $manager, TheaterRepository $theaterRepository): Response
public function new(Request $request, EntityManagerInterface $manager, TheaterRepository $theaterRepository, FileUploader $fileUploader): Response
{
$spectacle = new Spectacle();
......@@ -62,13 +63,11 @@ class SpectacleController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
/** @var UploadedFile $imageFile */
$imageFile = $form->get('image')->getData();
// this condition is needed because the 'image' field is not required
if ($imageFile) {
$originalFilename = pathinfo($imageFile->getClientOriginalName(), PATHINFO_FILENAME);
// resize image
$imageManager = new ImageManager(array('driver' => 'gd'));
$img = $imageManager->make($imageFile);
......@@ -77,40 +76,22 @@ class SpectacleController extends AbstractController
$constraint->upsize();
});
$img->save();
$fileImageName = $fileUploader->upload($imageFile);
$spectacle->setImage($fileImageName);
}
// this is needed to safely include the file name as part of the URL
$slugger = new AsciiSlugger();
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$imageFile->guessExtension();
// Move the file to the directory where images are stored
try {
$imageFile->move(
$this->getParameter('images_directory'),
$newFilename
);
} catch (FileException $e) {
throw new FileException($e);
}
// set image
$spectacle->setImage($newFilename);
// set Theater
$spectacle->setTheater($theater);
// set Theater
$spectacle->setTheater($theater);
// persistant data
$manager->persist($spectacle);
// persistant data
$manager->persist($spectacle);
// save to database
$manager->flush();
// save to database
$manager->flush();
return $this->redirectToRoute('spectacle_index', [
'id' => $spectacle->getId(),
]);
}
return $this->redirectToRoute('spectacle_index', [
'id' => $spectacle->getId(),
]);
}
return $this->render('spectacle/new.html.twig', [
......
......@@ -86,8 +86,9 @@ class TheaterController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
//$theaterService->geocode($theater);
/** @var UploadedFile $file */
$fileLogo = $form['logo']->getData();
/** @var UploadedFile $fileLogo */
//$fileLogo = $form['logo']->getData();
$fileLogo = $request->files->get('theater')['logo'];
if ($fileLogo) {
// resize image
$imageManager = new ImageManager(array('driver' => 'gd'));
......@@ -101,7 +102,7 @@ class TheaterController extends AbstractController
$theater->setLogo($fileLogoName);
}
/** @var UploadedFile $file */
/** @var UploadedFile $filePicture */
$filePicture = $request->files->get('theater')['picture'];
if ($filePicture) {
// resize image
......
......@@ -77,11 +77,6 @@ class Theater
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\File(
* maxSize = "5M",
* mimeTypes = {"image/*"},
* mimeTypesMessage = "Taille limite de l'image: 5Mo"
* )
*/
private $logo;
......@@ -91,6 +86,15 @@ class Theater
*/
private $website;
// /^[0-9]{1,}[.]{0,1}[0-9]{0,2}$/ /^[0-9]{1,}(\.|)[0-9]{0,2}$/g /^[1-9][0-9]*\.[0-9]{2}$/
/**
*
* @Assert\Regex( "/^[0-9]{1,}(\.|)[0-9]{0,2}$/", message =" tarif non valide")
* @ORM\Column(type="float", nullable=true)
*/
private $baseRate;
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="theater", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
......@@ -114,11 +118,6 @@ class Theater
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\File(
* maxSize = "5M",
* mimeTypes = {"image/*"},
* mimeTypesMessage = "Taille limite de l'image: 5Mo"
* )
*/
private $picture;
......@@ -236,7 +235,7 @@ class Theater
return $this->logo;
}
public function setLogo($logo): self
public function setLogo(?string $logo): self
{
if ($logo) {
$this->logo = $logo;
......@@ -257,6 +256,18 @@ class Theater
return $this;
}
public function getBaseRate(): ?float
{
return $this->baseRate;
}
public function setBaseRate(?float $baseRate): self
{
$this->baseRate = $baseRate;
return $this;
}
public function getUser(): ?User
{
return $this->user;
......
......@@ -52,7 +52,7 @@ class SpectacleType extends AbstractType
->add(
'image',
FileType::class,
['required'=>true,
['required'=>false,
'help' => 'jpg/png',
'data_class' => null]
)
......
{{ form_start(form, { 'attr': {'autocomplete': 'off'} }) }}
<div class="row">
<div class="col-sm-6">
{{ form_label(form.isBalise, 'Offre Balises') }}
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_widget(form.isBalise) }}</h6>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.duration, 'Durée (H m)') }}</h6>
{{ form_widget(form.duration, {'attr': {'class': 'hold'}}) }}
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-6">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.title, 'Titre') }}</h6>
{{ form_widget(form.title) }}
</div>
<div class="col-sm-4" id="wrapper">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.image, 'Illustration') }}</h6>
{{ form_widget(form.image, {'attr': {'class': 'hold','placeholder:': 'format : png', 'onchange':'preview_image(event)', 'required': 'true' }}) }}
<img id="output_image"/>
{{ form_help(form.image) }}
</div>
<div class="col-sm-2">
{% if spectacle.image is not null %}
<img class="img_logo img-thumbnail" src="{{ asset('uploads/images/' ~ spectacle.image) }}" width="150" alt="">
{% endif %}
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-6">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.description, 'Description') }}</h6>
{{ form_widget(form.description, {'attr': {'rows' : '10' }}) }}
</div>
<div class="col-sm-6">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.distribution, 'Distribution') }}</h6>
{{ form_widget(form.distribution, {'attr': {'rows' : '10' }}) }}
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-6">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.photoCredits, 'Crédits Photos') }}</h6>
{{ form_widget(form.photoCredits) }}
</div>
<div class="col-sm-6">
<h6 class="mt-3 font-weight-bold text-uppercase m-0">{{ form_label(form.spectacleLink, 'Lien du spectacle') }}</h6>
{{ form_widget(form.spectacleLink) }}
</div>
</div>
<div class="d-flew justify-content-around mt-3">
<button class="btn btn-light btn-sm"><i class="fas fa-save mr-2"></i>{{ button_label|default('Enregistrer les modifications') }}</button>
</div>
{{ form_end(form) }}
<script type='text/javascript'>
function preview_image(event)
{
var reader = new FileReader();
reader.onload = function()
{
var output = document.getElementById('output_image');
output.src = reader.result;
}
reader.readAsDataURL(event.target.files[0]);
}
</script>
<style>
#output_image{
padding-top: 10px;
max-width:200px;
}
</style>
......@@ -12,6 +12,6 @@
</div>
</div>
<div class="card-body p-3 ">
{{ include('spectacle/_form.html.twig') }}
{{ include('spectacle/_formNew.html.twig') }}
</div>
{% endblock %}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment