Skip to content
Permalink
Browse files

Improved import/export loops

  • Loading branch information...
Franck Allimant authored and roadster31 committed May 20, 2019
1 parent a65fc16 commit 832dac801c6aac7128e1d3e452b454806c01c5b4
@@ -26,6 +26,9 @@ protected function getBaseUrl()
return $this->container->getParameter("export.base_url");
}
/**
* @return ExportQUery
*/
protected function getQueryModel()
{
return ExportQuery::create();
@@ -21,6 +21,9 @@
*/
class ExportCategory extends ImportExportCategory
{
/**
* @return ExportCategoryQuery
*/
protected function getQueryModel()
{
return ExportCategoryQuery::create();
@@ -26,6 +26,9 @@ protected function getBaseUrl()
return $this->container->getParameter("import.base_url");
}
/**
* @return ImportQuery
*/
protected function getQueryModel()
{
return ImportQuery::create();
@@ -21,6 +21,9 @@
*/
class ImportCategory extends ImportExportCategory
{
/**
* @return ImportCategoryQuery
*/
protected function getQueryModel()
{
return ImportCategoryQuery::create();
@@ -13,13 +13,14 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\ExportCategoryQuery;
use Thelia\Model\ImportCategoryQuery;
use Thelia\Type\EnumListType;
use Thelia\Type\TypeCollection;
@@ -30,6 +31,7 @@
*
* {@inheritdoc}
* @method int[] getId()
* @method string[] getRef()
* @method string[] getOrder()
*/
abstract class ImportExportCategory extends BaseI18nLoop implements PropelSearchLoopInterface
@@ -38,16 +40,18 @@ abstract class ImportExportCategory extends BaseI18nLoop implements PropelSearch
/**
* @param LoopResult $loopResult
*
* @return LoopResult
* @throws \Propel\Runtime\Exception\PropelException
*/
public function parseResults(LoopResult $loopResult)
{
/** @var \Thelia\Model\ExportCategory|\Thelia\Model\ImportCategory $category */
foreach ($loopResult->getResultDataCollection() as $category) {
$loopResultRow = new LoopResultRow($category);
$loopResultRow
->set("ID", $category->getId())
->set("REF", $category->getRef())
->set("TITLE", $category->getVirtualColumn("i18n_TITLE"))
->set("POSITION", $category->getPosition())
;
@@ -66,7 +70,7 @@ public function parseResults(LoopResult $loopResult)
*/
public function buildModelCriteria()
{
/** @var ModelCriteria $query */
/** @var ImportCategoryQuery|ExportCategoryQuery $query */
$query = $this->getQueryModel();
$this->configureI18nProcessing($query, array('TITLE'));
@@ -75,6 +79,10 @@ public function buildModelCriteria()
$query->filterById($ids, Criteria::IN);
}
if (null !== $refs = $this->getRef()) {
$query->filterByRef($refs, Criteria::IN);
}
if (null !== $orders = $this->getOrder()) {
foreach ($orders as $order) {
switch ($order) {
@@ -84,6 +92,12 @@ public function buildModelCriteria()
case "id_reverse":
$query->orderById(Criteria::DESC);
break;
case "ref":
$query->orderByRef();
break;
case "ref_reverse":
$query->orderByRef(Criteria::DESC);
break;
case "alpha":
$query->addAscendingOrderByColumn("i18n_TITLE");
break;
@@ -110,15 +124,19 @@ protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createAnyListTypeArgument('ref'),
new Argument(
"order",
new TypeCollection(
new EnumListType(["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"])
new EnumListType(["id", "id_reverse", "ref", "ref_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"])
),
"manual"
)
);
}
/**
* @return ImportCategoryQuery|ExportCategoryQuery
*/
abstract protected function getQueryModel();
}
@@ -13,14 +13,14 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Exception\ClassNotFoundException;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Log\Tlog;
use Thelia\Model\Import as ImportModel;
use Thelia\Tools\URL;
use Thelia\Type\EnumListType;
@@ -33,6 +33,7 @@
*
* {@inheritdoc}
* @method int[] getId()
* @method string[] getRef()
* @method int[] getCategory()
* @method string[] getOrder()
*/
@@ -44,12 +45,12 @@ abstract class ImportExportType extends BaseI18nLoop implements PropelSearchLoop
/**
* @param LoopResult $loopResult
*
* @return LoopResult
* @throws \Propel\Runtime\Exception\PropelException
*/
public function parseResults(LoopResult $loopResult)
{
/** @var ImportModel $type */
/** @var ImportModel|\Thelia\Model\Export $type */
foreach ($loopResult->getResultDataCollection() as $type) {
$loopResultRow = new LoopResultRow($type);
@@ -61,14 +62,15 @@ public function parseResults(LoopResult $loopResult)
$loopResultRow
->set("HANDLE_CLASS", $type->getHandleClass())
->set("ID", $type->getId())
->set("REF", $type->getRef())
->set("TITLE", $type->getVirtualColumn("i18n_TITLE"))
->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION"))
->set("URL", $url)
->set("POSITION", $type->getPosition())
->set("CATEGORY_ID", $type->getByName($this->getCategoryName()))
;
} catch (ClassNotFoundException $e) {
} catch (\ErrorException $e) {
} catch (\Exception $e) {
Tlog::getInstance()->error($e->getMessage());
}
$this->addOutputFields($loopResultRow, $type);
@@ -85,7 +87,7 @@ public function parseResults(LoopResult $loopResult)
*/
public function buildModelCriteria()
{
/** @var ModelCriteria $query */
/** @var \Thelia\Model\ImportQuery|\Thelia\Model\ExportQUery $query */
$query = $this->getQueryModel();
$this->configureI18nProcessing($query, array('TITLE', 'DESCRIPTION'));
@@ -94,6 +96,10 @@ public function buildModelCriteria()
$query->filterById($ids);
}
if (null !== $refs = $this->getRef()) {
$query->filterByRef($refs);
}
if (null !== $categories = $this->getCategory()) {
$query->filterBy($this->getCategoryName(), $categories, Criteria::IN);
}
@@ -107,6 +113,12 @@ public function buildModelCriteria()
case "id_reverse":
$query->orderById(Criteria::DESC);
break;
case "ref":
$query->orderByRef();
break;
case "ref_reverse":
$query->orderByRef(Criteria::DESC);
break;
case "alpha":
$query->addAscendingOrderByColumn("i18n_TITLE");
break;
@@ -155,6 +167,7 @@ protected function getArgDefinitions()
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('category'),
Argument::createAnyListTypeArgument('ref'),
new Argument(
"order",
new TypeCollection(
@@ -167,12 +180,21 @@ protected function getArgDefinitions()
public static function getAllowedOrders()
{
return ["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"];
return ["id", "id_reverse", "ref", "ref_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"];
}
/**
* @return string
*/
abstract protected function getBaseUrl();
/**
* @return \Thelia\Model\ImportQuery|\Thelia\Model\ExportQUery
*/
abstract protected function getQueryModel();
/**
* @return string
*/
abstract protected function getCategoryName();
}

0 comments on commit 832dac8

Please sign in to comment.
You can’t perform that action at this time.