[11/06/2024] Les premières modifs + installation de quelques modules indispensables

This commit is contained in:
2024-06-11 14:57:59 +02:00
parent 5ac5653ae5
commit 77cf2c7cc6
1626 changed files with 171457 additions and 131 deletions

View File

@@ -0,0 +1,270 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint;
use OpenApi\Exception\OpenApiException;
use OpenApi\Model\Api\BaseApiModel;
use OpenApi\Model\Api\Error;
use OpenApi\OpenApi;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Translation\Translator;
use Thelia\Model\LangQuery;
use TheliaBlocks\Model\BlockGroupI18nQuery;
use TheliaBlocks\Model\BlockGroupQuery;
/**
* Class BlockGroup.
*
* @OA\Schema(
* schema="BlockGroup",
* title="BlockGroup",
* )
*/
class BlockGroup extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $id;
/**
* @var bool
* @OA\Property(
* type="boolean",
* )
*/
protected $visible;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $title;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $slug = null;
/**
* @var array
* @OA\Property(
* readOnly=true,
* type="array",
* @OA\Items(
* ref="#/components/schemas/ItemBlockGroup"
* )
* )
*/
protected $itemBlockGroups = [];
/**
* @var string
* @OA\Property(
* description="All blocks json encoded",
* type="string"
* )
*/
protected $jsonContent;
/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items()
* )
*/
protected $locales;
/**
* @param $groups
*
* @throws OpenApiException
*
* @return BlockGroup
*/
public function validate($groups, $recursively = true)
{
parent::validate($groups, $recursively);
$violations = [];
if (null !== $this->getSlug()) {
$sameSlugQuery = BlockGroupQuery::create()
->filterBySlug($this->getSlug());
if (null !== $this->getId()) {
$sameSlugQuery->filterById($this->getId(), Criteria::NOT_EQUAL);
}
if (null !== $sameSlugQuery->findOne()) {
$violations[] = $this->modelFactory->buildModel(
'SchemaViolation',
[
'key' => 'slug',
'error' => Translator::getInstance()->trans('Slug must be unique', [], OpenApi::DOMAIN_NAME),
]
);
}
}
if (!empty($violations)) {
/** @var Error $error */
$error = $this->modelFactory->buildModel(
'Error',
['title' => Translator::getInstance()->trans('Invalid data', [], OpenApi::DOMAIN_NAME)]
);
$error->setSchemaViolations($violations);
throw new OpenApiException($error);
}
return $this;
}
/**
* @return int
*/
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function isVisible(): bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
/**
* @return string
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @param string $slug
*/
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return string
*/
public function getJsonContent(): ?string
{
return $this->jsonContent;
}
public function setJsonContent(?string $jsonContent): self
{
$this->jsonContent = $jsonContent;
return $this;
}
public function getItemBlockGroups(): array
{
return $this->itemBlockGroups;
}
public function setItemBlockGroups(array $itemBlockGroups): self
{
$this->itemBlockGroups = $itemBlockGroups;
return $this;
}
public function getLocales(): array|null
{
return $this->locales;
}
public function setLocales(array $locales): self
{
$this->locales = $locales;
return $this;
}
protected function getTheliaModel($propelModelName = null)
{
return parent::getTheliaModel(\TheliaBlocks\Model\BlockGroup::class);
}
public function createFromTheliaModel($theliaModel, $locale = null): void
{
parent::createFromTheliaModel($theliaModel, $locale);
$locales = array_map(
function ($item) {
return LangQuery::create()->findOneByLocale($item['Locale'])->getLocale();
},
BlockGroupI18nQuery::create()
->filterById($this->getId())
->find()
->toArray()
);
$this->setLocales($locales);
}
}

View File

@@ -0,0 +1,228 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model\Api;
use OpenApi\Annotations as OA;
use OpenApi\Constraint;
use OpenApi\Model\Api\BaseApiModel;
use Thelia\Tools\URL;
use TheliaMain\PropelResolver;
/**
* Class ItemBlockGroup.
*
* @OA\Schema(
* schema="ItemBlockGroup",
* title="ItemBlockGroup",
* )
*/
class ItemBlockGroup extends BaseApiModel
{
/**
* @var int
* @OA\Property(
* type="integer",
* )
*/
protected $id;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $itemType;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $itemId;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $itemTitle;
/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $itemUrl;
/**
* @var int
* @OA\Property(
* type="integer",
* )
* @Constraint\NotBlank(groups={"read"})
*/
protected $blockGroupId;
/**
* @return int
*/
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getItemType(): string
{
return $this->itemType;
}
public function setItemType(string $itemType): self
{
$this->itemType = $itemType;
return $this;
}
public function getItemId(): int
{
return $this->itemId;
}
public function setItemId(int $itemId): self
{
$this->itemId = $itemId;
return $this;
}
/**
* @return int
*/
public function getBlockGroupId(): ?int
{
return $this->blockGroupId;
}
public function setBlockGroupId(int $blockGroupId): self
{
$this->blockGroupId = $blockGroupId;
return $this;
}
public function getItemTitle(): string
{
return $this->itemTitle;
}
public function setItemTitle(string $itemTitle): self
{
$this->itemTitle = $itemTitle;
return $this;
}
public function getItemUrl(): string
{
return $this->itemUrl;
}
public function setItemUrl(string $itemUrl): self
{
$this->itemUrl = $itemUrl;
return $this;
}
protected function getTheliaModel($propelModelName = null)
{
return parent::getTheliaModel(\TheliaBlocks\Model\ItemBlockGroup::class);
}
public function createFromTheliaModel($theliaModel, $locale = null)
{
parent::createFromTheliaModel($theliaModel, $locale);
if (!$this->getItemType()) {
return $this;
}
try {
$tableMapClass = PropelResolver::getTableMapByTableName($this->getItemType());
if (!$tableMapClass) {
return $this;
}
$tableMap = new $tableMapClass();
$queryClass = $tableMap->getClassName().'Query';
if (!class_exists($queryClass)) {
return $this;
}
$query = $queryClass::create();
if (null === $query) {
return $this;
}
$item = $query->findOneById($this->getItemId());
if ($item === null) {
return $this;
}
if (method_exists($item, 'getTitle')) {
$this->setItemTitle($item->getTitle());
}
switch ($this->getItemType()) {
case 'product':
$this->setItemUrl(URL::getInstance()->absoluteUrl("/admin/products/update?product_id={$this->getItemId()}"));
break;
case 'category':
$this->setItemUrl(URL::getInstance()->absoluteUrl("/admin/categories/update?category_id={$this->getItemId()}"));
break;
case 'content':
$this->setItemUrl(URL::getInstance()->absoluteUrl("/admin/content/update/{$this->getItemId()}"));
break;
case 'brand':
$this->setItemUrl(URL::getInstance()->absoluteUrl("/admin/brands/update/{$this->getItemId()}"));
break;
case 'folder':
$this->setItemUrl(URL::getInstance()->absoluteUrl("/admin/folders/update/{$this->getItemId()}"));
break;
default:
if (method_exists($item, 'getUrl')) {
$this->setItemUrl($item->getUrl());
}
break;
}
} catch (\Throwable $th) {
// throw $th;
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Connection\ConnectionInterface;
use TheliaBlocks\Model\Base\BlockGroup as BaseBlockGroup;
/**
* Skeleton subclass for representing a row from the 'block_group' table.
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
class BlockGroup extends BaseBlockGroup
{
public const SLUG_MAX_LENGTH = 45;
/**
* Code to be run before inserting to database.
*
* @param ConnectionInterface $con
*
* @return bool
*/
public function preSave(ConnectionInterface $con = null)
{
if (null === $this->getSlug()) {
$this->setSlug($this->slugify($this->getTitle()));
}
$this->setSlug($this->findUnusedSlug(substr($this->getSlug(), 0, self::SLUG_MAX_LENGTH)));
return parent::preInsert($con);
}
protected function findUnusedSlug($baseSlug, $iteration = 0)
{
$iteratedSlug = $baseSlug;
if ($iteration !== 0) {
$iterationSuffix = '_'.$iteration;
$iteratedSlug = substr($baseSlug, 0, self::SLUG_MAX_LENGTH - mb_strlen($iterationSuffix)).$iterationSuffix;
}
$alreadyExistForAnotherGroupQuery = BlockGroupQuery::create()->filterBySlug($iteratedSlug);
if (null !== $this->getId()) {
$alreadyExistForAnotherGroupQuery->filterById($this->getId(), Criteria::NOT_EQUAL);
}
if (null === $alreadyExistForAnotherGroupQuery->findOne()) {
return $iteratedSlug;
}
++$iteration;
return $this->findUnusedSlug($baseSlug, $iteration);
}
protected function slugify($text)
{
$table = [
'Š' => 'S', 'š' => 's', 'Đ' => 'Dj', 'đ' => 'dj', 'Ž' => 'Z', 'ž' => 'z', 'Č' => 'C', 'č' => 'c', 'Ć' => 'C', 'ć' => 'c',
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O',
'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss',
'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e',
'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o',
'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b',
'ÿ' => 'y', 'Ŕ' => 'R', 'ŕ' => 'r', '/' => '_', ' ' => '_',
];
// -- Remove duplicated spaces
$text = preg_replace(['/\s{2,}/', '/[\t\n]/'], '_', $text);
$text = preg_replace('~[^\pL\d]+~u', '_', $text);
// -- Returns the slug
return trim(strtolower(strtr($text, $table)), '_');
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model;
use TheliaBlocks\Model\Base\BlockGroupI18n as BaseBlockGroupI18n;
/**
* Skeleton subclass for representing a row from the 'block_group_i18n' table.
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
class BlockGroupI18n extends BaseBlockGroupI18n
{
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model;
use TheliaBlocks\Model\Base\BlockGroupI18nQuery as BaseBlockGroupI18nQuery;
/**
* Skeleton subclass for performing query and update operations on the 'block_group_i18n' table.
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
class BlockGroupI18nQuery extends BaseBlockGroupI18nQuery
{
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model;
use TheliaBlocks\Model\Base\BlockGroupQuery as BaseBlockGroupQuery;
/**
* Skeleton subclass for performing query and update operations on the 'block_group' table.
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
class BlockGroupQuery extends BaseBlockGroupQuery
{
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model;
use TheliaBlocks\Model\Base\ItemBlockGroup as BaseItemBlockGroup;
/**
* Skeleton subclass for representing a row from the 'item_block_group' table.
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
class ItemBlockGroup extends BaseItemBlockGroup
{
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TheliaBlocks\Model;
use TheliaBlocks\Model\Base\ItemBlockGroupQuery as BaseItemBlockGroupQuery;
/**
* Skeleton subclass for performing query and update operations on the 'item_block_group' table.
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*/
class ItemBlockGroupQuery extends BaseItemBlockGroupQuery
{
}