update
This commit is contained in:
@@ -27,16 +27,17 @@
|
||||
namespace PrestaShop\Module\ProductComment\Addons;
|
||||
|
||||
use Doctrine\Common\Cache\FilesystemCache;
|
||||
use DOMDocument;
|
||||
use DOMNode;
|
||||
use DOMXPath;
|
||||
use GuzzleHttp\Message\Request;
|
||||
use GuzzleHttp\Subscriber\Cache\CacheStorage;
|
||||
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;
|
||||
use PrestaShop\CircuitBreaker\AdvancedCircuitBreakerFactory;
|
||||
use PrestaShop\CircuitBreaker\Contract\FactoryInterface;
|
||||
use PrestaShop\CircuitBreaker\FactorySettings;
|
||||
use PrestaShop\CircuitBreaker\Storage\DoctrineCache;
|
||||
use Symfony\Component\CssSelector\CssSelectorConverter;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use DOMNode;
|
||||
|
||||
/**
|
||||
* Class CategoryFetcher helps you to fetch an Addon category data. It calls the Addons
|
||||
@@ -69,13 +70,13 @@ class CategoryFetcher
|
||||
/** @var array */
|
||||
private $defaultData;
|
||||
|
||||
/** @var AdvancedCircuitBreakerFactory */
|
||||
/** @var FactoryInterface */
|
||||
private $factory;
|
||||
|
||||
/** @var FactorySettings */
|
||||
/** @var array */
|
||||
private $apiSettings;
|
||||
|
||||
/** @var FactorySettings */
|
||||
/** @var array */
|
||||
private $platformSettings;
|
||||
|
||||
/**
|
||||
@@ -257,7 +258,7 @@ class CategoryFetcher
|
||||
|
||||
$parameters['utm_source'] = 'back-office';
|
||||
$parameters['utm_medium'] = 'modules';
|
||||
$parameters['utm_campaign'] = 'back-office-' . Tools::strtoupper($isoCode);
|
||||
$parameters['utm_campaign'] = 'back-office-' . strtoupper($isoCode);
|
||||
|
||||
//Clean link used to fetch description (no need for tracking then)
|
||||
$category['clean_link'] = self::ADDONS_BASE_URL . $parsedUrl['path'];
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
namespace PrestaShop\Module\ProductComment\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Language;
|
||||
use Validate;
|
||||
|
||||
/**
|
||||
* @ORM\Table()
|
||||
@@ -34,6 +36,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
*/
|
||||
class ProductCommentCriterion
|
||||
{
|
||||
const NAME_MAX_LENGTH = 64;
|
||||
const ENTIRE_CATALOG_TYPE = 1;
|
||||
const CATEGORIES_TYPE = 2;
|
||||
const PRODUCTS_TYPE = 3;
|
||||
@@ -61,6 +64,95 @@ class ProductCommentCriterion
|
||||
*/
|
||||
private $active = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* Need to be implemented as ORM\OneToMany in the future
|
||||
*/
|
||||
private $names;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* Need to be implemented as ORM\OneToMany in the future
|
||||
*/
|
||||
private $categories;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* Need to be implemented as ORM\OneToMany in the future
|
||||
*/
|
||||
private $products;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$langIsoIds = Language::getIsoIds();
|
||||
foreach ($langIsoIds as $langIsoId) {
|
||||
$this->names[$langIsoId['id_lang']] = $langIsoId['iso_code'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getNames()
|
||||
{
|
||||
return $this->names;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $langNames
|
||||
*
|
||||
* @return ProductCommentCriterion
|
||||
*/
|
||||
public function setNames($langNames)
|
||||
{
|
||||
$this->names = $langNames;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $selectedCategories
|
||||
*
|
||||
* @return ProductCommentCriterion
|
||||
*/
|
||||
public function setCategories($selectedCategories)
|
||||
{
|
||||
$this->categories = $selectedCategories;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProducts()
|
||||
{
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $selectedProducts
|
||||
*
|
||||
* @return ProductCommentCriterion
|
||||
*/
|
||||
public function setProducts($selectedProducts)
|
||||
{
|
||||
$this->products = $selectedProducts;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -108,4 +200,18 @@ class ProductCommentCriterion
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
foreach ($this->names as $value) {
|
||||
if (!Validate::isGenericName($value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,28 @@
|
||||
|
||||
namespace PrestaShop\Module\ProductComment\Repository;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use PrestaShop\Module\ProductComment\Entity\ProductCommentCriterion;
|
||||
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
|
||||
|
||||
class ProductCommentCriterionRepository
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ProductCommentCriterion>
|
||||
*
|
||||
* @method ProductCommentCriterion|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ProductCommentCriterion|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ProductCommentCriterion[] findAll()
|
||||
* @method ProductCommentCriterion[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ProductCommentCriterionRepository extends ServiceEntityRepository
|
||||
{
|
||||
/**
|
||||
* @var ManagerRegistry the Doctrine Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var Connection the Database connection
|
||||
*/
|
||||
@@ -43,15 +59,164 @@ class ProductCommentCriterionRepository
|
||||
private $databasePrefix;
|
||||
|
||||
/**
|
||||
* @param ManagerRegistry $registry
|
||||
* @param Connection $connection
|
||||
* @param string $databasePrefix
|
||||
*/
|
||||
public function __construct(Connection $connection, $databasePrefix)
|
||||
public function __construct($registry, $connection, $databasePrefix)
|
||||
{
|
||||
parent::__construct($registry, ProductCommentCriterion::class);
|
||||
$this->connection = $connection;
|
||||
$this->databasePrefix = $databasePrefix;
|
||||
}
|
||||
|
||||
public function add(ProductCommentCriterion $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(ProductCommentCriterion $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteLangs($criterion): int
|
||||
{
|
||||
return $this->connection->executeUpdate('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion_lang`
|
||||
WHERE `id_product_comment_criterion` = ' . $criterion->getId());
|
||||
}
|
||||
|
||||
private function deleteCategories($criterion): int
|
||||
{
|
||||
return $this->connection->executeUpdate('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion_category`
|
||||
WHERE `id_product_comment_criterion` = ' . $criterion->getId());
|
||||
}
|
||||
|
||||
private function deleteProducts($criterion): int
|
||||
{
|
||||
return $this->connection->executeUpdate('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion_product`
|
||||
WHERE `id_product_comment_criterion` = ' . $criterion->getId());
|
||||
}
|
||||
|
||||
private function deleteGrades($criterion): int
|
||||
{
|
||||
return $this->connection->executeUpdate('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'product_comment_criterion_grade`
|
||||
WHERE `id_product_comment_criterion` = ' . $criterion->getId());
|
||||
}
|
||||
|
||||
/* Remove a criterion and Delete its manual relation _lang, _category, _product, _grade */
|
||||
public function delete(ProductCommentCriterion $criterion): int
|
||||
{
|
||||
$res = 0;
|
||||
|
||||
$criterionType = $criterion->getType();
|
||||
|
||||
$this->remove($criterion, true);
|
||||
|
||||
$res += $this->deleteLangs($criterion);
|
||||
|
||||
if ($criterionType == ProductCommentCriterion::CATEGORIES_TYPE) {
|
||||
$res += $this->deleteCategories($criterion);
|
||||
} elseif ($criterionType == ProductCommentCriterion::PRODUCTS_TYPE) {
|
||||
$res += $this->deleteProducts($criterion);
|
||||
}
|
||||
|
||||
$res += $this->deleteGrades($criterion);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/* Update a criterion and Update its manual relation _lang, _category, _product, _grade */
|
||||
public function update(ProductCommentCriterion $criterion): int
|
||||
{
|
||||
$res = 0;
|
||||
|
||||
$criterionType = $criterion->getType();
|
||||
|
||||
$this->getEntityManager()->persist($criterion);
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$res += $this->deleteLangs($criterion);
|
||||
$res += $this->updateLangs($criterion);
|
||||
|
||||
if ($criterionType == ProductCommentCriterion::CATEGORIES_TYPE) {
|
||||
$res += $this->deleteCategories($criterion);
|
||||
$res += $this->updateCategories($criterion);
|
||||
} elseif ($criterionType == ProductCommentCriterion::PRODUCTS_TYPE) {
|
||||
$res += $this->deleteProducts($criterion);
|
||||
$res += $this->updateProducts($criterion);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function updateLangs($criterion): int
|
||||
{
|
||||
$res = 0;
|
||||
$criterionId = $criterion->getId();
|
||||
foreach ($criterion->getNames() as $key => $value) {
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->insert(_DB_PREFIX_ . 'product_comment_criterion_lang')
|
||||
->values(
|
||||
[
|
||||
'id_product_comment_criterion' => '?',
|
||||
'id_lang' => '?',
|
||||
'name' => '?',
|
||||
]
|
||||
)
|
||||
->setParameter(0, $criterionId)
|
||||
->setParameter(1, $key)
|
||||
->setParameter(2, $value)
|
||||
;
|
||||
$res += $this->connection->executeUpdate($qb->getSQL(), $qb->getParameters(), $qb->getParameterTypes());
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function updateCategories($criterion): int
|
||||
{
|
||||
$res = 0;
|
||||
$criterionId = $criterion->getId();
|
||||
foreach ($criterion->getCategories() as $id_category) {
|
||||
$res += $this->connection->executeUpdate(
|
||||
'INSERT INTO `' .
|
||||
_DB_PREFIX_ . 'product_comment_criterion_category` (`id_product_comment_criterion`, `id_category`)
|
||||
VALUES(' . $criterionId . ',' . $id_category . ')'
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function updateProducts($criterion): int
|
||||
{
|
||||
$res = 0;
|
||||
$criterionId = $criterion->getId();
|
||||
foreach ($criterion->getProducts() as $id_product) {
|
||||
$res += $this->connection->executeUpdate(
|
||||
'INSERT INTO `' .
|
||||
_DB_PREFIX_ . 'product_comment_criterion_product` (`id_product_comment_criterion`, `id_product`)
|
||||
VALUES(' . $criterionId . ',' . $id_product . ')'
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $idProduct
|
||||
* @param int $idLang
|
||||
@@ -88,4 +253,116 @@ class ProductCommentCriterionRepository
|
||||
|
||||
return $qb->execute()->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Criterions
|
||||
*
|
||||
* @return array Criterions
|
||||
*/
|
||||
public function getCriterions($id_lang, $type = false, $active = false)
|
||||
{
|
||||
$sql = '
|
||||
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` = ' . $id_lang . ($active ? ' AND active = 1' : '') . ($type ? ' AND id_product_comment_criterion_type = ' . (int) $type : '') . '
|
||||
ORDER BY pccl.`name` ASC';
|
||||
$criterions = $this->connection->executeQuery($sql)->fetchAll();
|
||||
|
||||
$types = self::getTypes();
|
||||
foreach ($criterions as $key => $data) {
|
||||
$criterions[$key]['type_name'] = $types[$data['id_product_comment_criterion_type']];
|
||||
}
|
||||
|
||||
return $criterions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_criterion
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProducts(int $id_criterion)
|
||||
{
|
||||
$sql = '
|
||||
SELECT pccp.id_product, pccp.id_product_comment_criterion
|
||||
FROM `' . _DB_PREFIX_ . 'product_comment_criterion_product` pccp
|
||||
WHERE pccp.id_product_comment_criterion = ' . $id_criterion;
|
||||
|
||||
$res = $this->connection->executeQuery($sql)->fetchAll();
|
||||
|
||||
$products = [];
|
||||
if ($res) {
|
||||
foreach ($res as $row) {
|
||||
$products[] = (int) $row['id_product'];
|
||||
}
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_criterion
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories(int $id_criterion)
|
||||
{
|
||||
$sql = '
|
||||
SELECT pccc.id_category, pccc.id_product_comment_criterion
|
||||
FROM `' . _DB_PREFIX_ . 'product_comment_criterion_category` pccc
|
||||
WHERE pccc.id_product_comment_criterion = ' . $id_criterion;
|
||||
|
||||
$res = $this->connection->executeQuery($sql)->fetchAll();
|
||||
|
||||
$criterions = [];
|
||||
if ($res) {
|
||||
foreach ($res as $row) {
|
||||
$criterions[] = (int) $row['id_category'];
|
||||
}
|
||||
}
|
||||
|
||||
return $criterions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTypes()
|
||||
{
|
||||
$sfTranslator = SymfonyContainer::getInstance()->get('translator');
|
||||
|
||||
return [
|
||||
1 => $sfTranslator->trans('Valid for the entire catalog', [], 'Modules.Productcomments.Admin'),
|
||||
2 => $sfTranslator->trans('Restricted to some categories', [], 'Modules.Productcomments.Admin'),
|
||||
3 => $sfTranslator->trans('Restricted to some products', [], 'Modules.Productcomments.Admin'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Criterion with names in active languages
|
||||
*
|
||||
* @return ProductCommentCriterion
|
||||
*/
|
||||
public function findRelation($id_criterion)
|
||||
{
|
||||
if ($id_criterion > 0) {
|
||||
$criterion = $this->find($id_criterion);
|
||||
$sql = '
|
||||
SELECT `id_lang`, `name`
|
||||
FROM `' . _DB_PREFIX_ . 'product_comment_criterion_lang` pccl
|
||||
WHERE pccl.id_product_comment_criterion = ' . $id_criterion . '
|
||||
ORDER BY pccl.`id_lang` ASC';
|
||||
$langNames = $this->connection->executeQuery($sql)->fetchAll();
|
||||
$langArray = [];
|
||||
foreach ($langNames as $langName) {
|
||||
$langArray[$langName['id_lang']] = $langName['name'];
|
||||
}
|
||||
$criterion->setNames($langArray);
|
||||
} else {
|
||||
$criterion = new ProductCommentCriterion();
|
||||
}
|
||||
|
||||
return $criterion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,28 @@
|
||||
|
||||
namespace PrestaShop\Module\ProductComment\Repository;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Hook;
|
||||
use PrestaShop\Module\ProductComment\Entity\ProductComment;
|
||||
|
||||
class ProductCommentRepository
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ProductComment>
|
||||
*
|
||||
* @method ProductComment|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ProductComment|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ProductComment[] findAll()
|
||||
* @method ProductComment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ProductCommentRepository extends ServiceEntityRepository
|
||||
{
|
||||
/**
|
||||
* @var ManagerRegistry the Doctrine Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var Connection the Database connection
|
||||
*/
|
||||
@@ -54,23 +71,54 @@ class ProductCommentRepository
|
||||
const DEFAULT_COMMENTS_PER_PAGE = 5;
|
||||
|
||||
/**
|
||||
* @param ManagerRegistry $registry
|
||||
* @param Connection $connection
|
||||
* @param string $databasePrefix
|
||||
* @param bool $guestCommentsAllowed
|
||||
* @param int $commentsMinimalTime
|
||||
*/
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
$registry,
|
||||
$connection,
|
||||
$databasePrefix,
|
||||
$guestCommentsAllowed,
|
||||
$commentsMinimalTime
|
||||
) {
|
||||
parent::__construct($registry, ProductComment::class);
|
||||
$this->connection = $connection;
|
||||
$this->databasePrefix = $databasePrefix;
|
||||
$this->guestCommentsAllowed = (bool) $guestCommentsAllowed;
|
||||
$this->commentsMinimalTime = (int) $commentsMinimalTime;
|
||||
}
|
||||
|
||||
public function add(ProductComment $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(ProductComment $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(ProductComment $entity): void
|
||||
{
|
||||
$entityId = $entity->getId();
|
||||
|
||||
$this->remove($entity, true);
|
||||
|
||||
$this->deleteGrades($entityId);
|
||||
$this->deleteReports($entityId);
|
||||
$this->deleteUsefulness($entityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param int $page
|
||||
@@ -153,7 +201,7 @@ class ProductCommentRepository
|
||||
/** @var QueryBuilder $qb */
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('SUM(pc.grade) / COUNT(pc.grade) AS averageGrade')
|
||||
->select('AVG(pc.grade) AS averageGrade')
|
||||
->from($this->databasePrefix . 'product_comment', 'pc')
|
||||
->andWhere('pc.id_product = :id_product')
|
||||
->andWhere('pc.deleted = :deleted')
|
||||
@@ -168,7 +216,84 @@ class ProductCommentRepository
|
||||
;
|
||||
}
|
||||
|
||||
return (float) $qb->execute()->fetchColumn();
|
||||
return (float) $qb->execute()->fetch(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $langId
|
||||
* @param int $shopId
|
||||
* @param int $validate
|
||||
* @param bool $deleted
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param bool $skip_validate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getByValidate($langId, $shopId, $validate = 0, $deleted = false, $page = null, $limit = null, $skip_validate = false)
|
||||
{
|
||||
/** @var QueryBuilder $qb */
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('pc.`id_product_comment`, pc.`id_product`, c.id_customer AS customer_id,
|
||||
IF(c.id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`), pc.customer_name) customer_name,
|
||||
pc.`title`, pc.`content`, pc.`grade`, pc.`date_add`, pl.`name`')
|
||||
->from($this->databasePrefix . 'product_comment', 'pc')
|
||||
->leftJoin('pc', $this->databasePrefix . 'customer', 'c', 'pc.id_customer = c.id_customer')
|
||||
->leftJoin('pc', $this->databasePrefix . 'product_lang', 'pl', 'pc.id_product = pl.id_product')
|
||||
->andWhere('pc.deleted = :deleted')
|
||||
->setParameter('deleted', $deleted)
|
||||
->andWhere('pl.id_lang = :id_lang')
|
||||
->setParameter('id_lang', $langId)
|
||||
->andWhere('pl.id_shop = :id_shop')
|
||||
->setParameter('id_shop', $shopId)
|
||||
->addOrderBy('pc.date_add', 'DESC')
|
||||
;
|
||||
|
||||
if (!$skip_validate) {
|
||||
$qb
|
||||
->andWhere('pc.validate = :validate')
|
||||
->setParameter('validate', $validate)
|
||||
;
|
||||
}
|
||||
if ($page && $limit) {
|
||||
$limit = (int) $limit;
|
||||
$offset = ($page - 1) * $limit;
|
||||
$qb
|
||||
->setFirstResult($offset)
|
||||
->setMaxResults($limit);
|
||||
}
|
||||
|
||||
return $this->connection->executeQuery(
|
||||
$qb->getSQL(), $qb->getParameters(), $qb->getParameterTypes()
|
||||
)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $validate
|
||||
* @param bool $skip_validate
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCountByValidate($validate = 0, $skip_validate = false)
|
||||
{
|
||||
/** @var QueryBuilder $qb */
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('COUNT(*)')
|
||||
->from($this->databasePrefix . 'product_comment', 'pc')
|
||||
;
|
||||
|
||||
if (!$skip_validate) {
|
||||
$qb
|
||||
->andWhere('pc.validate = :validate')
|
||||
->setParameter('validate', $validate)
|
||||
;
|
||||
}
|
||||
|
||||
return (int) $this->connection->executeQuery(
|
||||
$qb->getSQL(), $qb->getParameters(), $qb->getParameterTypes()
|
||||
)->fetch(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,10 +329,7 @@ class ProductCommentRepository
|
||||
|
||||
$sql .= ' FROM ' . $this->databasePrefix . 'product_comment';
|
||||
|
||||
$query = $this->connection->prepare($sql);
|
||||
$query->execute();
|
||||
|
||||
return (array) $query->fetch();
|
||||
return $this->connection->executeQuery($sql)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +358,7 @@ class ProductCommentRepository
|
||||
;
|
||||
}
|
||||
|
||||
return (int) $qb->execute()->fetchColumn();
|
||||
return (int) $qb->execute()->fetch(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,12 +389,7 @@ class ProductCommentRepository
|
||||
|
||||
$sql .= ' FROM ' . $this->databasePrefix . 'product_comment';
|
||||
|
||||
// return $sql;
|
||||
|
||||
$query = $this->connection->prepare($sql);
|
||||
$query->execute();
|
||||
|
||||
return (array) $query->fetch();
|
||||
return (array) $this->connection->executeQuery($sql)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,4 +533,88 @@ class ProductCommentRepository
|
||||
|
||||
return empty($comments) ? [] : $comments[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProductComment $productComment
|
||||
* @param int $validate
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate($productComment, $validate = 1)
|
||||
{
|
||||
$success = $this->connection->executeUpdate('
|
||||
UPDATE `' . _DB_PREFIX_ . 'product_comment` SET
|
||||
`validate` = ' . $validate . '
|
||||
WHERE `id_product_comment` = ' . $productComment->getId());
|
||||
|
||||
Hook::exec('actionObjectProductCommentValidateAfter', ['object' => $productComment]);
|
||||
|
||||
return (bool) $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_product_comment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteGrades($id_product_comment)
|
||||
{
|
||||
$success = $this->connection->executeUpdate('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'product_comment_grade`
|
||||
WHERE `id_product_comment` = ' . $id_product_comment);
|
||||
|
||||
return (bool) $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_product_comment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteReports($id_product_comment)
|
||||
{
|
||||
$success = $this->connection->executeUpdate('
|
||||
DELETE FROM `' . $this->databasePrefix . 'product_comment_report`
|
||||
WHERE `id_product_comment` = ' . $id_product_comment);
|
||||
|
||||
return (bool) $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_product_comment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteUsefulness($id_product_comment)
|
||||
{
|
||||
$success = $this->connection->executeUpdate('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'product_comment_usefulness`
|
||||
WHERE `id_product_comment` = ' . $id_product_comment);
|
||||
|
||||
return (bool) $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $langId
|
||||
* @param int $shopId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReportedComments($langId, $shopId)
|
||||
{
|
||||
$sql = 'SELECT DISTINCT(pc.`id_product_comment`), pc.`id_product`, pc.`content`, pc.`grade`, pc.`date_add`, pc.`title`
|
||||
, IF(c.id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`), pc.customer_name) customer_name, pl.`name`
|
||||
FROM `' . $this->databasePrefix . 'product_comment_report` pcr
|
||||
LEFT JOIN `' . $this->databasePrefix . 'product_comment` pc
|
||||
ON pcr.id_product_comment = pc.id_product_comment
|
||||
LEFT JOIN `' . $this->databasePrefix . 'customer` c ON (c.`id_customer` = pc.`id_customer`)
|
||||
LEFT JOIN `' . $this->databasePrefix . 'product_lang` pl ON ' .
|
||||
'(pl.`id_product` = pc.`id_product` ' .
|
||||
' AND pl.`id_lang` = ' . $langId .
|
||||
' AND pl.`id_shop` = ' . $shopId .
|
||||
')
|
||||
ORDER BY pc.`date_add` DESC';
|
||||
|
||||
return $this->connection->executeQuery($sql)->fetchAll();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user