public function testExplainPlanFromObject() { BookstoreDataPopulator::depopulate($this->con); BookstoreDataPopulator::populate($this->con); $db = Propel::getDb(BookPeer::DATABASE_NAME); $c = new ModelCriteria('bookstore', 'Book'); $c->join('Book.Author'); $c->where('Author.FirstName = ?', 'Neal'); $c->select('Title'); $explain = $c->explain($this->con); if ($db instanceof DBMySQL) { $this->assertEquals(sizeof($explain), 2, 'Explain plan return two lines'); // explain can change sometime, test can't be strict $this->assertArrayHasKey('select_type', $explain[0], 'Line 1, select_type key exist'); $this->assertArrayHasKey('table', $explain[0], 'Line 1, table key exist'); $this->assertArrayHasKey('type', $explain[0], 'Line 1, type key exist'); $this->assertArrayHasKey('possible_keys', $explain[0], 'Line 1, possible_keys key exist'); $this->assertArrayHasKey('select_type', $explain[1], 'Line 2, select_type key exist'); $this->assertArrayHasKey('table', $explain[1], 'Line 2, table key exist'); $this->assertArrayHasKey('type', $explain[1], 'Line 2, type key exist'); $this->assertArrayHasKey('possible_keys', $explain[1], 'Line 2, possible_keys key exist'); } elseif ($db instanceof DBOracle) { $this->assertTrue(sizeof($explain) > 2, 'Explain plan return more than 2 lines'); } else { $this->markTestSkipped('Cannot test explain plan on adapter ' . get_class($db)); } }
public function testGetConsumerByKey() { $consumerKey = 'bar'; $this->query->expects($this->once())->method('filterByConsumerKey')->with($this->equalTo('bar')); $this->query->expects($this->once())->method('findOne'); $this->consumerProvider->getConsumerByKey($consumerKey); }
/** * Produces a union-query from two queries. * * @todo Implement support for ORDER, LIMIT etc. * * @param ModelCriteria $mc1 * @param ModelCriteria $mc2 * @return mixed */ public static function union(ModelCriteria $mc1, ModelCriteria $mc2) { $dbMap = Propel::getDatabaseMap($mc1->getDbName()); $db = Propel::getDB($mc1->getDbName()); $con = Propel::getConnection($mc1->getDbName(), Propel::CONNECTION_READ); // we may modify criteria, so copy it first $c1 = clone $mc1; $c2 = clone $mc2; // check that the columns of the main class are already added (if this is the primary ModelCriteria) if (!$c1->hasSelectClause() && !$c1->getPrimaryCriteria()) { $c1->addSelfSelectColumns(); } if (!$c2->hasSelectClause() && !$c2->getPrimaryCriteria()) { $c2->addSelfSelectColumns(); } $con->beginTransaction(); try { $params = array(); $sql1 = BasePeer::createSelectSql($c1, $params); $sql2 = BasePeer::createSelectSql($c2, $params); $stmt = $con->prepare("({$sql1}) UNION ALL ({$sql2})"); $db->bindValues($stmt, $params, $dbMap); $stmt->execute(); $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } return $c1->getFormatter()->init($c1)->format($stmt); }
public function loadByType(&$model) { $C = new ModelCriteria(); $C->addClause(ModelCriteria::EQUALS, 'type', $model->type); $models = self::select($model->modelName, $C); if (count($models) > 0) { $model = $models[0]; return TRUE; } return FALSE; }
/** * Constructor * * @param \ModelCriteria|string $modelOrQuery A query object, or model class as string. * @param array $options */ public function __construct($modelOrQuery, array $options = array()) { if (is_string($modelOrQuery)) { $this->model = $modelOrQuery; $this->query = \PropelQuery::from($this->model); } else { if ($modelOrQuery instanceof \ModelCriteria) { $this->query = $modelOrQuery; $this->model = $this->query->getModelName(); } else { throw new \Exception('Invalid argument'); } } parent::__construct($options); }
public static function getChartDatasetData(\ModelCriteria $q) { $data = array('raw' => array(), 'daily' => array(), 'weekly' => array(), 'monthly' => array()); $cache = self::getGemCache(); $rates = $q->select(array('rateDatetime', 'rate'))->filterByRateDatetime(date("Y-m-d 00:00:00", strtotime("-1 week")), \Criteria::GREATER_EQUAL)->find(); /* * use these 3 arrays to maintain the values over which we calculate the moving average * every value is added to the array, but we pop off values older then the specified threshold (day, week, month) */ $dailyValues = array(); $weeklyValues = array(); $monthlyValues = array(); foreach ($rates as $rateEntry) { $date = new DateTime("{$rateEntry['rateDatetime']}"); $date->setTimezone(new DateTimeZone('UTC')); $timestamp = $date->getTimestamp(); $dailyValues[$timestamp] = $rateEntry['rate']; $weeklyValues[$timestamp] = $rateEntry['rate']; $monthlyValues[$timestamp] = $rateEntry['rate']; $rateEntry['rate'] = round($rateEntry['rate'], 2); foreach ($dailyValues as $keyTimestamp => $value) { if ($timestamp - $keyTimestamp > 86400) { unset($dailyValues[$keyTimestamp]); } else { break; } } foreach ($weeklyValues as $keyTimestamp => $value) { if ($timestamp - $keyTimestamp > 604800) { unset($weeklyValues[$keyTimestamp]); } else { break; } } foreach ($monthlyValues as $keyTimestamp => $value) { if ($timestamp - $keyTimestamp > 18144000) { unset($monthlyValues[$keyTimestamp]); } else { break; } } $data['raw'][] = array($timestamp * 1000, $rateEntry['rate']); $data['daily'][] = array($timestamp * 1000, round(array_sum($dailyValues) / count($dailyValues), 2)); $data['weekly'][] = array($timestamp * 1000, round(array_sum($weeklyValues) / count($weeklyValues), 2)); $data['monthly'][] = array($timestamp * 1000, round(array_sum($monthlyValues) / count($monthlyValues), 2)); } return $data; }
public function testPreAndPostDelete() { $c = new ModelCriteria('bookstore', 'Book'); $books = $c->find(); $count = count($books); $book = $books->shift(); $this->con->lastAffectedRows = 0; $c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book', 'b'); $c->where('b.Id = ?', $book->getId()); $nbBooks = $c->delete($this->con); $this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after delete() even if preDelete() returns not null'); $this->con->lastAffectedRows = 0; $c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book'); $nbBooks = $c->deleteAll($this->con); $this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll() even if preDelete() returns not null'); }
public function __construct($table, $groupField, $name, $joinCriterion) { parent::__construct(); $this->name = $name; $this->selectTable($table); $this->selectField($groupField, "group_field"); $this->groupBy($groupField); $this->joinCriterion = $joinCriterion; }
/** * Initializes internal state of BasePagePropertyQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'rapila'; } if (null === $modelName) { $modelName = 'PageProperty'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseUcConfigurationQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'cpu'; } if (null === $modelName) { $modelName = 'UcConfiguration'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseGalleryFolderQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'propel'; } if (null === $modelName) { $modelName = 'GalleryFolder'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseJournalEntryImageQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'rapila'; } if (null === $modelName) { $modelName = 'JournalEntryImage'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseGastofacturacionQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'itrade'; } if (null === $modelName) { $modelName = 'Gastofacturacion'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseExpedienteanticipoQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'itrade'; } if (null === $modelName) { $modelName = 'Expedienteanticipo'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseLanguageObjectHistoryQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'rapila'; } if (null === $modelName) { $modelName = 'LanguageObjectHistory'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseServicioestadoQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'itrade'; } if (null === $modelName) { $modelName = 'Servicioestado'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BasePlayerQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'bookingCourtDB'; } if (null === $modelName) { $modelName = 'Player'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseLinkCategoryQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'rapila'; } if (null === $modelName) { $modelName = 'LinkCategory'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseProveedoritradearchivoQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'itrade'; } if (null === $modelName) { $modelName = 'Proveedoritradearchivo'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseCategoryQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'zendshop'; } if (null === $modelName) { $modelName = 'Category'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseDetailTransaksiQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'propel'; } if (null === $modelName) { $modelName = 'DetailTransaksi'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseSearchIndexWordQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'rapila'; } if (null === $modelName) { $modelName = 'SearchIndexWord'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BasehelpHourSigninQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'cscrew'; } if (null === $modelName) { $modelName = 'helpHourSignin'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BasememberProfileQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'cscrew'; } if (null === $modelName) { $modelName = 'memberProfile'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseKategoriQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'propel'; } if (null === $modelName) { $modelName = 'Kategori'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseBookQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'bookstore'; } if (null === $modelName) { $modelName = 'Book'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseUserGroupQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'rapila'; } if (null === $modelName) { $modelName = 'UserGroup'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseUcUserPermissionMatchesQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'cpu'; } if (null === $modelName) { $modelName = 'UcUserPermissionMatches'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseUdmQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'hva'; } if (null === $modelName) { $modelName = 'Udm'; } parent::__construct($dbName, $modelName, $modelAlias); }
/** * Initializes internal state of BaseCategoriagastoQuery object. * * @param string $dbName The dabase name * @param string $modelName The phpName of a model, e.g. 'Book' * @param string $modelAlias The alias for the model in this query, e.g. 'b' */ public function __construct($dbName = null, $modelName = null, $modelAlias = null) { if (null === $dbName) { $dbName = 'itrade'; } if (null === $modelName) { $modelName = 'Categoriagasto'; } parent::__construct($dbName, $modelName, $modelAlias); }