deblan.tv/vendor/trinity/src/Trinity/Bundle/MediaBundle/Model/MediaQuery.php
2015-03-02 21:57:49 +01:00

37 lines
1 KiB
PHP

<?php
namespace Trinity\Bundle\MediaBundle\Model;
use Trinity\Bundle\MediaBundle\Model\om\BaseMediaQuery;
class MediaQuery extends BaseMediaQuery
{
public function filterByCategoryId($categoryId = null, $comparison = null)
{
$category = CategoryQuery::create()->findOneById($categoryId);
if ($category) {
return $this->filterByCategory($category, $comparison);
}
return parent::filterByCategoryId($categoryId, $comparison);
}
public function filterByCategory($category, $comparison = null)
{
if ($category instanceof Category) {
$categories = $category->getDescendants();
$categories[] = $category;
$categoriesIds = [];
foreach ($categories as $category) {
$categoriesIds[] = $category->getId();
}
return $this->where(sprintf('%s in (%s)', MediaPeer::CATEGORY_ID, implode(',', $categoriesIds)));
}
return parent::filterByCategory($category, $comparison);
}
}