CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,543 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* This is an "inner" class that describes an object in the criteria.
*
* In Torque this is an inner class of the Criteria class.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @version $Revision: 1740 $
* @package propel.runtime.query
*/
class Criterion
{
const UND = " AND ";
const ODER = " OR ";
/** Value of the CO. */
protected $value;
/** Comparison value.
* @var SqlEnum
*/
protected $comparison;
/** Table name. */
protected $table;
/** Real table name */
protected $realtable;
/** Column name. */
protected $column;
/** flag to ignore case in comparison */
protected $ignoreStringCase = false;
/**
* The DBAdaptor which might be used to get db specific
* variations of sql.
*/
protected $db;
/**
* other connected criteria and their conjunctions.
*/
protected $clauses = array();
protected $conjunctions = array();
/** "Parent" Criteria class */
protected $parent;
/**
* Create a new instance.
*
* @param Criteria $parent The outer class (this is an "inner" class).
* @param string $column TABLE.COLUMN format.
* @param mixed $value
* @param string $comparison
*/
public function __construct(Criteria $outer, $column, $value, $comparison = null)
{
$this->value = $value;
$dotPos = strrpos($column, '.');
if ($dotPos === false) {
// no dot => aliased column
$this->table = null;
$this->column = $column;
} else {
$this->table = substr($column, 0, $dotPos);
$this->column = substr($column, $dotPos + 1);
}
$this->comparison = ($comparison === null) ? Criteria::EQUAL : $comparison;
$this->init($outer);
}
/**
* Init some properties with the help of outer class
* @param Criteria $criteria The outer class
*/
public function init(Criteria $criteria)
{
// init $this->db
try {
$db = Propel::getDB($criteria->getDbName());
$this->setDB($db);
} catch (Exception $e) {
// we are only doing this to allow easier debugging, so
// no need to throw up the exception, just make note of it.
Propel::log("Could not get a DBAdapter, sql may be wrong", Propel::LOG_ERR);
}
// init $this->realtable
$realtable = $criteria->getTableForAlias($this->table);
$this->realtable = $realtable ? $realtable : $this->table;
}
/**
* Get the column name.
*
* @return string A String with the column name.
*/
public function getColumn()
{
return $this->column;
}
/**
* Set the table name.
*
* @param name A String with the table name.
* @return void
*/
public function setTable($name)
{
$this->table = $name;
}
/**
* Get the table name.
*
* @return string A String with the table name.
*/
public function getTable()
{
return $this->table;
}
/**
* Get the comparison.
*
* @return string A String with the comparison.
*/
public function getComparison()
{
return $this->comparison;
}
/**
* Get the value.
*
* @return mixed An Object with the value.
*/
public function getValue()
{
return $this->value;
}
/**
* Get the value of db.
* The DBAdapter which might be used to get db specific
* variations of sql.
* @return DBAdapter value of db.
*/
public function getDB()
{
return $this->db;
}
/**
* Set the value of db.
* The DBAdapter might be used to get db specific variations of sql.
* @param DBAdapter $v Value to assign to db.
* @return void
*/
public function setDB(DBAdapter $v)
{
$this->db = $v;
foreach ( $this->clauses as $clause ) {
$clause->setDB($v);
}
}
/**
* Sets ignore case.
*
* @param boolean $b True if case should be ignored.
* @return Criterion A modified Criterion object.
*/
public function setIgnoreCase($b)
{
$this->ignoreStringCase = (boolean) $b;
return $this;
}
/**
* Is ignore case on or off?
*
* @return boolean True if case is ignored.
*/
public function isIgnoreCase()
{
return $this->ignoreStringCase;
}
/**
* Get the list of clauses in this Criterion.
* @return array
*/
private function getClauses()
{
return $this->clauses;
}
/**
* Get the list of conjunctions in this Criterion
* @return array
*/
public function getConjunctions()
{
return $this->conjunctions;
}
/**
* Append an AND Criterion onto this Criterion's list.
*/
public function addAnd(Criterion $criterion)
{
$this->clauses[] = $criterion;
$this->conjunctions[] = self::UND;
return $this;
}
/**
* Append an OR Criterion onto this Criterion's list.
* @return Criterion
*/
public function addOr(Criterion $criterion)
{
$this->clauses[] = $criterion;
$this->conjunctions[] = self::ODER;
return $this;
}
/**
* Appends a Prepared Statement representation of the Criterion
* onto the buffer.
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
* @return void
* @throws PropelException - if the expression builder cannot figure out how to turn a specified
* expression into proper SQL.
*/
public function appendPsTo(&$sb, array &$params)
{
$sb .= str_repeat ( '(', count($this->clauses) );
$this->dispatchPsHandling($sb, $params);
foreach ($this->clauses as $key => $clause) {
$sb .= $this->conjunctions[$key];
$clause->appendPsTo($sb, $params);
$sb .= ')';
}
}
/**
* Figure out which Criterion method to use
* to build the prepared statement and parameters using to the Criterion comparison
* and call it to append the prepared statement and the parameters of the current clause
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
protected function dispatchPsHandling(&$sb, array &$params)
{
switch ($this->comparison) {
case Criteria::CUSTOM:
// custom expression with no parameter binding
$this->appendCustomToPs($sb, $params);
break;
case Criteria::IN:
case Criteria::NOT_IN:
// table.column IN (?, ?) or table.column NOT IN (?, ?)
$this->appendInToPs($sb, $params);
break;
case Criteria::LIKE:
case Criteria::NOT_LIKE:
case Criteria::ILIKE:
case Criteria::NOT_ILIKE:
// table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres)
$this->appendLikeToPs($sb, $params);
break;
default:
// table.column = ? or table.column >= ? etc. (traditional expressions, the default)
$this->appendBasicToPs($sb, $params);
}
}
/**
* Appends a Prepared Statement representation of the Criterion onto the buffer
* For custom expressions with no binding, e.g. 'NOW() = 1'
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
protected function appendCustomToPs(&$sb, array &$params)
{
if ($this->value !== "") {
$sb .= (string) $this->value;
}
}
/**
* Appends a Prepared Statement representation of the Criterion onto the buffer
* For IN expressions, e.g. table.column IN (?, ?) or table.column NOT IN (?, ?)
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
protected function appendInToPs(&$sb, array &$params)
{
if ($this->value !== "") {
$bindParams = array();
$index = count($params); // to avoid counting the number of parameters for each element in the array
foreach ((array) $this->value as $value) {
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$index++; // increment this first to correct for wanting bind params to start with :p1
$bindParams[] = ':p' . $index;
}
if (count($bindParams)) {
$field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column;
$sb .= $field . $this->comparison . '(' . implode(',', $bindParams) . ')';
} else {
$sb .= ($this->comparison === Criteria::IN) ? "1<>1" : "1=1";
}
}
}
/**
* Appends a Prepared Statement representation of the Criterion onto the buffer
* For LIKE expressions, e.g. table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres)
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
protected function appendLikeToPs(&$sb, array &$params)
{
$field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column;
$db = $this->getDb();
// If selection is case insensitive use ILIKE for PostgreSQL or SQL
// UPPER() function on column name for other databases.
if ($this->ignoreStringCase) {
if ($db instanceof DBPostgres) {
if ($this->comparison === Criteria::LIKE) {
$this->comparison = Criteria::ILIKE;
} elseif ($this->comparison === Criteria::NOT_LIKE) {
$this->comparison = Criteria::NOT_ILIKE;
}
} else {
$field = $db->ignoreCase($field);
}
}
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value);
$sb .= $field . $this->comparison;
// If selection is case insensitive use SQL UPPER() function
// on criteria or, if Postgres we are using ILIKE, so not necessary.
if ($this->ignoreStringCase && !($db instanceof DBPostgres)) {
$sb .= $db->ignoreCase(':p'.count($params));
} else {
$sb .= ':p'.count($params);
}
}
/**
* Appends a Prepared Statement representation of the Criterion onto the buffer
* For traditional expressions, e.g. table.column = ? or table.column >= ? etc.
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
protected function appendBasicToPs(&$sb, array &$params)
{
$field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column;
// NULL VALUES need special treatment because the SQL syntax is different
// i.e. table.column IS NULL rather than table.column = null
if ($this->value !== null) {
// ANSI SQL functions get inserted right into SQL (not escaped, etc.)
if ($this->value === Criteria::CURRENT_DATE || $this->value === Criteria::CURRENT_TIME || $this->value === Criteria::CURRENT_TIMESTAMP) {
$sb .= $field . $this->comparison . $this->value;
} else {
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value);
// default case, it is a normal col = value expression; value
// will be replaced w/ '?' and will be inserted later using PDO bindValue()
if ($this->ignoreStringCase) {
$sb .= $this->getDb()->ignoreCase($field) . $this->comparison . $this->getDb()->ignoreCase(':p'.count($params));
} else {
$sb .= $field . $this->comparison . ':p'.count($params);
}
}
} else {
// value is null, which means it was either not specified or specifically
// set to null.
if ($this->comparison === Criteria::EQUAL || $this->comparison === Criteria::ISNULL) {
$sb .= $field . Criteria::ISNULL;
} elseif ($this->comparison === Criteria::NOT_EQUAL || $this->comparison === Criteria::ISNOTNULL) {
$sb .= $field . Criteria::ISNOTNULL;
} else {
// for now throw an exception, because not sure how to interpret this
throw new PropelException("Could not build SQL for expression: $field " . $this->comparison . " NULL");
}
}
}
/**
* This method checks another Criteria to see if they contain
* the same attributes and hashtable entries.
* @return boolean
*/
public function equals($obj)
{
// TODO: optimize me with early outs
if ($this === $obj) {
return true;
}
if (($obj === null) || !($obj instanceof Criterion)) {
return false;
}
$crit = $obj;
$isEquiv = ( ( ($this->table === null && $crit->getTable() === null)
|| ( $this->table !== null && $this->table === $crit->getTable() )
)
&& $this->column === $crit->getColumn()
&& $this->comparison === $crit->getComparison());
// check chained criterion
$clausesLength = count($this->clauses);
$isEquiv &= (count($crit->getClauses()) == $clausesLength);
$critConjunctions = $crit->getConjunctions();
$critClauses = $crit->getClauses();
for ($i=0; $i < $clausesLength && $isEquiv; $i++) {
$isEquiv &= ($this->conjunctions[$i] === $critConjunctions[$i]);
$isEquiv &= ($this->clauses[$i] === $critClauses[$i]);
}
if ($isEquiv) {
$isEquiv &= $this->value === $crit->getValue();
}
return $isEquiv;
}
/**
* Returns a hash code value for the object.
*/
public function hashCode()
{
$h = crc32(serialize($this->value)) ^ crc32($this->comparison);
if ($this->table !== null) {
$h ^= crc32($this->table);
}
if ($this->column !== null) {
$h ^= crc32($this->column);
}
foreach ( $this->clauses as $clause ) {
// TODO: i KNOW there is a php incompatibility with the following line
// but i dont remember what it is, someone care to look it up and
// replace it if it doesnt bother us?
// $clause->appendPsTo($sb='',$params=array());
$sb = '';
$params = array();
$clause->appendPsTo($sb,$params);
$h ^= crc32(serialize(array($sb,$params)));
unset ( $sb, $params );
}
return $h;
}
/**
* Get all tables from nested criterion objects
* @return array
*/
public function getAllTables()
{
$tables = array();
$this->addCriterionTable($this, $tables);
return $tables;
}
/**
* method supporting recursion through all criterions to give
* us a string array of tables from each criterion
* @return void
*/
private function addCriterionTable(Criterion $c, array &$s)
{
$s[] = $c->getTable();
foreach ( $c->getClauses() as $clause ) {
$this->addCriterionTable($clause, $s);
}
}
/**
* get an array of all criterion attached to this
* recursing through all sub criterion
* @return array Criterion[]
*/
public function getAttachedCriterion()
{
$criterions = array($this);
foreach ($this->getClauses() as $criterion) {
$criterions = array_merge($criterions, $criterion->getAttachedCriterion());
}
return $criterions;
}
/**
* Ensures deep cloning of attached objects
*/
public function __clone()
{
foreach ($this->clauses as $key => $criterion) {
$this->clauses[$key] = clone $criterion;
}
}
}

View file

@ -0,0 +1,54 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Class that implements SPL Iterator interface. This allows foreach () to
* be used w/ Criteria objects. Probably there is no performance advantage
* to doing it this way, but it makes sense -- and simpler code.
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 1612 $
* @package propel.runtime.query
*/
class CriterionIterator implements Iterator
{
private $idx = 0;
private $criteria;
private $criteriaKeys;
private $criteriaSize;
public function __construct(Criteria $criteria) {
$this->criteria = $criteria;
$this->criteriaKeys = $criteria->keys();
$this->criteriaSize = count($this->criteriaKeys);
}
public function rewind() {
$this->idx = 0;
}
public function valid() {
return $this->idx < $this->criteriaSize;
}
public function key() {
return $this->criteriaKeys[$this->idx];
}
public function current() {
return $this->criteria->getCriterion($this->criteriaKeys[$this->idx]);
}
public function next() {
$this->idx++;
}
}

View file

@ -0,0 +1,250 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Data object to describe a join between two tables, for example
* <pre>
* table_a LEFT JOIN table_b ON table_a.id = table_b.a_id
* </pre>
*
* @author Francois Zaninotto (Propel)
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Kaspars Jaudzems <kaspars.jaudzems@inbox.lv> (Propel)
* @author Frank Y. Kim <frank.kim@clearink.com> (Torque)
* @author John D. McNally <jmcnally@collab.net> (Torque)
* @author Brett McLaughlin <bmclaugh@algx.net> (Torque)
* @author Eric Dobbs <eric@dobbse.net> (Torque)
* @author Henning P. Schmiedehausen <hps@intermeta.de> (Torque)
* @author Sam Joseph <sam@neurogrid.com> (Torque)
* @package propel.runtime.query
*/
class Join
{
// default comparison type
const EQUAL = "=";
// the left parts of the join condition
protected $left = array();
// the right parts of the join condition
protected $right = array();
// the comparison operators for each pair of columns in the join condition
protected $operator = array();
// the type of the join (LEFT JOIN, ...), or null for an implicit join
protected $joinType = null;
// the number of conditions in the join
protected $count = 0;
/**
* Constructor
* Use it preferably with no arguments, and then use addCondition() and setJoinType()
* Syntax with arguments used mainly for backwards compatibility
*
* @param string $leftColumn The left column of the join condition
* (may contain an alias name)
* @param string $rightColumn The right column of the join condition
* (may contain an alias name)
* @param string $joinType The type of the join. Valid join types are null (implicit join),
* Criteria::LEFT_JOIN, Criteria::RIGHT_JOIN, and Criteria::INNER_JOIN
*/
public function __construct($leftColumn = null, $rightColumn = null, $joinType = null)
{
if(!is_null($leftColumn)) {
if (!is_array($leftColumn)) {
// simple join
$this->addCondition($leftColumn, $rightColumn);
} else {
// join with multiple conditions
if (count($leftColumn) != count($rightColumn) ) {
throw new PropelException("Unable to create join because the left column count isn't equal to the right column count");
}
foreach ($leftColumn as $key => $value)
{
$this->addCondition($value, $rightColumn[$key]);
}
}
$this->setJoinType($joinType);
}
}
/**
* Join condition definition
*
* @param string $left The left column of the join condition
* (may contain an alias name)
* @param string $right The right column of the join condition
* (may contain an alias name)
* @param string $operator The comparison operator of the join condition, default Join::EQUAL
*/
public function addCondition($left, $right, $operator = self::EQUAL)
{
$this->left[] = $left;
$this->right[] = $right;
$this->operator[] = $operator;
$this->count++;
}
/**
* Retrieve the number of conditions in the join
*
* @return integer The number of conditions in the join
*/
public function countConditions()
{
return $this->count;
}
/**
* Return an array of the join conditions
*
* @return array An array of arrays representing (left, comparison, right) for each condition
*/
public function getConditions()
{
$conditions = array();
for ($i=0; $i < $this->count; $i++) {
$conditions[] = array(
'left' => $this->getLeftColumn($i),
'operator' => $this->getOperator($i),
'right' => $this->getRightColumn($i)
);
}
return $conditions;
}
/**
* @return the comparison operator for the join condition
*/
public function getOperator($index = 0)
{
return $this->operator[$index];
}
public function getOperators()
{
return $this->operator;
}
/**
* Set the join type
*
* @param string $joinType The type of the join. Valid join types are
* null (adding the join condition to the where clause),
* Criteria::LEFT_JOIN(), Criteria::RIGHT_JOIN(), and Criteria::INNER_JOIN()
*/
public function setJoinType($joinType = null)
{
$this->joinType = $joinType;
}
/**
* Get the join type
*
* @return string The type of the join, i.e. Criteria::LEFT_JOIN(), ...,
* or null for adding the join condition to the where Clause
*/
public function getJoinType()
{
return $this->joinType;
}
/**
* @return the left column of the join condition
*/
public function getLeftColumn($index = 0)
{
return $this->left[$index];
}
/**
* @return all right columns of the join condition
*/
public function getLeftColumns()
{
return $this->left;
}
public function getLeftColumnName($index = 0)
{
return substr($this->left[$index], strrpos($this->left[$index], '.') + 1);
}
public function getLeftTableName($index = 0)
{
return substr($this->left[$index], 0, strrpos($this->left[$index], '.'));
}
/**
* @return the right column of the join condition
*/
public function getRightColumn($index = 0)
{
return $this->right[$index];
}
/**
* @return all right columns of the join condition
*/
public function getRightColumns()
{
return $this->right;
}
public function getRightColumnName($index = 0)
{
return substr($this->right[$index], strrpos($this->right[$index], '.') + 1);
}
public function getRightTableName($index = 0)
{
return substr($this->right[$index], 0, strrpos($this->right[$index], '.'));
}
public function equals($join)
{
return $join !== null
&& $join instanceof Join
&& $this->joinType == $join->getJoinType()
&& $this->getConditions() == $join->getConditions();
}
/**
* returns a String representation of the class,
* mainly for debugging purposes
*
* @return string A String representation of the class
*/
public function toString()
{
$result = '';
if ($this->joinType !== null) {
$result .= $this->joinType . ' : ';
}
foreach ($this->getConditions() as $index => $condition) {
$result .= implode($condition);
if ($index + 1 < $this->count) {
$result .= ' AND ';
}
}
$result .= '(ignoreCase not considered)';
return $result;
}
public function __toString()
{
return $this->toString();
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,283 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* This is an "inner" class that describes an object in the criteria.
*
* @author Francois
* @version $Revision: 1630 $
* @package propel.runtime.query
*/
class ModelCriterion extends Criterion
{
protected $clause = '';
/**
* Create a new instance.
*
* @param Criteria $parent The outer class (this is an "inner" class).
* @param ColumnMap $column A Column object to help escaping the value
* @param mixed $value
* @param string $comparison, among ModelCriteria::MODEL_CLAUSE
* @param string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
*/
public function __construct(Criteria $outer, $column, $value = null, $comparison = ModelCriteria::MODEL_CLAUSE, $clause)
{
$this->value = $value;
if ($column instanceof ColumnMap) {
$this->column = $column->getName();
$this->table = $column->getTable()->getName();
} else {
$dotPos = strrpos($column,'.');
if ($dotPos === false) {
// no dot => aliased column
$this->table = null;
$this->column = $column;
} else {
$this->table = substr($column, 0, $dotPos);
$this->column = substr($column, $dotPos+1, strlen($column));
}
}
$this->comparison = ($comparison === null ? Criteria::EQUAL : $comparison);
$this->clause = $clause;
$this->init($outer);
}
public function getClause()
{
return $this->clause;
}
/**
* Figure out which MocelCriterion method to use
* to build the prepared statement and parameters using to the Criterion comparison
* and call it to append the prepared statement and the parameters of the current clause.
* For performance reasons, this method tests the cases of parent::dispatchPsHandling()
* first, and that is not possible through inheritance ; that's why the parent
* code is duplicated here.
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
protected function dispatchPsHandling(&$sb, array &$params)
{
switch ($this->comparison) {
case Criteria::CUSTOM:
// custom expression with no parameter binding
$this->appendCustomToPs($sb, $params);
break;
case Criteria::IN:
case Criteria::NOT_IN:
// table.column IN (?, ?) or table.column NOT IN (?, ?)
$this->appendInToPs($sb, $params);
break;
case Criteria::LIKE:
case Criteria::NOT_LIKE:
case Criteria::ILIKE:
case Criteria::NOT_ILIKE:
// table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres)
$this->appendLikeToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE:
// regular model clause, e.g. 'book.TITLE = ?'
$this->appendModelClauseToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_LIKE:
// regular model clause, e.g. 'book.TITLE = ?'
$this->appendModelClauseLikeToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_SEVERAL:
// Ternary model clause, e.G 'book.ID BETWEEN ? AND ?'
$this->appendModelClauseSeveralToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_ARRAY:
// IN or NOT IN model clause, e.g. 'book.TITLE NOT IN ?'
$this->appendModelClauseArrayToPs($sb, $params);
break;
default:
// table.column = ? or table.column >= ? etc. (traditional expressions, the default)
$this->appendBasicToPs($sb, $params);
}
}
/**
* Appends a Prepared Statement representation of the ModelCriterion onto the buffer
* For regular model clauses, e.g. 'book.TITLE = ?'
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
public function appendModelClauseToPs(&$sb, array &$params)
{
if ($this->value !== null) {
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value);
$sb .= str_replace('?', ':p'.count($params), $this->clause);
} else {
$sb .= $this->clause;
}
}
/**
* Appends a Prepared Statement representation of the ModelCriterion onto the buffer
* For LIKE model clauses, e.g. 'book.TITLE LIKE ?'
* Handles case insensitivity for VARCHAR columns
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
public function appendModelClauseLikeToPs(&$sb, array &$params)
{
// LIKE is case insensitive in mySQL and SQLite, but not in PostGres
// If the column is case insensitive, use ILIKE / NOT ILIKE instead of LIKE / NOT LIKE
if ($this->ignoreStringCase && $this->getDb() instanceof DBPostgres) {
$this->clause = preg_replace('/LIKE \?$/i', 'ILIKE ?', $this->clause);
}
$this->appendModelClauseToPs($sb, $params);
}
/**
* Appends a Prepared Statement representation of the ModelCriterion onto the buffer
* For ternary model clauses, e.G 'book.ID BETWEEN ? AND ?'
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
public function appendModelClauseSeveralToPs(&$sb, array &$params)
{
$clause = $this->clause;
foreach ((array) $this->value as $value) {
if ($value === null) {
// FIXME we eventually need to translate a BETWEEN to
// something like WHERE (col < :p1 OR :p1 IS NULL) AND (col < :p2 OR :p2 IS NULL)
// in order to support null values
throw new PropelException('Null values are not supported inside BETWEEN clauses');
}
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$clause = self::strReplaceOnce('?', ':p'.count($params), $clause);
}
$sb .= $clause;
}
/**
* Appends a Prepared Statement representation of the ModelCriterion onto the buffer
* For IN or NOT IN model clauses, e.g. 'book.TITLE NOT IN ?'
*
* @param string &$sb The string that will receive the Prepared Statement
* @param array $params A list to which Prepared Statement parameters will be appended
*/
public function appendModelClauseArrayToPs(&$sb, array &$params)
{
$_bindParams = array(); // the param names used in query building
$_idxstart = count($params);
$valuesLength = 0;
foreach ( (array) $this->value as $value ) {
$valuesLength++; // increment this first to correct for wanting bind params to start with :p1
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$_bindParams[] = ':p'.($_idxstart + $valuesLength);
}
if ($valuesLength !== 0) {
$sb .= str_replace('?', '(' . implode(',', $_bindParams) . ')', $this->clause);
} else {
$sb .= (stripos($this->clause, ' NOT IN ') === false) ? "1<>1" : "1=1";
}
unset ( $value, $valuesLength );
}
/**
* This method checks another Criteria to see if they contain
* the same attributes and hashtable entries.
* @return boolean
*/
public function equals($obj)
{
// TODO: optimize me with early outs
if ($this === $obj) {
return true;
}
if (($obj === null) || !($obj instanceof ModelCriterion)) {
return false;
}
$crit = $obj;
$isEquiv = ( ( ($this->table === null && $crit->getTable() === null)
|| ( $this->table !== null && $this->table === $crit->getTable() )
)
&& $this->clause === $crit->getClause()
&& $this->column === $crit->getColumn()
&& $this->comparison === $crit->getComparison());
// check chained criterion
$clausesLength = count($this->clauses);
$isEquiv &= (count($crit->getClauses()) == $clausesLength);
$critConjunctions = $crit->getConjunctions();
$critClauses = $crit->getClauses();
for ($i=0; $i < $clausesLength && $isEquiv; $i++) {
$isEquiv &= ($this->conjunctions[$i] === $critConjunctions[$i]);
$isEquiv &= ($this->clauses[$i] === $critClauses[$i]);
}
if ($isEquiv) {
$isEquiv &= $this->value === $crit->getValue();
}
return $isEquiv;
}
/**
* Returns a hash code value for the object.
*/
public function hashCode()
{
$h = crc32(serialize($this->value)) ^ crc32($this->comparison) ^ crc32($this->clause);
if ($this->table !== null) {
$h ^= crc32($this->table);
}
if ($this->column !== null) {
$h ^= crc32($this->column);
}
foreach ( $this->clauses as $clause ) {
// TODO: i KNOW there is a php incompatibility with the following line
// but i dont remember what it is, someone care to look it up and
// replace it if it doesnt bother us?
// $clause->appendPsTo($sb='',$params=array());
$sb = '';
$params = array();
$clause->appendPsTo($sb,$params);
$h ^= crc32(serialize(array($sb,$params)));
unset ( $sb, $params );
}
return $h;
}
/**
* Replace only once
* taken from http://www.php.net/manual/en/function.str-replace.php
*
*/
protected static function strReplaceOnce($search, $replace, $subject)
{
$firstChar = strpos($subject, $search);
if($firstChar !== false) {
$beforeStr = substr($subject,0,$firstChar);
$afterStr = substr($subject, $firstChar + strlen($search));
return $beforeStr.$replace.$afterStr;
} else {
return $subject;
}
}
}

View file

@ -0,0 +1,166 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* A ModelJoin is a Join object tied to a RelationMap object
*
* @author Francois Zaninotto (Propel)
* @package propel.runtime.query
*/
class ModelJoin extends Join
{
protected $relationMap;
protected $tableMap;
protected $leftTableAlias;
protected $relationAlias;
protected $previousJoin;
public function setRelationMap(RelationMap $relationMap, $leftTableAlias = null, $relationAlias = null)
{
$leftCols = $relationMap->getLeftColumns();
$rightCols = $relationMap->getRightColumns();
$nbColumns = $relationMap->countColumnMappings();
for ($i=0; $i < $nbColumns; $i++) {
$leftColName = ($leftTableAlias ? $leftTableAlias : $leftCols[$i]->getTableName()) . '.' . $leftCols[$i]->getName();
$rightColName = ($relationAlias ? $relationAlias : $rightCols[$i]->getTableName()) . '.' . $rightCols[$i]->getName();
$this->addCondition($leftColName, $rightColName, Criteria::EQUAL);
}
$this->relationMap = $relationMap;
$this->leftTableAlias = $leftTableAlias;
$this->relationAlias = $relationAlias;
return $this;
}
public function getRelationMap()
{
return $this->relationMap;
}
/**
* Sets the right tableMap for this join
*
* @param TableMap $tableMap The table map to use
*
* @return ModelJoin The current join object, for fluid interface
*/
public function setTableMap(TableMap $tableMap)
{
$this->tableMap = $tableMap;
return $this;
}
/**
* Gets the right tableMap for this join
*
* @return TableMap The table map
*/
public function getTableMap()
{
if (null === $this->tableMap && null !== $this->relationMap)
{
$this->tableMap = $this->relationMap->getRightTable();
}
return $this->tableMap;
}
public function setPreviousJoin(ModelJoin $join)
{
$this->previousJoin = $join;
return $this;
}
public function getPreviousJoin()
{
return $this->previousJoin;
}
public function isPrimary()
{
return null === $this->previousJoin;
}
public function setLeftTableAlias($leftTableAlias)
{
$this->leftTableAlias = $leftTableAlias;
return $this;
}
public function getLeftTableAlias()
{
return $this->leftTableAlias;
}
public function hasLeftTableAlias()
{
return null !== $this->leftTableAlias;
}
public function setRelationAlias($relationAlias)
{
$this->relationAlias = $relationAlias;
return $this;
}
public function getRelationAlias()
{
return $this->relationAlias;
}
public function hasRelationAlias()
{
return null !== $this->relationAlias;
}
/**
* This method returns the last related, but already hydrated object up until this join
* Starting from $startObject and continuously calling the getters to get
* to the base object for the current join.
*
* This method only works if PreviousJoin has been defined,
* which only happens when you provide dotted relations when calling join
*
* @param Object $startObject the start object all joins originate from and which has already hydrated
* @return Object the base Object of this join
*/
public function getObjectToRelate($startObject)
{
if($this->isPrimary()) {
return $startObject;
} else {
$previousJoin = $this->getPreviousJoin();
$previousObject = $previousJoin->getObjectToRelate($startObject);
$method = 'get' . $previousJoin->getRelationMap()->getName();
return $previousObject->$method();
}
}
public function equals($join)
{
return parent::equals($join)
&& $this->relationMap == $join->getRelationMap()
&& $this->previousJoin == $join->getPreviousJoin()
&& $this->relationAlias == $join->getRelationAlias();
}
public function __toString()
{
return parent::toString()
. ' tableMap: ' . ($this->tableMap ? get_class($this->tableMap) : 'null')
. ' relationMap: ' . $this->relationMap->getName()
. ' previousJoin: ' . ($this->previousJoin ? '(' . $this->previousJoin . ')' : 'null')
. ' relationAlias: ' . $this->relationAlias;
}
}

View file

@ -0,0 +1,33 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Factory for model queries
*
* @author François Zaninotto
* @version $Revision: 1612 $
* @package propel.runtime.query
*/
class PropelQuery
{
public static function from($queryClassAndAlias)
{
list($class, $alias) = ModelCriteria::getClassAndAlias($queryClassAndAlias);
$queryClass = $class . 'Query';
if (!class_exists($queryClass)) {
throw new PropelException('Cannot find a query class for ' . $class);
}
$query = new $queryClass();
if ($alias !== null) {
$query->setModelAlias($alias);
}
return $query;
}
}