Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -2,20 +2,24 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\Folder\FolderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Files\FileModelParentInterface;
use Thelia\Model\Base\Folder as BaseFolder;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
use Thelia\Model\Tools\UrlRewritingTrait;
class Folder extends BaseFolder implements FileModelParentInterface
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
use PositionManagementTrait;
use \Thelia\Model\Tools\UrlRewritingTrait;
use UrlRewritingTrait;
/**
* {@inheritDoc}
@@ -34,26 +38,25 @@ class Folder extends BaseFolder implements FileModelParentInterface
}
/**
*
* count all products for current category and sub categories
*
* @param bool|string $contentVisibility true (default) to count only visible products, false to count only hidden
* products, or * to count all products.
* @return int
*/
public function countAllContents()
public function countAllContents($contentVisibility = true)
{
$children = FolderQuery::findAllChild($this->getId());
array_push($children, $this);
$contentsCount = 0;
foreach ($children as $child) {
$contentsCount += ContentQuery::create()
->filterByFolder($child)
->count();
$query = ContentQuery::create()->filterByFolder(new ObjectCollection($children), Criteria::IN);
if ($contentVisibility !== '*') {
$query->filterByVisible($contentVisibility);
}
return $contentsCount;
return $query->count();
}
/**
@@ -63,7 +66,6 @@ class Folder extends BaseFolder implements FileModelParentInterface
*/
public function getRoot($folderId)
{
$folder = FolderQuery::create()->findPk($folderId);
if (0 !== $folder->getParent()) {
@@ -75,11 +77,12 @@ class Folder extends BaseFolder implements FileModelParentInterface
}
return $folderId;
}
/**
* Calculate next position relative to our parent
* @param FolderQuery $query
*/
protected function addCriteriaToPositionQuery($query)
{
@@ -133,4 +136,21 @@ class Folder extends BaseFolder implements FileModelParentInterface
$this->dispatchEvent(TheliaEvents::AFTER_DELETEFOLDER, new FolderEvent($this));
}
/**
* Overload for the position management
* @param Base\ContentFolder $contentFolder
* @inheritdoc
*/
protected function doAddContentFolder($contentFolder)
{
parent::doAddContentFolder($contentFolder);
$contentFolderPosition = ContentFolderQuery::create()
->filterByFolderId($contentFolder->getFolderId())
->orderByPosition(Criteria::DESC)
->findOne();
$contentFolder->setPosition($contentFolderPosition !== null ? $contentFolderPosition->getPosition() + 1 : 1);
}
}