Esempio n. 1
0
 function testComplexChaining()
 {
     $a = new lmbSQLCriteria('a');
     $b = new lmbSQLCriteria('b');
     $c = new lmbSQLCriteria('c');
     $d = new lmbSQLCriteria('d');
     $e = new lmbSQLCriteria('e');
     $g = new lmbSQLCriteria('g');
     $h = new lmbSQLCriteria('h');
     $a->addOr($b->addAnd($c))->addAnd($d->addOr($e)->addAnd($g->addOr($h)));
     $this->assertEqual($a->toStatementString(), 'a OR (b AND c) AND (d OR e AND (g OR h))');
 }
Esempio n. 2
0
 /**
  * @param string $uri
  * @return lmbCmsDocument
  */
 static function findByUri($uri)
 {
     $identifiers = explode('/', rtrim($uri, '/'));
     $criteria = new lmbSQLCriteria('level = 0');
     $level = 0;
     foreach ($identifiers as $identifier) {
         $identifier_criteria = lmbSQLCriteria::equal('identifier', $identifier);
         $identifier_criteria->addAnd(lmbSQLCriteria::equal('level', $level));
         $criteria->addOr($identifier_criteria);
         $level++;
     }
     $documents = lmbActiveRecord::find('lmbCmsDocument', $criteria);
     $parent_id = 0;
     foreach ($identifiers as $identifier) {
         if (!($document = self::_getNodeByParentIdAndIdentifier($documents, $parent_id, $identifier))) {
             return false;
         }
         $parent_id = $document->getId();
     }
     return $document;
 }
 function testFindWithKind()
 {
     $valid_object1 = new BarFooOneTableTestObject();
     $valid_object1->setTitle('title1');
     $valid_object1->save();
     $valid_object2 = new BarFooOneTableTestObject();
     $valid_object2->setTitle('title2');
     $valid_object2->save();
     $wrong_class_object = new FooOneTableTestObject();
     $wrong_class_object->setTitle('title1');
     $wrong_class_object->save();
     $wrong_title_object = new FooOneTableTestObject();
     $wrong_title_object->setTitle('wrong_title');
     $wrong_title_object->save();
     $criteria = new lmbSQLCriteria();
     $criteria->add(lmbSQLCriteria::equal('title', 'title1'));
     $criteria->addOr(lmbSQLCriteria::equal('title', 'title2'));
     $records = lmbActiveRecord::find('BarFooOneTableTestObject', $criteria)->sort(array('id'))->getArray();
     $this->assertEqual(count($records), 2);
     $this->assertEqual($records[0]->title, $valid_object1->title);
     $this->assertEqual($records[1]->title, $valid_object2->title);
 }