Completed template management

This commit is contained in:
franck
2013-09-16 12:52:35 +02:00
parent 657456109b
commit 696a2be8ba
13 changed files with 639 additions and 23 deletions

View File

@@ -0,0 +1,51 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Model\Template;
class TemplateAddAttributeEvent extends TemplateEvent
{
protected $attribute_id;
public function __construct(Template $template, $attribute_id)
{
parent::__construct($template);
$this->attribute_id = $attribute_id;
}
public function getAttributeId()
{
return $this->attribute_id;
}
public function setAttributeId($attribute_id)
{
$this->attribute_id = $attribute_id;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Model\Template;
class TemplateAddFeatureEvent extends TemplateEvent
{
protected $feature_id;
public function __construct(Template $template, $feature_id)
{
parent::__construct($template);
$this->feature_id = $feature_id;
}
public function getFeatureId()
{
return $this->feature_id;
}
public function setFeatureId($feature_id)
{
$this->feature_id = $feature_id;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Model\Template;
class TemplateDeleteAttributeEvent extends TemplateEvent
{
protected $attribute_id;
public function __construct(Template $template, $attribute_id)
{
parent::__construct($template);
$this->attribute_id = $attribute_id;
}
public function getAttributeId()
{
return $this->attribute_id;
}
public function setAttributeId($attribute_id)
{
$this->attribute_id = $attribute_id;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Model\Template;
class TemplateDeleteFeatureEvent extends TemplateEvent
{
protected $feature_id;
public function __construct(Template $template, $feature_id)
{
parent::__construct($template);
$this->feature_id = $feature_id;
}
public function getFeatureId()
{
return $this->feature_id;
}
public function setFeatureId($feature_id)
{
$this->feature_id = $feature_id;
return $this;
}
}

View File

@@ -343,6 +343,12 @@ final class TheliaEvents
const TEMPLATE_UPDATE = "action.updateTemplate";
const TEMPLATE_DELETE = "action.deleteTemplate";
const TEMPLATE_ADD_ATTRIBUTE = "action.templateAddAttribute";
const TEMPLATE_DELETE_ATTRIBUTE = "action.templateDeleteAttribute";
const TEMPLATE_ADD_FEATURE = "action.templateAddFeature";
const TEMPLATE_DELETE_FEATURE = "action.templateDeleteFeature";
const BEFORE_CREATETEMPLATE = "action.before_createTemplate";
const AFTER_CREATETEMPLATE = "action.after_createTemplate";

View File

@@ -64,6 +64,7 @@ class Attribute extends BaseI18nLoop
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('product'),
Argument::createIntListTypeArgument('template'),
Argument::createIntListTypeArgument('exclude_template'),
Argument::createIntListTypeArgument('exclude'),
new Argument(
'order',
@@ -115,15 +116,25 @@ class Attribute extends BaseI18nLoop
$template = $productObj->getTemplate();
}
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
if (null !== $template) {
$search->filterById(
AttributeTemplateQuery::create()->filterByTemplateId($template)->select('id')->find(),
AttributeTemplateQuery::create()->filterByTemplateId($template)->select('attribute_id')->find(),
Criteria::IN
);
}
$exclude_template = $this->getExcludeTemplate();
// If we have to filter by template, find all attributes assigned to this template, and filter by found IDs
if (null !== $exclude_template) {
// Exclure tous les attribut qui sont attachés aux templates indiqués
$search->filterById(
AttributeTemplateQuery::create()->filterByTemplateId($exclude_template)->select('attribute_id')->find(),
Criteria::NOT_IN
);
}
$orders = $this->getOrder();
foreach ($orders as $order) {

View File

@@ -38,6 +38,7 @@ use Thelia\Model\Map\ProductCategoryTableMap;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
use Thelia\Model\FeatureTemplateQuery;
/**
*
@@ -60,7 +61,8 @@ class Feature extends BaseI18nLoop
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('product'),
Argument::createIntListTypeArgument('category'),
Argument::createIntListTypeArgument('template'),
Argument::createIntListTypeArgument('exclude_template'),
Argument::createBooleanOrBothTypeArgument('visible', 1),
Argument::createIntListTypeArgument('exclude'),
new Argument(
@@ -102,22 +104,33 @@ class Feature extends BaseI18nLoop
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
$product = $this->getProduct();
$category = $this->getCategory();
$template = $this->getTemplate();
if (null !== $product) {
$productCategories = ProductCategoryQuery::create()->select(array(ProductCategoryTableMap::CATEGORY_ID))->filterByProductId($product, Criteria::IN)->find()->getData();
// Find the template assigned to the product.
$productObj = ProductQuery::create()->findPk($product);
if (null === $category) {
$category = $productCategories;
} else {
$category = array_merge($category, $productCategories);
}
// Ignore if the product cannot be found.
if ($productObj !== null)
$template = $productObj->getTemplate();
}
// If we have to filter by template, find all features assigned to this template, and filter by found IDs
if (null !== $template) {
$search->filterById(
FeatureTemplateQuery::create()->filterByTemplateId($template)->select('feature_id')->find(),
Criteria::IN
);
}
if (null !== $category) {
$search->filterByCategory(
CategoryQuery::create()->filterById($category)->find(),
Criteria::IN
$exclude_template = $this->getExcludeTemplate();
// If we have to filter by template, find all features assigned to this template, and filter by found IDs
if (null !== $exclude_template) {
// Exclure tous les attribut qui sont attachés aux templates indiqués
$search->filterById(
FeatureTemplateQuery::create()->filterByTemplateId($exclude_template)->select('feature_id')->find(),
Criteria::NOT_IN
);
}