Merge branch 'master' into cart

Conflicts:
	core/lib/Thelia/Core/Template/Loop/Category.php
	install/faker.php
This commit is contained in:
Manuel Raynaud
2013-08-07 10:23:44 +02:00
24 changed files with 1398 additions and 30 deletions

View File

@@ -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;
}
}

View File

@@ -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