/** * @todo fix error (hack) */ function testIsRoot_Positive() { //force tree init $node = $this->_createDocument('root', $parent_node = null); $root = lmbActiveRecord::findOne('lmbCmsDocument', array('sort' => 'id')); $this->assertTrue($root->isRoot()); }
static function findRoot($class_name = '') { if (!$class_name) { $class_name = self::_getCallingClass(); } return lmbActiveRecord::findOne($class_name, lmbSQLCriteria::equal('parent_id', 0)); }
function check($value) { $criteria = lmbSQLCriteria::equal($this->field_name, $value)->addAnd('parent_id = ' . ($this->parent_id ? $this->parent_id : $this->node->getParent()->getId())); if (!$this->node->isNew()) { $criteria->addAnd('id <> ' . $this->node->getId()); } if (lmbActiveRecord::findOne(get_class($this->node), $criteria)) { $this->error($this->error_message); } }
function check($value) { $criteria = new lmbSQLFieldCriteria($this->field_name, $value); if ($this->text_block->getId()) { $criteria->addAnd('id <> ' . $this->text_block->getId()); } if (lmbActiveRecord::findOne('lmbCmsTextBlock', $criteria)) { $this->error('Тектовый блок со значением поля {Field} уже существует'); } }
function check($value) { $criteria = new lmbSQLFieldCriteria($this->field_name, $value); if (!$this->user->isNew()) { $criteria->addAnd('id <> ' . $this->user->getId()); } if (lmbActiveRecord::findOne('lmbCmsUser', $criteria)) { $this->error('Пользователь со значением поля {Field} уже существует'); } }
static function findOneByIdentifier($identifier) { if ($block = lmbActiveRecord::findOne('lmbCmsTextBlock', lmbSQLCriteria::equal('identifier', $identifier))) { return $block; } if (!($default_content = lmbToolkit::instance()->getConf('text_blocks')->get($identifier))) { return null; } $block = new lmbCmsTextBlock(); $block->import($default_content); $block->setIdentifier($identifier); return $block; }
function testLazyWorksOkForEagerAttach_OneToOneRelations() { $person = new PersonForLazyAttributesTest(); $person->setName('Some name'); $lazy_object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content'); $person->set('lazy_object', $lazy_object); $person->save(); $person_loaded = lmbActiveRecord::findOne('PersonForLazyAttributesTest', array('criteria' => 'person_for_test.id = ' . $person->getId(), 'attach' => 'lazy_object')); $lazy_object2 = $person_loaded->getLazyObject(); $this->_checkLazyness($lazy_object2, $annotation, $content); }
function testFindOneAlias() { $object1 = $this->creator->createOneTableObject(); $object2 = $this->creator->createOneTableObject(); $this->assertFalse($object2->isNew()); $found = lmbActiveRecord::findOne('TestOneTableObject', lmbActiveRecord::getDefaultConnection()->quoteIdentifier("id") . '=' . $object1->getId()); $this->assertEqual($found->get('annotation'), $object1->get('annotation')); $this->assertEqual($found->get('content'), $object1->get('content')); $this->assertEqual($found->get('news_date'), $object1->get('news_date')); $this->assertEqual($found->get('id'), $object1->getId()); //testing convenient alias $found = TestOneTableObject::findOne(lmbActiveRecord::getDefaultConnection()->quoteIdentifier("id") . '=' . $object1->getId()); $this->assertEqual($found->get('annotation'), $object1->get('annotation')); $this->assertEqual($found->get('content'), $object1->get('content')); $this->assertEqual($found->get('news_date'), $object1->get('news_date')); $this->assertEqual($found->get('id'), $object1->getId()); }