Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/SovBundle into develop

develop
Charly 3 years ago
parent
commit
7da81829ff
7 changed files with 50 additions and 11 deletions
  1. +24
    -6
      Component/EntityComponent.php
  2. +2
    -2
      Controller/AbstractAdminController.php
  3. +2
    -2
      Controller/User/UserAdminController.php
  4. +1
    -0
      Repository/AbstractRepositoryQuery.php
  5. +1
    -0
      Resources/views/admin/setting/form.html.twig
  6. +14
    -1
      Twig/StoreTwigExtension.php
  7. +6
    -0
      Twig/TwigExtension.php

+ 24
- 6
Component/EntityComponent.php View File

@@ -3,6 +3,11 @@
namespace Lc\SovBundle\Component;

use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Doctrine\Extension\BlameableInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
use Lc\SovBundle\Doctrine\Extension\TimestampableInterface;
use Lc\SovBundle\Event\EntityComponentEvent;
use Lc\SovBundle\Model\File\FileInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -30,6 +35,7 @@ class EntityComponent
$newEntity = clone $entity;
$classMetadata = $this->entityManager->getClassMetadata(get_class($newEntity));

//Dupplication de l'image ou du fichier lier
foreach ($classMetadata->getAssociationMappings() as $associationMapping){
if(in_array(FileInterface::class, class_implements($associationMapping['targetEntity']))){
$methodGet = 'get'.ucfirst($associationMapping['fieldName']);
@@ -41,16 +47,28 @@ class EntityComponent
}
}
}
}


if($newEntity instanceof DevAliasInterface){
$newEntity->setDevAlias(null);
}

if($newEntity instanceof SeoInterface) {
$newEntity->setOldUrls(array());
}

//TODO dispatch event duplicate
/* if ($newEntity instanceof ProductFamilyInterface) {
// @TODO : à adapter
//$newEntity = $this->productFamilyUtils->processBeforePersistProductFamily($newEntity, false, true);
if($newEntity instanceof BlameableInterface) {
$newEntity->setUpdatedBy(null);
$newEntity->setCreatedBy(null);
}
*/
$this->entityManager->create($newEntity);

if($newEntity instanceof TimestampableInterface) {
$newEntity->setUpdatedAt(new \DateTime());
$newEntity->setCreatedAt(new \DateTime());
}

$this->entityManager->create($newEntity);
$this->eventDispatcher->dispatch(new EntityComponentEvent($newEntity), EntityComponentEvent::DUPLICATE_EVENT);

return $newEntity;

+ 2
- 2
Controller/AbstractAdminController.php View File

@@ -75,7 +75,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->overrideGlobalActions($responseParameters->get('global_actions'));
}
if ($responseParameters->get('entities')) {
$this->overrideEntitiesActions($responseParameters->get('entities'));
$this->overrideEntitiesActions($responseParameters->get('entities'), $responseParameters->get('pageName'));
}
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) {
$responseParameters->set('fields', $this->configureFields('index'));
@@ -95,7 +95,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $this->getEntityFqcn();
}

public function overrideEntitiesActions(?EntityCollection $entities): void
public function overrideEntitiesActions(?EntityCollection $entities, string $pageName): void
{
}


+ 2
- 2
Controller/User/UserAdminController.php View File

@@ -43,9 +43,9 @@ abstract class UserAdminController extends AbstractAdminController
return $switchAction;
}

public function overrideEntitiesActions(?EntityCollection $entities): void
public function overrideEntitiesActions(?EntityCollection $entities, string $pageName): void
{
parent::overrideEntitiesActions($entities); // TODO: Change the autogenerated stub
parent::overrideEntitiesActions($entities, $pageName); // TODO: Change the autogenerated stub
foreach ($entities as $entity) {
foreach ($entity->getActions() as $action) {
if ($action->getName() == ActionDefinition::SWITCH_USER) {

+ 1
- 0
Repository/AbstractRepositoryQuery.php View File

@@ -130,6 +130,7 @@ abstract class AbstractRepositoryQuery implements RepositoryQueryInterface
return $this;
}*/

// @TODO : créer un addOrderBy et un orderBy
public function orderBy(string $field, string $sort = 'ASC'): self
{
if (strpos($field, '.')!==false) {

+ 1
- 0
Resources/views/admin/setting/form.html.twig View File

@@ -47,5 +47,6 @@
{% do form.settings.setRendered %}

{{ form_end(form) }}

{% endblock %}
{% endembed %}

+ 14
- 1
Twig/StoreTwigExtension.php View File

@@ -3,7 +3,10 @@
namespace Lc\SovBundle\Twig;

use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Model\Site\SiteInterface;
use Lc\SovBundle\Repository\Reminder\ReminderStoreInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\Security\Core\Security;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@@ -12,19 +15,24 @@ class StoreTwigExtension extends AbstractExtension
{
protected Security $security;
protected ReminderStoreInterface $reminderStore;
protected SettingSolver $settingSolver;

public function __construct(
Security $security,
ReminderStoreInterface $reminderStore
ReminderStoreInterface $reminderStore,
SettingSolver $settingSolver
) {
$this->security = $security;
$this->reminderStore = $reminderStore;
$this->settingSolver = $settingSolver;
}

public function getFunctions()
{
return [
new TwigFunction('sov_reminders', [$this, 'getReminders']),
new TwigFunction('site_setting', [$this, 'getSiteSetting']),

];
}

@@ -33,6 +41,11 @@ class StoreTwigExtension extends AbstractExtension
return [];
}

public function getSiteSetting(SiteInterface $site, string $settingName): ?string
{
return $this->settingSolver->getSettingValue($site, $settingName);
}

public function getReminders($params)
{
// @TODO : à faire

+ 6
- 0
Twig/TwigExtension.php View File

@@ -114,9 +114,15 @@ class TwigExtension extends AbstractExtension
new TwigFilter('sov_cache', [$this, 'sovCache']),
new TwigFilter('slugify', [$this, 'slugify']),
new TwigFilter('md5', [$this, 'md5']),
new TwigFilter('rot13', [$this, 'rot13']),
];
}

public function rot13(string $string): string
{
return str_rot13($string);
}

public function isInstanceOf(EntityInterface $entity, string $interfaceName)
{
$reflection = new \ReflectionClass($entity);

Loading…
Cancel
Save