Refactoring of images and documents management
This commit is contained in:
@@ -3,18 +3,22 @@
|
|||||||
namespace Thelia\Model;
|
namespace Thelia\Model;
|
||||||
|
|
||||||
use Thelia\Core\Event\Category\CategoryEvent;
|
use Thelia\Core\Event\Category\CategoryEvent;
|
||||||
|
use Thelia\Files\FileModelParentInterface;
|
||||||
use Thelia\Model\Base\Category as BaseCategory;
|
use Thelia\Model\Base\Category as BaseCategory;
|
||||||
|
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Propel\Runtime\Connection\ConnectionInterface;
|
use Propel\Runtime\Connection\ConnectionInterface;
|
||||||
|
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||||
|
use Thelia\Model\Tools\PositionManagementTrait;
|
||||||
|
use Thelia\Model\Tools\UrlRewritingTrait;
|
||||||
|
|
||||||
class Category extends BaseCategory
|
class Category extends BaseCategory implements FileModelParentInterface
|
||||||
{
|
{
|
||||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
use ModelEventDispatcherTrait;
|
||||||
|
|
||||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
use PositionManagementTrait;
|
||||||
|
|
||||||
use \Thelia\Model\Tools\UrlRewritingTrait;
|
use UrlRewritingTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int number of child for the current category
|
* @return int number of child for the current category
|
||||||
|
|||||||
@@ -2,16 +2,22 @@
|
|||||||
|
|
||||||
namespace Thelia\Model;
|
namespace Thelia\Model;
|
||||||
|
|
||||||
|
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Routing\Router;
|
use Symfony\Component\Routing\Router;
|
||||||
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
|
use Thelia\Files\FileModelParentInterface;
|
||||||
|
use Thelia\Form\BaseForm;
|
||||||
|
use Thelia\Form\CategoryDocumentModification;
|
||||||
use Thelia\Model\Base\CategoryDocument as BaseCategoryDocument;
|
use Thelia\Model\Base\CategoryDocument as BaseCategoryDocument;
|
||||||
use Propel\Runtime\Connection\ConnectionInterface;
|
use Propel\Runtime\Connection\ConnectionInterface;
|
||||||
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
|
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
|
||||||
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
|
use Thelia\Model\Breadcrumb\CatalogBreadcrumbTrait;
|
||||||
|
use Thelia\Files\FileModelInterface;
|
||||||
use Thelia\Model\Tools\PositionManagementTrait;
|
use Thelia\Model\Tools\PositionManagementTrait;
|
||||||
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
use Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||||
|
|
||||||
class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterface
|
class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterface, FileModelInterface
|
||||||
{
|
{
|
||||||
use ModelEventDispatcherTrait;
|
use ModelEventDispatcherTrait;
|
||||||
use PositionManagementTrait;
|
use PositionManagementTrait;
|
||||||
@@ -19,6 +25,8 @@ class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterfa
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate next position relative to our parent
|
* Calculate next position relative to our parent
|
||||||
|
*
|
||||||
|
* @param CategoryDocumentQuery $query
|
||||||
*/
|
*/
|
||||||
protected function addCriteriaToPositionQuery($query)
|
protected function addCriteriaToPositionQuery($query)
|
||||||
{
|
{
|
||||||
@@ -36,11 +44,7 @@ class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Document parent id
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param int $parentId parent id
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
public function setParentId($parentId)
|
public function setParentId($parentId)
|
||||||
{
|
{
|
||||||
@@ -50,9 +54,7 @@ class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Document parent id
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @return int parent id
|
|
||||||
*/
|
*/
|
||||||
public function getParentId()
|
public function getParentId()
|
||||||
{
|
{
|
||||||
@@ -71,13 +73,68 @@ class CategoryDocument extends BaseCategoryDocument implements BreadcrumbInterfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @inheritdoc
|
||||||
* return the complete breadcrumb for a given resource.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab)
|
public function getBreadcrumb(Router $router, ContainerInterface $container, $tab, $locale)
|
||||||
{
|
{
|
||||||
return $this->getCategoryBreadcrumb($router, $container, $tab);
|
return $this->getCategoryBreadcrumb($router, $container, $tab, $locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return FileModelParentInterface the parent file model
|
||||||
|
*/
|
||||||
|
public function getParentFileModel()
|
||||||
|
{
|
||||||
|
return new Category();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the form used to change this object information
|
||||||
|
*
|
||||||
|
* @return BaseForm the form
|
||||||
|
*/
|
||||||
|
public function getUpdateFormId()
|
||||||
|
{
|
||||||
|
return 'thelia.admin.category.document.modification';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the form instance used to change this object information
|
||||||
|
*
|
||||||
|
* @param \Thelia\Core\HttpFoundation\Request $request
|
||||||
|
*
|
||||||
|
* @return BaseForm the form
|
||||||
|
*/
|
||||||
|
public function getUpdateFormInstance(Request $request)
|
||||||
|
{
|
||||||
|
return new CategoryDocumentModification($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string the path to the upload directory where files are stored, without final slash
|
||||||
|
*/
|
||||||
|
public function getUploadDir()
|
||||||
|
{
|
||||||
|
return THELIA_LOCAL_DIR . 'media'.DS.'documents'.DS.'category';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $objectId the ID of the object
|
||||||
|
*
|
||||||
|
* @return string the URL to redirect to after update from the back-office
|
||||||
|
*/
|
||||||
|
public function getRedirectionUrl($objectId)
|
||||||
|
{
|
||||||
|
return '/admin/categories/update?category_id=' . $objectId . '?current_tab=document';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Query instance for this object
|
||||||
|
*
|
||||||
|
* @return ModelCriteria
|
||||||
|
*/
|
||||||
|
public function getQueryInstance()
|
||||||
|
{
|
||||||
|
return CategoryDocumentQuery::create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user