implement new breadcrumb on image and document edition in the catalog

This commit is contained in:
Manuel Raynaud
2014-06-11 10:29:52 +02:00
parent afe48b2d33
commit 476bda3d4a
11 changed files with 220 additions and 20 deletions

View File

@@ -0,0 +1,28 @@
<?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 {
/**
*
* return the complete breadcrumb for a given resource.
*
* @return array
*/
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab);
}

View File

@@ -0,0 +1,85 @@
<?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, &$locale)
{
$translator = Translator::getInstance();
$catalogUrl = $router->generate('admin.catalog', [], Router::ABSOLUTE_URL);
$breadcrumb = [
$translator->trans('Home', [], 'bo.default') => $router->generate('admin.home.view', [], Router::ABSOLUTE_URL),
$translator->trans('Catalog', [], 'bo.default') => $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']);
}
$locale = $result['LOCALE'];
return $breadcrumb;
}
public function getProductBreadcrumb(Router $router, ContainerInterface $container, $tab)
{
$product = $this->getProduct();
$locale = null;
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $product->getDefaultCategoryId(), $locale);
$product->setLocale($locale);
$request = $container->get('request');
//$breadcrumb[$product->getTitle()] = $product->getUrl().'&current_tab=images';
$breadcrumb[$product->getTitle()] = sprintf("%s?product_id=%d&current_tab=%s",
$router->generate('admin.products.update', [], Router::ABSOLUTE_URL),
$product->getId(),
$tab
);
return $breadcrumb;
}
public function getCategoryBreadcrumb(Router $router, ContainerInterface $container, $tab)
{
$locale = null;
$category = $this->getCategory();
$breadcrumb = $this->getBaseBreadcrumb($router, $container, $this->getParentId(), $locale);
$category->setLocale($locale);
$breadcrumb[$category->getTitle()] = sprintf("%s?category_id=%d&current_tab=%s",
$router->generate('admin.categories.update',[], Router::ABSOLUTE_URL),
$category->getId(),
$tab
);
return $breadcrumb;
}
}

View File

@@ -2,13 +2,20 @@
namespace Thelia\Model;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Thelia\Model\Base\CategoryDocument as BaseCategoryDocument;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
use Thelia\Model\Tools\PositionManagementTrait;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
class CategoryDocument extends BaseCategoryDocument
class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterface
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use ModelEventDispatcherTrait;
use PositionManagementTrait;
use CatalogBreadcrumbTrait;
/**
* Calculate next position relative to our parent
@@ -62,4 +69,15 @@ class CategoryDocument extends BaseCategoryDocument
return true;
}
/**
*
* return the complete breadcrumb for a given resource.
*
* @return array
*/
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
{
return $this->getCategoryBreadcrumb($router, $container, $tab);
}
}

View File

@@ -2,13 +2,20 @@
namespace Thelia\Model;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Thelia\Model\Base\CategoryImage as BaseCategoryImage;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
class CategoryImage extends BaseCategoryImage
class CategoryImage extends BaseCategoryImage implements BreadcrumbInterface
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use ModelEventDispatcherTrait;
use PositionManagementTrait;
use CatalogBreadcrumbTrait;
/**
* Calculate next position relative to our parent
@@ -62,4 +69,15 @@ class CategoryImage extends BaseCategoryImage
return true;
}
/**
*
* return the complete breadcrumb for a given resource.
*
* @return array
*/
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
{
return $this->getCategoryBreadcrumb($router, $container, $tab);
}
}

View File

@@ -2,13 +2,20 @@
namespace Thelia\Model;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Thelia\Model\Base\ProductDocument as BaseProductDocument;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
use Thelia\Model\Tools\PositionManagementTrait;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
class ProductDocument extends BaseProductDocument
class ProductDocument extends BaseProductDocument implements BreadcrumbInterface
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use ModelEventDispatcherTrait;
use PositionManagementTrait;
use CatalogBreadcrumbTrait;
/**
* Calculate next position relative to our parent
@@ -63,4 +70,14 @@ class ProductDocument extends BaseProductDocument
return true;
}
/**
*
* return the complete breadcrumb for a given resource.
*
* @return array
*/
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
{
return $this->getProductBreadcrumb($router, $container, $tab);
}
}

View File

@@ -2,13 +2,23 @@
namespace Thelia\Model;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Thelia\Core\Template\Loop\CategoryPath;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Base\ProductImage as BaseProductImage;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
use Thelia\Tools\URL;
class ProductImage extends BaseProductImage
class ProductImage extends BaseProductImage implements BreadcrumbInterface
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use ModelEventDispatcherTrait;
use PositionManagementTrait;
use CatalogBreadcrumbTrait;
/**
* Calculate next position relative to our parent
@@ -62,4 +72,15 @@ class ProductImage extends BaseProductImage
return true;
}
/**
*
* return the complete breadcrumb for a given resource.
*
* @return array
*/
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
{
return $this->getProductBreadcrumb($router, $container, $tab);
}
}