Merge branch 'master' into cart
Conflicts: core/lib/Thelia/Core/Template/Loop/Category.php install/faker.php
This commit is contained in:
63
core/lib/Thelia/Admin/Controller/CategoryController.php
Normal file
63
core/lib/Thelia/Admin/Controller/CategoryController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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\Admin\Controller;
|
||||
|
||||
class CategoryController extends BaseAdminController {
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
// Show top level categories and products
|
||||
$args = array(
|
||||
'action' => 'browse',
|
||||
'current_category_id' => 0
|
||||
);
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
public function processAction($action)
|
||||
{
|
||||
list($action, $id) = explode('/', $action);
|
||||
|
||||
$args = array(
|
||||
'action' => $action,
|
||||
'current_category_id' => $id
|
||||
);
|
||||
|
||||
// Browe categories
|
||||
if ($action == 'browse') {
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
// Create a new category
|
||||
else if ($action = 'create') {
|
||||
return $this->render('edit_category', $args);
|
||||
}
|
||||
// Edit an existing category
|
||||
else if ($action = 'edit') {
|
||||
return $this->render('edit_category', $args);
|
||||
}
|
||||
|
||||
//return $this->render("categories");
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,13 @@
|
||||
<loop class="Thelia\Core\Template\Loop\Address" name="address"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Auth" name="auth"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Content" name="content"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Country" name="country"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Customer" name="customer"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Feature" name="feature"/>
|
||||
<loop class="Thelia\Core\Template\Loop\FeatureAvailable" name="feature_available"/>
|
||||
<loop class="Thelia\Core\Template\Loop\FeatureValue" name="feature_value"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Folder" name="folder"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Order" name="order"/>
|
||||
<loop class="Thelia\Core\Template\Loop\OrderStatus" name="order-status"/>
|
||||
<loop class="Thelia\Core\Template\Loop\CategoryPath" name="category-path"/>
|
||||
@@ -82,7 +84,7 @@
|
||||
<argument type="service" id="request" />
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
<argument type="service" id="thelia.parser.context"/>
|
||||
<argument >false</argument>
|
||||
<argument >true</argument> <!-- debug mode -->
|
||||
<argument >%kernel.environment%</argument>
|
||||
<argument >%kernel.debug%</argument>
|
||||
</service>
|
||||
|
||||
@@ -97,7 +97,8 @@ abstract class BaseLoop
|
||||
|
||||
if (substr($name, 0, 3) == 'get') {
|
||||
|
||||
$argName = strtolower(substr($name, 3));
|
||||
// camelCase to underscore: getNotEmpty -> not_empty
|
||||
$argName = strtolower(preg_replace('/([^A-Z])([A-Z])/', "$1_$2", substr($name, 3)));
|
||||
|
||||
return $this->getArg($argName)->getValue();
|
||||
}
|
||||
|
||||
@@ -161,11 +161,14 @@ class Category extends BaseLoop
|
||||
|
||||
$categories = $this->search($search, $pagination);
|
||||
|
||||
$notEmpty = $this->getNot_empty();
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($categories as $category) {
|
||||
|
||||
if ($this->getNot_empty() && $category->countAllProducts() == 0) continue;
|
||||
if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
|
||||
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
|
||||
126
core/lib/Thelia/Core/Template/Loop/CategoryPath.php
Normal file
126
core/lib/Thelia/Core/Template/Loop/CategoryPath.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?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\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* Category path loop, to get the path to a given category.
|
||||
*
|
||||
* - category is the category id
|
||||
* - depth is the maximum depth to go, default unlimited
|
||||
* - level is the exact level to return. Example: if level = 2 and the path is c1 -> c2 -> c3 -> c4, the loop will return c2
|
||||
* - visible if true or missing, only visible categories will be displayed. If false, all categories (visible or not) are returned.
|
||||
*
|
||||
* example :
|
||||
*
|
||||
* <THELIA_cat type="category-path" category="3">
|
||||
* <a href="#URL">#TITLE</a>
|
||||
* </THELIA_cat>
|
||||
*
|
||||
*
|
||||
* Class CategoryPath
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class CategoryPath extends BaseLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntTypeArgument('category', null, true),
|
||||
Argument::createIntTypeArgument('depth'),
|
||||
Argument::createIntTypeArgument('level'),
|
||||
Argument::createBooleanTypeArgument('visible', true, false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination (ignored)
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$id = $this->getCategory();
|
||||
$visible = $this->getVisible();
|
||||
|
||||
$search = CategoryQuery::create();
|
||||
$search->filterById($id);
|
||||
if ($visible == true) $search->filterByVisible($visible);
|
||||
|
||||
$results = array();
|
||||
|
||||
do {
|
||||
$category = $search->findOne();
|
||||
|
||||
if ($category != null) {
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
$loopResultRow
|
||||
->set("TITLE",$category->getTitle())
|
||||
->set("URL", $category->getUrl())
|
||||
->set("ID", $category->getId())
|
||||
;
|
||||
|
||||
$results[] = $loopResultRow;
|
||||
|
||||
$parent = $category->getParent();
|
||||
|
||||
if ($parent > 0) {
|
||||
$search = CategoryQuery::create();
|
||||
$search->filterById($parent);
|
||||
if ($visible == true) $search->filterByVisible($visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
while ($category != null && $parent > 0);
|
||||
|
||||
// Reverse list and build the final result
|
||||
$results = array_reverse($results);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach($results as $result) $loopResult->addRow($result);
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
238
core/lib/Thelia/Core/Template/Loop/Content.php
Executable file
238
core/lib/Thelia/Core/Template/Loop/Content.php
Executable file
@@ -0,0 +1,238 @@
|
||||
<?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\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\ActiveQuery\Join;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\Base\FeatureContentQuery;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\Map\ContentTableMap;
|
||||
use Thelia\Model\ContentFolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* Content loop
|
||||
*
|
||||
*
|
||||
* Class Content
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Content extends BaseLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('folder'),
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('current_folder'),
|
||||
Argument::createIntTypeArgument('depth', 1),
|
||||
Argument::createBooleanTypeArgument('visible', 1),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'random', 'given_id'))
|
||||
),
|
||||
'alpha'
|
||||
),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
Argument::createIntListTypeArgument('exclude_folder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return LoopResult
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = ContentQuery::create();
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (!is_null($id)) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$folder = $this->getFolder();
|
||||
|
||||
if (!is_null($folder)) {
|
||||
$folders = FolderQuery::create()->filterById($folder, Criteria::IN)->find();
|
||||
|
||||
$depth = $this->getDepth();
|
||||
|
||||
if(null !== $depth) {
|
||||
foreach(FolderQuery::findAllChild($folder, $depth) as $subFolder) {
|
||||
$folders->prepend($subFolder);
|
||||
}
|
||||
}
|
||||
|
||||
$search->filterByFolder(
|
||||
$folders,
|
||||
Criteria::IN
|
||||
);
|
||||
}
|
||||
|
||||
$current = $this->getCurrent();
|
||||
|
||||
if ($current === true) {
|
||||
$search->filterById($this->request->get("content_id"));
|
||||
} elseif($current === false) {
|
||||
$search->filterById($this->request->get("content_id"), Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$current_folder = $this->getCurrent_folder();
|
||||
|
||||
if ($current_folder === true) {
|
||||
$search->filterByFolder(
|
||||
FolderQuery::create()->filterByContent(
|
||||
ContentFolderQuery::create()->filterByContentId(
|
||||
$this->request->get("content_id"),
|
||||
Criteria::EQUAL
|
||||
)->find(),
|
||||
Criteria::IN
|
||||
)->find(),
|
||||
Criteria::IN
|
||||
);
|
||||
} elseif($current_folder === false) {
|
||||
$search->filterByFolder(
|
||||
FolderQuery::create()->filterByContent(
|
||||
ContentFolderQuery::create()->filterByContentId(
|
||||
$this->request->get("content_id"),
|
||||
Criteria::EQUAL
|
||||
)->find(),
|
||||
Criteria::IN
|
||||
)->find(),
|
||||
Criteria::NOT_IN
|
||||
);
|
||||
}
|
||||
|
||||
$visible = $this->getVisible();
|
||||
|
||||
$search->filterByVisible($visible);
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE);
|
||||
break;
|
||||
case "manual":
|
||||
if(null === $folder || count($folder) != 1)
|
||||
throw new \InvalidArgumentException('Manual order cannot be set without single folder argument');
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case "manual_reverse":
|
||||
if(null === $folder || count($folder) != 1)
|
||||
throw new \InvalidArgumentException('Manual order cannot be set without single folder argument');
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
case "given_id":
|
||||
if(null === $id)
|
||||
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
|
||||
foreach($id as $singleId) {
|
||||
$givenIdMatched = 'given_id_matched_' . $singleId;
|
||||
$search->withColumn(ContentTableMap::ID . "='$singleId'", $givenIdMatched);
|
||||
$search->orderBy($givenIdMatched, Criteria::DESC);
|
||||
}
|
||||
break;
|
||||
case "random":
|
||||
$search->clearOrderByColumns();
|
||||
$search->addAscendingOrderByColumn('RAND()');
|
||||
break(2);
|
||||
}
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (!is_null($exclude)) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$exclude_folder = $this->getExclude_folder();
|
||||
|
||||
if (!is_null($exclude_folder)) {
|
||||
$search->filterByFolder(
|
||||
FolderQuery::create()->filterById($exclude_folder, Criteria::IN)->find(),
|
||||
Criteria::NOT_IN
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
* @todo : verify here if we want results for row without translations.
|
||||
*/
|
||||
|
||||
$search->joinWithI18n(
|
||||
$this->request->getSession()->getLocale(),
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);
|
||||
|
||||
$search->groupBy(ContentTableMap::ID);
|
||||
|
||||
$contents = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($contents as $content) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
$loopResultRow->set("ID", $content->getId())
|
||||
->set("TITLE",$content->getTitle())
|
||||
->set("CHAPO", $content->getChapo())
|
||||
->set("DESCRIPTION", $content->getDescription())
|
||||
->set("POSTSCRIPTUM", $content->getPostscriptum())
|
||||
->set("POSITION", $content->getPosition())
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
|
||||
}
|
||||
179
core/lib/Thelia/Core/Template/Loop/Folder.php
Executable file
179
core/lib/Thelia/Core/Template/Loop/Folder.php
Executable file
@@ -0,0 +1,179 @@
|
||||
<?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\Template\Loop;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
* Class Folder
|
||||
*
|
||||
* @package Thelia\Core\Template\Loop
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Folder extends BaseLoop
|
||||
{
|
||||
/**
|
||||
* @return ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntTypeArgument('parent'),
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('not_empty', 0),
|
||||
Argument::createBooleanTypeArgument('visible', 1),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual-reverse', 'random'))
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
Argument::createIntListTypeArgument('exclude')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
$search = FolderQuery::create();
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (!is_null($id)) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$parent = $this->getParent();
|
||||
|
||||
if (!is_null($parent)) {
|
||||
$search->filterByParent($parent);
|
||||
}
|
||||
|
||||
|
||||
$current = $this->getCurrent();
|
||||
|
||||
if ($current === true) {
|
||||
$search->filterById($this->request->get("folder_id"));
|
||||
} elseif ($current === false) {
|
||||
$search->filterById($this->request->get("folder_id"), Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
|
||||
if (!is_null($exclude)) {
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE);
|
||||
break;
|
||||
case "alpha_reverse":
|
||||
$search->addDescendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE);
|
||||
break;
|
||||
case "manual-reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case "random":
|
||||
$search->clearOrderByColumns();
|
||||
$search->addAscendingOrderByColumn('RAND()');
|
||||
break(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \Criteria::INNER_JOIN in second parameter for joinWithI18n exclude query without translation.
|
||||
*
|
||||
* @todo : verify here if we want results for row without translations.
|
||||
*/
|
||||
|
||||
$search->joinWithI18n(
|
||||
$this->request->getSession()->getLocale(),
|
||||
(ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN
|
||||
);
|
||||
|
||||
$folders = $this->search($search, $pagination);
|
||||
|
||||
$notEmpty = $this->getNot_empty();
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
|
||||
if ($notEmpty && $folder->countAllProducts() == 0) continue;
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
$loopResultRow
|
||||
->set("ID", $folder->getId())
|
||||
->set("TITLE",$folder->getTitle())
|
||||
->set("CHAPO", $folder->getChapo())
|
||||
->set("DESCRIPTION", $folder->getDescription())
|
||||
->set("POSTSCRIPTUM", $folder->getPostscriptum())
|
||||
->set("PARENT", $folder->getParent())
|
||||
->set("CONTENT_COUNT", $folder->countChild())
|
||||
->set("VISIBLE", $folder->getVisible() ? "1" : "0")
|
||||
->set("POSITION", $folder->getPosition())
|
||||
|
||||
->set("CREATE_DATE", $folder->getCreatedAt())
|
||||
->set("UPDATE_DATE", $folder->getUpdatedAt())
|
||||
->set("VERSION", $folder->getVersion())
|
||||
->set("VERSION_DATE", $folder->getVersionCreatedAt())
|
||||
->set("VERSION_AUTHOR", $folder->getVersionCreatedBy())
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,7 @@ class Product extends BaseLoop
|
||||
* @param $pagination
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
@@ -402,11 +403,11 @@ class Product extends BaseLoop
|
||||
->set("CHAPO", $product->getChapo())
|
||||
->set("DESCRIPTION", $product->getDescription())
|
||||
->set("POSTSCRIPTUM", $product->getPostscriptum())
|
||||
->set("PRICE", $product->getPrice())
|
||||
->set("PROMO_PRICE", $product->getPrice2())
|
||||
->set("WEIGHT", $product->getWeight())
|
||||
->set("PROMO", $product->getPromo())
|
||||
->set("NEW", $product->getNewness())
|
||||
//->set("PRICE", $product->getPrice())
|
||||
//->set("PROMO_PRICE", $product->getPrice2())
|
||||
//->set("WEIGHT", $product->getWeight())
|
||||
//->set("PROMO", $product->getPromo())
|
||||
//->set("NEW", $product->getNewness())
|
||||
->set("POSITION", $product->getPosition())
|
||||
;
|
||||
|
||||
|
||||
@@ -4,6 +4,37 @@ namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Folder as BaseFolder;
|
||||
|
||||
class Folder extends BaseFolder {
|
||||
class Folder extends BaseFolder
|
||||
{
|
||||
/**
|
||||
* @return int number of contents for the folder
|
||||
*/
|
||||
public function countChild()
|
||||
{
|
||||
return FolderQuery::countChild($this->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* count all products for current category and sub categories
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countAllContents()
|
||||
{
|
||||
$children = FolderQuery::findAllChild($this->getId());
|
||||
array_push($children, $this);
|
||||
|
||||
$contentsCount = 0;
|
||||
|
||||
foreach($children as $child)
|
||||
{
|
||||
$contentsCount += ProductQuery::create()
|
||||
->filterByCategory($child)
|
||||
->count();
|
||||
}
|
||||
|
||||
return $contentsCount;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,52 @@ use Thelia\Model\Base\FolderQuery as BaseFolderQuery;
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
*/
|
||||
class FolderQuery extends BaseFolderQuery {
|
||||
class FolderQuery extends BaseFolderQuery
|
||||
{
|
||||
/**
|
||||
*
|
||||
* count how many direct contents a folder has
|
||||
*
|
||||
* @param int $parent folder id
|
||||
* @return int
|
||||
*/
|
||||
public static function countChild($parent)
|
||||
{
|
||||
return self::create()->filterByParent($parent)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* find all contents for a given folder.
|
||||
*
|
||||
* @param $folderId the folder id or an array of id
|
||||
* @param int $depth max depth you want to search
|
||||
* @param int $currentPosition don't change this param, it is used for recursion
|
||||
* @return \Thelia\Model\Folder[]
|
||||
*/
|
||||
public static function findAllChild($folderId, $depth = 0, $currentPosition = 0)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
if(is_array($folderId)) {
|
||||
foreach($folderId as $folderSingleId) {
|
||||
$result = array_merge($result, (array) self::findAllChild($folderSingleId, $depth, $currentPosition));
|
||||
}
|
||||
} else {
|
||||
$currentPosition++;
|
||||
|
||||
if($depth == $currentPosition && $depth != 0) return;
|
||||
|
||||
$categories = self::create()
|
||||
->filterByParent($folderId)
|
||||
->find();
|
||||
|
||||
|
||||
foreach ($categories as $folder) {
|
||||
array_push($result, $folder);
|
||||
$result = array_merge($result, (array) self::findAllChild($folder->getId(), $depth, $currentPosition));
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
} // FolderQuery
|
||||
|
||||
51
core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php
Executable file
51
core/lib/Thelia/Tests/Core/Template/Loop/ContentTest.php
Executable 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\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
use Thelia\Core\Template\Loop\Content;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ContentTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Content';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Content($this->request, $this->dispatcher, $this->securityContext);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
51
core/lib/Thelia/Tests/Core/Template/Loop/FolderTest.php
Executable file
51
core/lib/Thelia/Tests/Core/Template/Loop/FolderTest.php
Executable 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\Tests\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
use Thelia\Core\Template\Loop\Folder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class FolderTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\Folder';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new Folder($this->request, $this->dispatcher, $this->securityContext);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user