/** * Gets paged posts from a category * * @param Category $category * @param int $page * @return Zend\Paginator\Paginator **/ public function getPagedFromCategory(Category $category, $page) { $qb = $this->em->createQueryBuilder(); $qb->select('partial p.{id, title}')->from(self::ENTITY_POST, 'p')->join('p.category', 'c')->orderBy('p.dateAdded', 'DESC')->where('c.id = :id')->andWhere('p.isPublished = :published')->setParameters(array('id' => $category->getId(), 'published' => 1)); $paginator = PaginatorFactory::create($qb, $page); return $paginator; }
/** * Declares an association between this object and a Category object. * * @param Category $v * @return Post The current object (for fluent API support) * @throws PropelException */ public function setCategory(Category $v = null) { if ($v === null) { $this->setCategoryId(NULL); } else { $this->setCategoryId($v->getId()); } $this->aCategory = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Category object, it will not be re-added. if ($v !== null) { $v->addPost($this); } return $this; }
/** * Filter the query by a related Category object * * @param Category|PropelCollection $category The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return PostQuery The current query, for fluid interface */ public function filterByCategory($category, $comparison = null) { if ($category instanceof Category) { return $this->addUsingAlias(PostPeer::CATEGORY_ID, $category->getId(), $comparison); } elseif ($category instanceof PropelCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(PostPeer::CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByCategory() only accepts arguments of type Category or PropelCollection'); } }
/** * Exclude object from result * * @param Category $category Object to remove from the list of results * * @return CategoryQuery The current query, for fluid interface */ public function prune($category = null) { if ($category) { $this->addUsingAlias(CategoryPeer::ID, $category->getId(), Criteria::NOT_EQUAL); } return $this; }