Ejemplo n.º 1
0
 /**
  * @return void
  */
 public function testToCriteriaShouldReturnCriteriaWithParameters()
 {
     $filterTransfer = new FilterTransfer();
     $filterTransfer->setLimit(10);
     $filterTransfer->setOffset(0);
     $filterTransfer->setOrderDirection('DESC');
     $filterTransfer->setOrderBy('foobar');
     $filterCriteria = new PropelFilterCriteria($filterTransfer);
     $propelCriteria = $filterCriteria->toCriteria();
     $this->assertInstanceOf(Criteria::class, $propelCriteria);
     $this->assertEquals(10, $propelCriteria->getLimit());
     $this->assertEquals(0, $propelCriteria->getOffset());
     $this->assertEquals(['foobar DESC'], $propelCriteria->getOrderByColumns());
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function toCriteria()
 {
     $criteria = new Criteria();
     if ($this->filterTransfer->getLimit() !== null) {
         $criteria->setLimit($this->filterTransfer->getLimit());
     }
     if ($this->filterTransfer->getOffset() !== null) {
         $criteria->setOffset($this->filterTransfer->getOffset());
     }
     if ($this->filterTransfer->getOrderBy() !== null) {
         if ($this->filterTransfer->getOrderDirection() === 'ASC') {
             $criteria->addAscendingOrderByColumn($this->filterTransfer->getOrderBy());
         } elseif ($this->filterTransfer->getOrderDirection() === 'DESC') {
             $criteria->addDescendingOrderByColumn($this->filterTransfer->getOrderBy());
         }
     }
     return $criteria;
 }