[-] MO : Add ModuleController in ProductComments

// refacto ProductComments
This commit is contained in:
aFolletete
2012-05-18 10:09:02 +00:00
parent 3c8965780c
commit 155f2cbeee
10 changed files with 519 additions and 455 deletions
@@ -43,7 +43,6 @@ class ProductCommentCriterion extends ObjectModel
'fields' => array(
'id_product_comment_criterion_type' => array('type' => self::TYPE_INT),
'active' => array('type' => self::TYPE_BOOL),
// Lang fields
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
)
@@ -54,16 +53,23 @@ class ProductCommentCriterion extends ObjectModel
if (!parent::delete())
return false;
if ($this->id_product_comment_criterion_type == 2)
if (!Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category
WHERE id_product_comment_criterion='.(int)$this->id))
{
if (!Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category
WHERE id_product_comment_criterion='.(int)$this->id))
return false;
}
elseif ($this->id_product_comment_criterion_type == 3)
if (!Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product
WHERE id_product_comment_criterion='.(int)$this->id))
{
if (!Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product
WHERE id_product_comment_criterion='.(int)$this->id))
return false;
}
return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_comment_grade`
WHERE `id_product_comment_criterion` = '.(int)$this->id);
return Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_comment_grade`
WHERE `id_product_comment_criterion` = '.(int)$this->id);
}
public function update($nullValues = false)
@@ -74,11 +80,13 @@ class ProductCommentCriterion extends ObjectModel
if ($previousUpdate->id_product_comment_criterion_type != $this->id_product_comment_criterion_type)
{
if ($previousUpdate->id_product_comment_criterion_type == 2)
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category
WHERE id_product_comment_criterion='.(int)$previousUpdate->id);
return Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'product_comment_criterion_category
WHERE id_product_comment_criterion = '.(int)$previousUpdate->id);
elseif ($previousUpdate->id_product_comment_criterion_type == 3)
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product
WHERE id_product_comment_criterion='.(int)$previousUpdate->id);
return Db::getInstance()->execute('
DELETE FROM '._DB_PREFIX_.'product_comment_criterion_product
WHERE id_product_comment_criterion = '.(int)$previousUpdate->id);
}
return true;
}
@@ -92,8 +100,10 @@ class ProductCommentCriterion extends ObjectModel
{
if (!Validate::isUnsignedId($id_product))
die(Tools::displayError());
return (Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_product` (`id_product_comment_criterion`, `id_product`)
VALUES('.(int)$this->id.','.(int)$id_product.')'));
return Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_product` (`id_product_comment_criterion`, `id_product`)
VALUES('.(int)$this->id.','.(int)$id_product.')
');
}
/**
@@ -105,8 +115,10 @@ class ProductCommentCriterion extends ObjectModel
{
if (!Validate::isUnsignedId($id_category))
die(Tools::displayError());
return (Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_category` (`id_product_comment_criterion`, `id_category`)
VALUES('.(int)$this->id.','.(int)$id_category.')'));
return Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'product_comment_criterion_category` (`id_product_comment_criterion`, `id_category`)
VALUES('.(int)$this->id.','.(int)$id_category.')
');
}
/**
@@ -120,7 +132,7 @@ class ProductCommentCriterion extends ObjectModel
die(Tools::displayError());
if ($grade < 0)
$grade = 0;
else if ($grade > 10)
elseif ($grade > 10)
$grade = 10;
return (Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'product_comment_grade`
@@ -149,14 +161,25 @@ class ProductCommentCriterion extends ObjectModel
$alias = 'ps';
}
return Db::getInstance()->executeS('
SELECT pcc.`id_product_comment_criterion`, pccl.`name`
FROM `'._DB_PREFIX_.'product_comment_criterion` pcc
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion)
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.')
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`)
LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.' ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.')
WHERE pccl.`id_lang` = '.(int)($id_lang).' AND (pccp.id_product IS NOT NULL OR ps.id_product IS NOT NULL OR pcc.id_product_comment_criterion_type = 1) AND pcc.active = 1
GROUP BY pcc.id_product_comment_criterion');
SELECT pcc.`id_product_comment_criterion`, pccl.`name`
FROM `'._DB_PREFIX_.'product_comment_criterion` pcc
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl
ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion)
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp
ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.')
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc
ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`)
LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.'
ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.')
WHERE pccl.`id_lang` = '.(int)($id_lang).'
AND (
pccp.id_product IS NOT NULL
OR ps.id_product IS NOT NULL
OR pcc.id_product_comment_criterion_type = 1
)
AND pcc.active = 1
GROUP BY pcc.id_product_comment_criterion
');
}
/**
@@ -168,20 +191,21 @@ class ProductCommentCriterion extends ObjectModel
{
if (!Validate::isUnsignedId($id_lang))
die(Tools::displayError());
return (Db::getInstance()->executeS('
SELECT pcc.`id_product_comment_criterion`, pcc.id_product_comment_criterion_type, pccl.`name`, pcc.active
FROM `'._DB_PREFIX_.'product_comment_criterion` pcc
JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion)
WHERE pccl.`id_lang` = '.(int)$id_lang.($active ? ' AND active = 1' : '').($type ? ' AND id_product_comment_criterion_type = '.(int)$type : '').'
ORDER BY pccl.`name` ASC'));
return Db::getInstance()->executeS('
SELECT pcc.`id_product_comment_criterion`, pcc.id_product_comment_criterion_type, pccl.`name`, pcc.active
FROM `'._DB_PREFIX_.'product_comment_criterion` pcc
JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion)
WHERE pccl.`id_lang` = '.(int)$id_lang.($active ? ' AND active = 1' : '').($type ? ' AND id_product_comment_criterion_type = '.(int)$type : '').'
ORDER BY pccl.`name` ASC
');
}
public function getProducts()
{
$res = Db::getInstance()->executeS('
SELECT pccp.id_product, pccp.id_product_comment_criterion
FROM `'._DB_PREFIX_.'product_comment_criterion_product` pccp
WHERE pccp.id_product_comment_criterion = '.(int)$this->id);
SELECT pccp.id_product, pccp.id_product_comment_criterion
FROM `'._DB_PREFIX_.'product_comment_criterion_product` pccp
WHERE pccp.id_product_comment_criterion = '.(int)$this->id);
$products = array();
if ($res)
foreach ($res AS $row)
@@ -192,9 +216,9 @@ class ProductCommentCriterion extends ObjectModel
public function getCategories()
{
$res = Db::getInstance()->executeS('
SELECT pccc.id_category, pccc.id_product_comment_criterion
FROM `'._DB_PREFIX_.'product_comment_criterion_category` pccc
WHERE pccc.id_product_comment_criterion = '.(int)$this->id);
SELECT pccc.id_category, pccc.id_product_comment_criterion
FROM `'._DB_PREFIX_.'product_comment_criterion_category` pccc
WHERE pccc.id_product_comment_criterion = '.(int)$this->id);
$criterions = array();
if ($res)
foreach ($res AS $row)
@@ -204,19 +228,27 @@ class ProductCommentCriterion extends ObjectModel
public function deleteCategories()
{
return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_category` WHERE `id_product_comment_criterion` = '.(int)$this->id);
return Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_category`
WHERE `id_product_comment_criterion` = '.(int)$this->id);
}
public function deleteProducts()
{
return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_product` WHERE `id_product_comment_criterion` = '.(int)$this->id);
return Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_comment_criterion_product`
WHERE `id_product_comment_criterion` = '.(int)$this->id);
}
public static function getTypes()
{
// Instance of module class for translations
$module = new MailAlerts();
$module = new ProductComments();
return array(1 => $module->l('Valid for the entire catalog', 'ProductCommentCriterion'), 2 => $module->l('Restricted to some categories', 'ProductCommentCriterion'), 3 => $module->l('Restricted to some products', 'ProductCommentCriterion'));
return array(
1 => $module->l('Valid for the entire catalog', 'ProductCommentCriterion'),
2 => $module->l('Restricted to some categories', 'ProductCommentCriterion'),
3 => $module->l('Restricted to some products', 'ProductCommentCriterion')
);
}
}
}