Initial commit
This commit is contained in:
42
core/lib/Thelia/Model/Breadcrumb/BrandBreadcrumbTrait.php
Normal file
42
core/lib/Thelia/Model/Breadcrumb/BrandBreadcrumbTrait.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Breadcrumb;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\BrandQuery;
|
||||
|
||||
trait BrandBreadcrumbTrait
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, /** @noinspection PhpUnusedParameterInspection */ ContainerInterface $container, $tab, $locale)
|
||||
{
|
||||
$breadcrumb = [
|
||||
Translator::getInstance()->trans('Home') => $router->generate('admin.home.view', [], Router::ABSOLUTE_URL),
|
||||
Translator::getInstance()->trans('Brand') => $router->generate('admin.brand.default', [], Router::ABSOLUTE_URL)
|
||||
];
|
||||
|
||||
if (null !== $brand = BrandQuery::create()->findPk($this->getBrandId())) {
|
||||
$breadcrumb[$brand->setLocale($locale)->getTitle()] = sprintf(
|
||||
"%s?current_tab=%s",
|
||||
$router->generate('admin.brand.update', ['brand_id' => $brand->getId()], Router::ABSOLUTE_URL),
|
||||
$tab
|
||||
);
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
31
core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php
Normal file
31
core/lib/Thelia/Model/Breadcrumb/BreadcrumbInterface.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Breadcrumb;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
|
||||
interface BreadcrumbInterface
|
||||
{
|
||||
/**
|
||||
* Create a breadcrumb from the current object, that will be displayed to the file management UI
|
||||
*
|
||||
* @param Router $router the router where to find routes
|
||||
* @param ContainerInterface $container the container
|
||||
* @param string $tab the tab to return to (probably 'image' or 'document')
|
||||
* @param string $locale the current locale
|
||||
*
|
||||
* @return array an array of (label => URL)
|
||||
*/
|
||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab, $locale);
|
||||
}
|
||||
86
core/lib/Thelia/Model/Breadcrumb/CatalogBreadcrumbTrait.php
Normal file
86
core/lib/Thelia/Model/Breadcrumb/CatalogBreadcrumbTrait.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Breadcrumb;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Template\Loop\CategoryPath;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
trait CatalogBreadcrumbTrait
|
||||
{
|
||||
public function getBaseBreadcrumb(Router $router, ContainerInterface $container, $categoryId)
|
||||
{
|
||||
$translator = Translator::getInstance();
|
||||
$catalogUrl = $router->generate('admin.catalog', [], Router::ABSOLUTE_URL);
|
||||
$breadcrumb = [
|
||||
$translator->trans('Home') => $router->generate('admin.home.view', [], Router::ABSOLUTE_URL),
|
||||
$translator->trans('Catalog') => $catalogUrl,
|
||||
];
|
||||
|
||||
$categoryPath = new CategoryPath($container);
|
||||
$categoryPath->initializeArgs([
|
||||
'category' => $categoryId,
|
||||
'visible' => '*'
|
||||
]);
|
||||
|
||||
$results = $categoryPath->buildArray();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$breadcrumb[$result['TITLE']] = sprintf("%s?category_id=%d", $catalogUrl, $result['ID']);
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getProductBreadcrumb(Router $router, ContainerInterface $container, $tab, $locale)
|
||||
{
|
||||
/** @var \Thelia\Model\Product $product */
|
||||
$product = $this->getProduct();
|
||||
|
||||
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $product->getDefaultCategoryId(), $locale);
|
||||
|
||||
$product->setLocale($locale);
|
||||
|
||||
$breadcrumb[$product->getTitle()] = sprintf(
|
||||
"%s?product_id=%d¤t_tab=%s",
|
||||
$router->generate('admin.products.update', [], Router::ABSOLUTE_URL),
|
||||
$product->getId(),
|
||||
$tab
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getCategoryBreadcrumb(Router $router, ContainerInterface $container, $tab, $locale)
|
||||
{
|
||||
/** @var \Thelia\Model\Category $category */
|
||||
$category = $this->getCategory();
|
||||
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $this->getParentId());
|
||||
|
||||
$category->setLocale($locale);
|
||||
|
||||
$breadcrumb[$category->getTitle()] = sprintf(
|
||||
"%s?category_id=%d¤t_tab=%s",
|
||||
$router->generate(
|
||||
'admin.categories.update',
|
||||
[],
|
||||
Router::ABSOLUTE_URL
|
||||
),
|
||||
$category->getId(),
|
||||
$tab
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
96
core/lib/Thelia/Model/Breadcrumb/FolderBreadcrumbTrait.php
Normal file
96
core/lib/Thelia/Model/Breadcrumb/FolderBreadcrumbTrait.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Breadcrumb;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Template\Loop\FolderPath;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
trait FolderBreadcrumbTrait
|
||||
{
|
||||
public function getBaseBreadcrumb(Router $router, ContainerInterface $container, $folderId)
|
||||
{
|
||||
$translator = Translator::getInstance();
|
||||
$foldersUrl = $router->generate('admin.folders.default', [], Router::ABSOLUTE_URL);
|
||||
$breadcrumb = [
|
||||
$translator->trans('Home') => $router->generate('admin.home.view', [], Router::ABSOLUTE_URL),
|
||||
$translator->trans('Folder') => $foldersUrl,
|
||||
];
|
||||
|
||||
$folderPath = new FolderPath($container);
|
||||
$folderPath->initializeArgs([
|
||||
'folder' => $folderId,
|
||||
'visible' => '*'
|
||||
]);
|
||||
|
||||
$results = $folderPath->buildArray();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$breadcrumb[$result['TITLE']] = sprintf(
|
||||
"%s?parent=%d",
|
||||
$router->generate(
|
||||
'admin.folders.default',
|
||||
[],
|
||||
Router::ABSOLUTE_URL
|
||||
),
|
||||
$result['ID']
|
||||
);
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getFolderBreadcrumb(Router $router, $container, $tab, $locale)
|
||||
{
|
||||
/** @var \Thelia\Model\Folder $folder */
|
||||
$folder = $this->getFolder();
|
||||
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $this->getParentId());
|
||||
|
||||
$folder->setLocale($locale);
|
||||
|
||||
$breadcrumb[$folder->getTitle()] = sprintf(
|
||||
"%s?current_tab=%s",
|
||||
$router->generate(
|
||||
'admin.folders.update',
|
||||
['folder_id' => $folder->getId()],
|
||||
Router::ABSOLUTE_URL
|
||||
),
|
||||
$tab
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function getContentBreadcrumb(Router $router, ContainerInterface $container, $tab, $locale)
|
||||
{
|
||||
/** @var \Thelia\Model\Content $content */
|
||||
$content = $this->getContent();
|
||||
|
||||
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $content->getDefaultFolderId());
|
||||
|
||||
$content->setLocale($locale);
|
||||
|
||||
$breadcrumb[$content->getTitle()] = sprintf(
|
||||
"%s?current_tab=%s",
|
||||
$router->generate(
|
||||
'admin.content.update',
|
||||
['content_id' => $content->getId()],
|
||||
Router::ABSOLUTE_URL
|
||||
),
|
||||
$tab
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user