public function testWithObjects() { $criteria = Criteria::create(TestUser::dao())->add(Expression::containsIp(IpRange::create('192.168.1.1-192.168.1.255'), 'ip'))->addProjection(Projection::property('id')); $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_user"."id" FROM "test_user" WHERE "test_user"."ip" <<= \'192.168.1.1-192.168.1.255\''); $criteria = Criteria::create(TestInternetProvider::dao())->add(Expression::containsIp('range', IpAddress::create('42.42.42.42')))->addProjection(Projection::property('id')); $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_internet_provider"."id" FROM "test_internet_provider" WHERE \'42.42.42.42\' <<= "test_internet_provider"."range"'); }
/** * @return ProjectionChain **/ public function toProjection() { $projection = Projection::chain(); foreach ($this->list as $property) { $projection->add($property->evaluate($this->parameters)); } return $projection; }
public function testLazy() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $parent = TestParentObject::create(); $child = TestChildObject::create()->setParent($parent); $parent->dao()->add($parent); $child->dao()->add($child); $this->assertEquals($parent->getId(), Criteria::create(TestChildObject::dao())->setProjection(Projection::property('parent.id', 'parentId'))->add(Expression::eq('id', $child->getId()))->getCustom('parentId')); } }
function getCount() { if ($this->isFetched()) { return parent::getCount(); } $query = clone $this->getQuery(); $alias = get_class($this) . '_counter'; $query->get(Projection::count($this->getChildren()->getLogicalSchema()->getIdentifier(), $alias)); $sqlQuery = $this->makeSqlSelectQuery($query); $result = $this->getChildren()->getDao()->getRow($sqlQuery); $this->count = (int) $result[$alias]; return $this->count; }
public function testIpRangeProperty() { foreach (DBTestPool::me()->getPool() as $db) { DBPool::me()->setDefault($db); $akado = TestInternetProvider::create()->setName('Akada')->setRange(IpRange::create(IpAddress::create('192.168.1.1'), IpAddress::create('192.168.1.42'))); TestInternetProvider::dao()->add($akado); $plainRange = Criteria::create(TestInternetProvider::dao())->addProjection(Projection::property('range'))->add(Expression::eq('name', 'Akada'))->getCustom(); $this->assertEquals($plainRange['range'], '192.168.1.1-192.168.1.42'); TestInternetProvider::dao()->add(TestInternetProvider::create()->setName('DomRu')->setRange(IpRange::create('192.168.2.0/24'))); $list = Criteria::create(TestInternetProvider::dao())->addOrder('id')->getList(); $this->assertEquals(count($list), 2); } }
public function testForgottenDao() { $criteria = Criteria::create()->add(Expression::eq('id', 42)); $listCriteria = clone $criteria; try { $listCriteria->getList(); $this->fail(); } catch (WrongStateException $e) { /*it's good*/ } $customCriteria = clone $criteria; try { $customCriteria->addProjection(Projection::property('id'))->getCustomList(); $this->fail(); } catch (WrongStateException $e) { /*it's good*/ } }
/** * @param array $input * @return Projection */ protected function createProj($input, $block = true) { $proj = new Projection($input); $proj->setBlock($block); return $proj; }
/** * Gets the value of the entity's property. The value is obtained according to the current * setting of EntityQuery and the FetchStrategy set inside DAO of the entity * @param string name of the property * @return scalar */ function getProperty($property) { return $this->entity->getDao()->getProperty($this->makeSelect(Projection::property($property))); }
public function testQuery() { $criteria = Criteria::create(TestUser::dao())->setProjection(Projection::property('id'))->add(Expression::isTrue('id')); $this->assertCriteria('id from TestUser where id is true', $criteria)->assertCriteria('id from TestUser where id is true order by id asc', $criteria->addOrder(OrderBy::create('id')->asc()))->assertCriteria('id from TestUser where id is true order by id asc limit 10 offset 1', $criteria->setLimit(10)->setOffset(1))->assertCriteria('id from TestUser where id is true group by id order by id asc limit 10 offset 1', $criteria->setProjection(Projection::chain()->add(Projection::property('id'))->add(Projection::group('id'))))->assertCriteria('id from TestUser where id is true group by id order by id asc having id = 1 limit 10 offset 1', $criteria->setProjection(Projection::chain()->add(Projection::property('id'))->add(Projection::group('id'))->add(Projection::having(Expression::eq('id', 1)))))->assertCriteria('count(id) as count from TestUser group by id having count = 2', Criteria::create(TestUser::dao())->setProjection(Projection::chain()->add(Projection::count('id', 'count'))->add(Projection::group('id'))->add(Projection::having(Expression::eq('count', 2))))); }
public function testHaving() { $query = OQL::select('from TestUser'); $criteria = Criteria::create(TestUser::dao()); $this->assertCriteria($query->addHaving(OQL::having('id > 0')), $criteria->addProjection(Projection::having(Expression::gt('id', 0)))); $this->assertCriteria($query->addHaving(OQL::having('name is not null and (id <> $1 or id != $2)')->bindNext(4)->bindNext(8)), $criteria->addProjection(Projection::having(Expression::expAnd(Expression::notNull('name'), Expression::expOr(Expression::notEq('id', 4), Expression::notEq('id', 8)))))); $this->assertEquals(OQL::having('id + $15')->bind(15, 16)->toProjection(), Projection::having(Expression::add('id', 16))); $this->assertCriteria(OQL::select('from TestUser')->addHaving(OQL::having('id = $1')->bindNext(23))->bindNext(42), Criteria::create(TestUser::dao())->addProjection(Projection::having(Expression::eq('id', 42)))); }
/** * @return Criteria **/ public function dropProjection() { $this->projection = Projection::chain(); return $this; }
return false; } $prjCfg = $_SESSION['pluginsConfig']['coordinates']; $mapPrj = $prjCfg['mapPrj']; $mapPrjName = _p($mapPrj['name']); $showX = round($clickX, $mapPrj['roundTo']); $showY = round($clickY, $mapPrj['roundTo']); $prjJson = "["; $prjJson .= "{\"prjName\": \"{$mapPrjName}\", \"x\": {$showX}, \"y\": {$showY}},"; $prjList = $prjCfg['prj']; $prjTmp = array(); foreach ($prjList as $p) { $prjName = _p($p['name']); $roundTo = $p['roundTo']; $toPrj = $p['definition']; $prj = new Projection($clickX, $clickY, $fromPrj, $toPrj); $x = $prj->getX(); $y = $prj->getY(); //round values $x = round($x, $roundTo); $y = round($y, $roundTo); $prjTmp[] = "{\"prjName\": \"{$prjName}\", \"x\": {$x}, \"y\": {$y}}"; } $mapPrjName = _p($mapPrjName); $prjTmpStr = implode(',', $prjTmp); if (!$prjTmpStr) { $prjTmpStr = '[]'; } $prjJson .= " {$prjTmpStr}]"; header("Content-Type: text/plain; charset={$defCharset}"); // return JS object literals "{}" for XMLHTTP request
function getPropertyList($property, ISqlSelectQuery $query = null) { $property = $this->logicalSchema->getProperty($property); $type = $property->getType(); if (!$query) { $query = EntityQuery::create($this->entity)->get(Projection::property($property)); } $rows = $this->getRows($query); $propertySet = $type->assebmleSet($rows, $this->getFetchStrategy()); return $propertySet; }
/** * @dataProvider pixelToDegreesRangeExceptionProvider * @expectedException \RangeException */ public function testPixelsToDegreesRangeException($pixelX, $pixelY, $width, $height) { self::$projection->pixelsToDegrees($pixelX, $pixelY, $width, $height); }