getPath(), -1, PREG_SPLIT_NO_EMPTY); $count = count($parts); $sections = ['collections']; return $count > 0 && in_array($parts[0], $sections) && $count < 4; } protected function prepareRender(int $currentPage = 1) { $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); } parent::prepareRender($currentPage); } 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); } }