37 lines
1 KiB
PHP
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);
|
|
}
|
|
}
|