Skip to content

Commit

Permalink
#36 : correction de bug + affichage d'images sur l'écran d'accueil
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste-its committed Mar 1, 2021
1 parent 534eaf5 commit d9e28d2
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 86 deletions.
6 changes: 4 additions & 2 deletions config/packages/vich_uploader.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ vich_uploader:
db_driver: orm

mappings:
home-text_image:
uri_prefix: /img/homeTexts
text_image:
delete_on_remove: true
delete_on_update: true
uri_prefix: /assets/images/homeTexts
upload_destination: '%kernel.project_dir%/public/assets/images/homeTexts'
namer: Vich\UploaderBundle\Naming\UniqidNamer
7 changes: 7 additions & 0 deletions public/assets/css/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ h1, h2, h3, h4, h5 {
padding: 5px;
border-radius:20%;
cursor:pointer;
}

.home-image {
width: 25%;
height: auto;
object-fit: cover;
margin-right: 1em;
}
30 changes: 17 additions & 13 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\Customer;
use App\Entity\HalfDayAdjustment;
use App\Entity\HomeTexts;
use App\Entity\Options;
use App\Form\HalfDayAdjustmentType;
use App\Repository\HalfDayAdjustmentRepository;
Expand Down Expand Up @@ -281,18 +282,23 @@ public function text(Request $request)
]
);

$formtext = $this->createForm(TextHomeType::class, $texts[0]);
$formtext2 = $this->createForm(TextHomeType::class, $texts[1]);
$formtext3 = $this->createForm(TextHomeType::class, $texts[2]);
$formtext->handleRequest($request);
$homeTexts = new HomeTexts($texts[0], $texts[1], $texts[2]);
$formText = $this->createForm(TextHomeType::class, $homeTexts);
$formText->handleRequest($request);
if ($formText->isSubmitted() && $formText->isValid()) {
foreach ($homeTexts->getData() as $k => $data) {
if ($data['file']) {
$texts[$k]->setPictureFile($data['file']);
}

if ($formtext->isSubmitted() && $formtext->isValid()) {
$texts[0]->setContent($texts[0]->getContent() . " ");
$texts[1]->setContent($texts[1]->getContent() . " ");
$texts[2]->setContent($texts[2]->getContent() . " ");
$this->om->persist($texts[1]);
$this->om->flush();
if ($texts[$k]->getContent() === $data['text']) {
$texts[$k]->setContent($data['text'] . "&nbsp");
} else {
$texts[$k]->setContent($data['text']);
}
}

$this->om->flush();
$this->addFlash(
'option',
'Texte d\'accueil modifié avec succès'
Expand Down Expand Up @@ -345,9 +351,7 @@ public function text(Request $request)
'text1' => $texts[0],
'text2' => $texts[1],
'text3' => $texts[2],
'form1' => $formtext->createView(),
'form2' => $formtext2->createView(),
'form3' => $formtext3->createView(),
'form' => $formText->createView(),
'formplace' => $formplace->createView(),
'formhalfday' => $formhalfday->createView(),
'formmonth' => $formmonth->createView(),
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function index(
//!!!!!!!!!!!!!!!!!!!! récupérer le texte d'acceuil !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$options = $this->options->findBy(
[
'label' => 'Text'
'label' => 'Text',
'active' => true
]
);

Expand Down
232 changes: 232 additions & 0 deletions src/Entity/HomeTexts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<?php


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;

class HomeTexts
{

/**
* @Assert\NotNull()
*/
private $firstText;

private $firstActive;

/**
* @var File|null
* @Assert\File(mimeTypes={"image/png", "image/jpeg"})
*/
private $firstPictureFile;

/**
* @Assert\NotNull()
*/
private $secondText;

private $secondActive;

/**
* @var File|null
* @Assert\File(mimeTypes={"image/png", "image/jpeg"})
*/
private $secondPictureFile;

/**
* @Assert\NotNull()
*/
private $thirdText;

private $thirdActive;

/**
* @var File|null
* @Assert\File(mimeTypes={"image/png", "image/jpeg"})
*/
private $thirdPictureFile;

public function __construct(Options $firstHomeText, Options $secondHomeText, Options $thirdHomeText)
{
$this->firstText = $firstHomeText->getContent();
$this->firstActive = $firstHomeText->getActive();
$this->secondText = $secondHomeText->getContent();
$this->secondActive = $secondHomeText->getActive();
$this->thirdText = $thirdHomeText->getContent();
$this->thirdActive = $thirdHomeText->getActive();
}

public function getData(): ?array {
return [
['text' => $this->firstText, 'file' => $this->firstPictureFile],
['text' => $this->secondText, 'file' => $this->secondPictureFile],
['text' => $this->thirdText, 'file' => $this->thirdPictureFile],
];
}

/**
* @return string|null
*/
public function getFirstText(): ?string
{
return $this->firstText;
}

/**
* @param string|null $firstText
* @return HomeTexts
*/
public function setFirstText(?string $firstText): self
{
$this->firstText = $firstText;
return $this;
}

/**
* @return bool|null
*/
public function getFirstActive(): ?bool
{
return $this->firstActive;
}

/**
* @param bool|null $firstActive
* @return HomeTexts
*/
public function setFirstActive(?bool $firstActive): HomeTexts
{
$this->firstActive = $firstActive;
return $this;
}

/**
* @return File|null
*/
public function getFirstPictureFile(): ?File
{
return $this->firstPictureFile;
}

/**
* @param File|null $firstPictureFile
* @return HomeTexts
*/
public function setFirstPictureFile(?File $firstPictureFile): self
{
$this->firstPictureFile = $firstPictureFile;
return $this;
}

/**
* @return string|null
*/
public function getSecondText(): ?string
{
return $this->secondText;
}

/**
* @param string|null $secondText
* @return HomeTexts
*/
public function setSecondText(?string $secondText): self
{
$this->secondText = $secondText;
return $this;
}

/**
* @return bool|null
*/
public function getSecondActive(): ?bool
{
return $this->secondActive;
}

/**
* @param bool|null $secondActive
* @return HomeTexts
*/
public function setSecondActive(?bool $secondActive): HomeTexts
{
$this->secondActive = $secondActive;
return $this;
}

/**
* @return File|null
*/
public function getSecondPictureFile(): ?File
{
return $this->secondPictureFile;
}

/**
* @param File|null $secondPictureFile
* @return HomeTexts
*/
public function setSecondPictureFile(?File $secondPictureFile): self
{
$this->secondPictureFile = $secondPictureFile;
return $this;
}

/**
* @return string|null
*/
public function getThirdText(): ?string
{
return $this->thirdText;
}

/**
* @param string|null $thirdText
* @return HomeTexts
*/
public function setThirdText(?string $thirdText): self
{
$this->thirdText = $thirdText;
return $this;
}

/**
* @return bool|null
*/
public function getThirdActive(): ?bool
{
return $this->thirdActive;
}

/**
* @param bool|null $thirdActive
* @return HomeTexts
*/
public function setThirdActive(?bool $thirdActive): HomeTexts
{
$this->thirdActive = $thirdActive;
return $this;
}

/**
* @return File|null
*/
public function getThirdPictureFile(): ?File
{
return $this->thirdPictureFile;
}

/**
* @param File|null $thirdPictureFile
* @return HomeTexts
*/
public function setThirdPictureFile(?File $thirdPictureFile): self
{
$this->thirdPictureFile = $thirdPictureFile;
return $this;
}

}
30 changes: 26 additions & 4 deletions src/Form/TextHomeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Form;

use App\Entity\HomeTexts;
use App\Entity\Options;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -14,17 +16,37 @@ class TextHomeType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('content', CKEditorType::class)
->add('pictureFile', FileType::class, [
'label' => false
->add('firstText', CKEditorType::class)
->add('firstActive', CheckboxType::class, [
'label' => 'Activer le premier text'
])
->add('firstPictureFile', FileType::class, [
'required' => false,
'label' => false,
])
->add('secondText', CKEditorType::class)
->add('secondActive', CheckboxType::class, [
'label' => 'Activer le deuxième text'
])
->add('secondPictureFile', FileType::class, [
'required' => false,
'label' => false,
])
->add('thirdText', CKEditorType::class)
->add('thirdActive', CheckboxType::class, [
'label' => 'Activer le troisième text'
])
->add('thirdPictureFile', FileType::class, [
'required' => false,
'label' => false,
])
;
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Options::class,
'data_class' => HomeTexts::class,
]);
}
}
Loading

0 comments on commit d9e28d2

Please sign in to comment.