コード例 #1
0
 public function testChainForm()
 {
     $form = Form::create()->add(Primitive::string('a'))->add(Primitive::string('b'))->add(Primitive::integer('c'))->add(Primitive::integer('d'))->add(Primitive::boolean('e'))->add(Primitive::string('f'))->import(array('a' => 'true', 'c' => 123, 'd' => 123));
     $andChain = Expression::chain()->expAnd(Expression::expOr(new FormField('a'), Expression::notNull(new FormField('b'))))->expAnd(Expression::eq(new FormField('c'), new FormField('d')))->expAnd(Expression::isFalse(new FormField('e')));
     $this->assertTrue($andChain->toBoolean($form));
     $form->importMore(array('e' => 'on'));
     $this->assertFalse($andChain->toBoolean($form));
     $orChain = Expression::chain()->expOr(Expression::eq(new FormField('a'), new FormField('b')))->expOr(Expression::expOr(new FormField('e'), Expression::gt(new FormField('c'), new FormField('d'))))->expOr(Expression::in(new FormField('f'), array('qwer', 'asdf', 'zxcv')));
     $form->import(array());
     $this->assertFalse($orChain->toBoolean($form));
     $form->import(array('e' => '1'));
     $this->assertTrue($orChain->toBoolean($form));
     $form->import(array('a' => 'asdf', 'b' => 'qwerq', 'c' => '13', 'd' => '1313', 'f' => 'iukj'));
     $this->assertFalse($orChain->toBoolean($form));
     $form->import(array('c' => '13', 'd' => '12'));
     $this->assertTrue($orChain->toBoolean($form));
     $form->import(array('f' => 'asdfwer'));
     $this->assertFalse($orChain->toBoolean($form));
     $form->import(array('f' => 'qwer'));
     $this->assertTrue($orChain->toBoolean($form));
 }
コード例 #2
0
 /**
  * @return Criteria
  **/
 public function toCriteria()
 {
     $criteria = Criteria::create($this->dao)->setDistinct($this->distinct);
     $projections = array_merge($this->properties, $this->groupChain, $this->havingChain);
     foreach ($projections as $clause) {
         $criteria->addProjection($clause->bindAll($this->parameters)->toProjection());
     }
     if ($this->where) {
         if (count($this->where) == 1) {
             $clause = reset($this->where);
             $criteria->add($clause->bindAll($this->parameters)->toLogic());
         } else {
             $logic = Expression::chain();
             foreach ($this->where as $key => $clause) {
                 $expression = $clause->bindAll($this->parameters)->toLogic();
                 if ($this->whereLogic[$key] == BinaryExpression::EXPRESSION_AND) {
                     $logic->expAnd($expression);
                 } else {
                     $logic->expOr($expression);
                 }
             }
             $criteria->add($logic);
         }
     }
     foreach ($this->orderChain as $clause) {
         $criteria->addOrder($clause->bindAll($this->parameters)->toOrder());
     }
     if ($this->limit) {
         $criteria->setLimit($this->limit->evaluate($this->parameters));
     }
     if ($this->offset) {
         $criteria->setOffset($this->offset->evaluate($this->parameters));
     }
     return $criteria;
 }