/**
  * @return OrderChain
  **/
 public function toOrder()
 {
     $order = OrderChain::create();
     foreach ($this->list as $property) {
         $order->add($property->evaluate($this->parameters));
     }
     return $order;
 }
 public function testOrderBy()
 {
     $query = OQL::select('from TestUser');
     $criteria = Criteria::create(TestUser::dao());
     $this->assertCriteria($query->addOrderBy(OQL::orderBy('id')), $criteria->addOrder(OrderBy::create('id')));
     $this->assertCriteria($query->addOrderBy(OQL::orderBy('name asc, city.id desc')), $criteria->addOrder(OrderBy::create('name')->asc())->addOrder(OrderBy::create('city.id')->desc()));
     $this->assertEquals(OQL::orderBy('id + city.id desc, name')->toOrder(), OrderChain::create()->add(OrderBy::create(Expression::add('id', 'city.id'))->desc())->add(OrderBy::create('name')));
     $order = OQL::orderBy('name ilike $1')->bindNext('%ЙЦуК');
     $this->assertEquals($order->toOrder(), OrderChain::create()->add(OrderBy::create(Expression::ilike('name', '%ЙЦуК'))));
     $this->assertCriteria(OQL::select('from TestUser')->addOrderBy($order)->bindNext('test'), Criteria::create(TestUser::dao())->addOrder(OrderBy::create(Expression::ilike('name', 'test'))));
 }
Exemplo n.º 3
0
 public static function orderDataProvider()
 {
     return array(array(OrderBy::create('id'), 'test_user.id'), array(OrderChain::create()->add(OrderBy::create('id')->asc())->add(OrderBy::create('id')), 'test_user.id ASC, test_user.id'), array(OrderBy::create('id')->asc(), 'test_user.id ASC'), array(OrderBy::create('id')->desc(), 'test_user.id DESC'), array(OrderBy::create('id')->nullsFirst(), 'test_user.id NULLS FIRST'), array(OrderBy::create('id')->nullsLast(), 'test_user.id NULLS LAST'), array(OrderBy::create('id')->asc()->nullsLast(), 'test_user.id ASC NULLS LAST'), array(OrderBy::create('id')->desc()->nullsFirst(), 'test_user.id DESC NULLS FIRST'), array(OrderBy::create(Expression::isNull('id'))->asc()->nullsFirst(), '((test_user.id IS NULL)) ASC NULLS FIRST'));
 }
 public function testOrderBy()
 {
     $this->assertCriteria('from TestUser order by id', Criteria::create(TestUser::dao())->addOrder(OrderBy::create('id')))->assertCriteria('from TestUser order by id asc, nickname desc', Criteria::create(TestUser::dao())->addOrder(OrderChain::create()->add(OrderBy::create('id')->asc())->add(OrderBy::create('nickname')->desc())))->assertCriteria('from TestUser order by $1, nickname is null, -id/2 + 1 asc ', Criteria::create(TestUser::dao())->addOrder(OrderChain::create()->add(OrderBy::create(SQLFunction::create('rand')))->add(OrderBy::create(Expression::isNull('nickname')))->add(OrderBy::create(Expression::add(Expression::div(Expression::minus('id'), 2), 1))->asc())), array(1 => SQLFunction::create('rand')));
 }