2024-04-25 15:44:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\BundleRenderers\Renderers;
|
|
|
|
|
|
|
|
use App\Classes\Bundle;
|
|
|
|
|
|
|
|
class ProductBasedListRenderer extends ListRenderer
|
|
|
|
{
|
|
|
|
/**
|
2024-04-26 16:09:33 +02:00
|
|
|
* Return a boolean value indicating if this creator in particular can
|
|
|
|
* create bundles for specified section
|
2024-04-25 15:44:29 +02:00
|
|
|
*/
|
2024-04-26 16:09:33 +02:00
|
|
|
public static function handles(Bundle $bundle): bool
|
2024-04-25 15:44:29 +02:00
|
|
|
{
|
2024-04-26 16:09:33 +02:00
|
|
|
$parts = preg_split('#/#', $bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
$count = count($parts);
|
|
|
|
$sections = ['collections'];
|
|
|
|
|
|
|
|
return $count > 0
|
|
|
|
&& in_array($parts[0], $sections)
|
|
|
|
&& $count < 4;
|
|
|
|
}
|
2024-04-25 15:44:29 +02:00
|
|
|
|
2024-04-26 16:09:33 +02:00
|
|
|
protected function prepareRender(int $currentPage = 1)
|
|
|
|
{
|
2024-04-25 15:44:29 +02:00
|
|
|
$parts = preg_split('#/#', $this->bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
$count = count($parts);
|
|
|
|
|
|
|
|
switch ($count) {
|
|
|
|
case 2:
|
|
|
|
// A brand is specified
|
|
|
|
$brandPath = sprintf('%s/%s', 'collections', $parts[1]);
|
|
|
|
$brandBundle = new Bundle($brandPath, $this->bundle->getDisk());
|
|
|
|
$articleTitle = $brandBundle->getArticleTitle();
|
|
|
|
$siteTitle = sprintf('Objets de ma collection %s', $articleTitle);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// A collection is specified
|
|
|
|
$brandPath = sprintf('%s/%s', 'collections', $parts[1]);
|
|
|
|
$brandBundle = new Bundle($brandPath, $this->bundle->getDisk());
|
|
|
|
$collectionPath = sprintf('%s/%s/%s', 'collections', $parts[1], $parts[2]);
|
|
|
|
$collectionBundle = new Bundle($collectionPath, $this->bundle->getDisk());
|
|
|
|
$articleTitle = sprintf('%s %s', $brandBundle->getArticleTitle(), $collectionBundle->getArticleTitle());
|
|
|
|
$siteTitle = sprintf('Objets de ma collection %s', $articleTitle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($articleTitle)) {
|
|
|
|
data_set($this->viewData, 'articleTitle', $articleTitle);
|
|
|
|
data_set($this->viewData, 'siteTitle', $siteTitle);
|
|
|
|
}
|
|
|
|
|
2024-04-26 16:09:33 +02:00
|
|
|
parent::prepareRender($currentPage);
|
2024-04-25 15:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function handleFilters($subBundles)
|
|
|
|
{
|
|
|
|
$url = $this->bundle->getPath();
|
|
|
|
$parts = preg_split('#/#', $url, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
|
|
|
|
// $parts[0] is section
|
|
|
|
$selectedBrand = $parts[1] ?? null;
|
|
|
|
$selectedCollection = $parts[2] ?? null;
|
|
|
|
|
|
|
|
$filters = [
|
|
|
|
'Marque' => [
|
|
|
|
'values' => [],
|
|
|
|
'selected' => $selectedBrand ?? 'Toutes',
|
|
|
|
'visible' => true,
|
|
|
|
],
|
|
|
|
'Collection' => [
|
|
|
|
'values' => [],
|
|
|
|
'selected' => $selectedCollection ?? 'Toutes',
|
|
|
|
'visible' => $selectedBrand !== null,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$prefix = sprintf('%s/', $parts[0]);
|
|
|
|
|
|
|
|
if ($selectedBrand) {
|
|
|
|
$prefix .= $selectedBrand . '/';
|
|
|
|
|
|
|
|
if ($selectedCollection) {
|
|
|
|
$prefix .= $selectedCollection . '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($subBundles as $subBundle) {
|
|
|
|
$fileParts = preg_split('#/#', $subBundle, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
|
|
|
|
// $parts[0] is section
|
|
|
|
$brand = $fileParts[1] ?? null;
|
|
|
|
$collection = $fileParts[2] ?? null;
|
|
|
|
|
|
|
|
if ($brand) {
|
|
|
|
$brandPath = sprintf('/%s/%s/', $parts[0], $brand);
|
|
|
|
$bundle = new Bundle($brandPath, $this->bundle->getDisk());
|
|
|
|
$brandName = $bundle->getArticleTitle();
|
|
|
|
|
|
|
|
$filters['Marque']['values'][$brand] = [
|
|
|
|
'title' => $brandName,
|
|
|
|
'path' => $brandPath,
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($collection && $selectedBrand !== null) {
|
|
|
|
$collectionPath = sprintf('/%s/%s/%s/', $parts[0], $brand, $collection);
|
|
|
|
$bundle = new Bundle($collectionPath, $this->bundle->getDisk());
|
|
|
|
$collectionName = $bundle->getArticleTitle();
|
|
|
|
|
|
|
|
$filters['Collection']['values'][$collection] = [
|
|
|
|
'title' => $collectionName,
|
|
|
|
'path' => $collectionPath,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($filters['Marque']['values']);
|
|
|
|
ksort($filters['Collection']['values']);
|
|
|
|
|
|
|
|
$filters['Marque']['values'] = [
|
|
|
|
'Toutes' => [
|
|
|
|
'title' => 'Toutes',
|
|
|
|
'path' => sprintf('/%s/', $parts[0]),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
+ $filters['Marque']['values'];
|
|
|
|
|
|
|
|
$filters['Collection']['values'] = [
|
|
|
|
'Toutes' => [
|
|
|
|
'title' => 'Toutes',
|
|
|
|
'path' => sprintf('/%s/%s/', $parts[0], $selectedBrand),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
+ $filters['Collection']['values'];
|
|
|
|
|
|
|
|
data_set($this->viewData['pagination'], 'filters', $filters);
|
|
|
|
}
|
|
|
|
}
|