Browse Source

Refactoring frontend

develop
Guillaume 3 years ago
parent
commit
6dfacd908f
5 changed files with 91 additions and 5 deletions
  1. +1
    -1
      Model/File/FileModel.php
  2. +5
    -0
      Repository/AbstractRepositoryQuery.php
  3. +13
    -3
      Repository/AbstractStore.php
  4. +58
    -0
      Twig/MetaTwigExtension.php
  5. +14
    -1
      Twig/TwigExtension.php

+ 1
- 1
Model/File/FileModel.php View File





public function __toString(){ public function __toString(){
return $this->getLegend();
return ''.$this->getLegend();
} }


public function getPath(): ?string public function getPath(): ?string

+ 5
- 0
Repository/AbstractRepositoryQuery.php View File

return $this->andWhere('.'.$field.' = :'.$field)->setParameter($field, $value); return $this->andWhere('.'.$field.' = :'.$field)->setParameter($field, $value);
} }


public function filterByOldUrl(string $oldUrl): self
{
return $this->andWhere(':oldUrl IN .oldUrls')->setParameter('oldUrl', $oldUrl);
}

/* /*
* DEVALIAS * DEVALIAS
*/ */

+ 13
- 3
Repository/AbstractStore.php View File



public function getOneBySlug(string $slug, bool $isOnline = true, $query = null) public function getOneBySlug(string $slug, bool $isOnline = true, $query = null)
{ {
$query = $this->createDefaultQuery($query);
$query = $this->createQuery($query);
$query->filterBySlug($slug); $query->filterBySlug($slug);


if ($isOnline) { if ($isOnline) {


public function getOneByDevAlias(string $devAlias, $query = null) public function getOneByDevAlias(string $devAlias, $query = null)
{ {
$query = $this->createDefaultQuery($query);
$query = $this->createQuery($query);
$query->filterByDevAlias($devAlias); $query->filterByDevAlias($devAlias);
return $query->findOne(); return $query->findOne();
} }


public function getOneOnlineByDevAlias(string $devAlias, $query = null) public function getOneOnlineByDevAlias(string $devAlias, $query = null)
{ {
$query = $this->createDefaultQuery($query);
$query = $this->createQuery($query);
$query $query
->filterByDevAlias($devAlias) ->filterByDevAlias($devAlias)
->filterIsOnline(); ->filterIsOnline();
return $query->findOne(); return $query->findOne();
} }


public function getOneByOldUrl(string $oldUrl, $query = null)
{
$query = $this->createQuery($query);
$query
->filterByOldUrl($oldUrl)
->filterIsOnline();

return $query->findOne();
}

public function get($query = null) public function get($query = null)
{ {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);

+ 58
- 0
Twig/MetaTwigExtension.php View File

<?php

namespace Lc\SovBundle\Twig;

use Lc\SovBundle\Component\MetaComponent;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class MetaTwigExtension extends AbstractExtension
{
protected MetaComponent $metaComponent;

public function __construct(MetaComponent $metaComponent)
{
$this->metaComponent = $metaComponent;
}

public function getFunctions()
{
return [
new TwigFunction('sov_meta_title', [$this, 'getMetaTitle']),
new TwigFunction('sov_meta_description', [$this, 'getMetaDescription']),
new TwigFunction('sov_opengraph_title', [$this, 'getOpengraphTitle']),
new TwigFunction('sov_opengraph_description', [$this, 'getOpengraphDescription']),
new TwigFunction('sov_opengraph_image', [$this, 'getOpengraphImage']),
];
}

public function getFilters()
{
return [];
}

public function getMetaTitle($entity): string
{
return $this->metaComponent->getMetaTitle($entity);
}

public function getMetaDescription($entity): string
{
return $this->metaComponent->getMetaDescription($entity);
}

public function getOpenGraphTitle($entity): string
{
return $this->metaComponent->getOpenGraphTitle($entity);
}

public function getOpenGraphDescription($entity): string
{
return $this->metaComponent->getOpenGraphDescription($entity);
}

public function getOpenGraphImage($entity): string
{
return $this->metaComponent->getOpenGraphImage($entity);
}
}

+ 14
- 1
Twig/TwigExtension.php View File



use App\Repository\ReminderRepository; use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Component\MetaComponent;
use Lc\SovBundle\Component\StringComponent;
use Lc\SovBundle\Form\Newsletter\NewsletterType; use Lc\SovBundle\Form\Newsletter\NewsletterType;
use Lc\SovBundle\Repository\Reminder\ReminderStore; use Lc\SovBundle\Repository\Reminder\ReminderStore;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
protected $reminderStore; protected $reminderStore;
protected $security; protected $security;
protected FormFactoryInterface $formFactory; protected FormFactoryInterface $formFactory;
protected StringComponent $stringComponent;


public function __construct( public function __construct(
KernelInterface $kernel, KernelInterface $kernel,
TranslatorAdmin $translatorAdmin, TranslatorAdmin $translatorAdmin,
ReminderStore $reminderStore, ReminderStore $reminderStore,
Security $security, Security $security,
FormFactoryInterface $formFactory
FormFactoryInterface $formFactory,
StringComponent $stringComponent,
MetaComponent $metaComponent
) { ) {
$this->kernel = $kernel; $this->kernel = $kernel;
$this->parameterBag = $parameterBag; $this->parameterBag = $parameterBag;
$this->reminderStore = $reminderStore; $this->reminderStore = $reminderStore;
$this->security = $security; $this->security = $security;
$this->formFactory = $formFactory; $this->formFactory = $formFactory;
$this->stringComponent = $stringComponent;
$this->metaComponent = $metaComponent;
} }


public function getFunctions() public function getFunctions()
new TwigFunction('lc_format_price', [$this, 'formatPrice']), new TwigFunction('lc_format_price', [$this, 'formatPrice']),
new TwigFunction('die', [$this, 'die']), new TwigFunction('die', [$this, 'die']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']), new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
new TwigFunction('sov_limit_text', [$this, 'limitText']),
]; ];
} }


return $form->createView(); return $form->createView();
} }


public function limitText(string $text, int $limit)
{
return $this->stringComponent->limitText($text, $limit);
}

} }

Loading…
Cancel
Save