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:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
|
@ -0,0 +1,188 @@
|
|||
<?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 for iterating over a list of Propel objects stored as arrays
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @package propel.runtime.collection
|
||||
*/
|
||||
class PropelArrayCollection extends PropelCollection
|
||||
{
|
||||
protected $workerObject;
|
||||
|
||||
/**
|
||||
* Save all the elements in the collection
|
||||
*/
|
||||
public function save($con = null)
|
||||
{
|
||||
if (null === $con) {
|
||||
$con = $this->getConnection(Propel::CONNECTION_WRITE);
|
||||
}
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
$obj = $this->getWorkerObject();
|
||||
foreach ($this as $element) {
|
||||
$obj->clear();
|
||||
$obj->fromArray($element);
|
||||
$obj->setNew($obj->isPrimaryKeyNull());
|
||||
$obj->save($con);
|
||||
}
|
||||
$con->commit();
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the elements in the collection
|
||||
*/
|
||||
public function delete($con = null)
|
||||
{
|
||||
if (null === $con) {
|
||||
$con = $this->getConnection(Propel::CONNECTION_WRITE);
|
||||
}
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
foreach ($this as $element) {
|
||||
$obj = $this->getWorkerObject();
|
||||
$obj->setDeleted(false);
|
||||
$obj->fromArray($element);
|
||||
$obj->delete($con);
|
||||
}
|
||||
$con->commit();
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of the primary keys of all the objects in the collection
|
||||
*
|
||||
* @return array The list of the primary keys of the collection
|
||||
*/
|
||||
public function getPrimaryKeys($usePrefix = true)
|
||||
{
|
||||
$callable = array($this->getPeerClass(), 'getPrimaryKeyFromRow');
|
||||
$ret = array();
|
||||
foreach ($this as $key => $element) {
|
||||
$key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
|
||||
$ret[$key]= call_user_func($callable, array_values($element));
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the collection from an array
|
||||
* Uses the object model to force the column types
|
||||
* Does not empty the collection before adding the data from the array
|
||||
*
|
||||
* @param array $arr
|
||||
*/
|
||||
public function fromArray($arr)
|
||||
{
|
||||
$obj = $this->getWorkerObject();
|
||||
foreach ($arr as $element) {
|
||||
$obj->clear();
|
||||
$obj->fromArray($element);
|
||||
$this->append($obj->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representation of the collection
|
||||
* This is not an alias for getData(), since it returns a copy of the data
|
||||
*
|
||||
* @param string $keyColumn If null, the returned array uses an incremental index.
|
||||
* Otherwise, the array is indexed using the specified column
|
||||
* @param boolean $usePrefix If true, the returned array prefixes keys
|
||||
* with the model class name ('Article_0', 'Article_1', etc).
|
||||
*
|
||||
* <code>
|
||||
* $bookCollection->toArray();
|
||||
* array(
|
||||
* 0 => array('Id' => 123, 'Title' => 'War And Peace'),
|
||||
* 1 => array('Id' => 456, 'Title' => 'Don Juan'),
|
||||
* )
|
||||
* $bookCollection->toArray('Id');
|
||||
* array(
|
||||
* 123 => array('Id' => 123, 'Title' => 'War And Peace'),
|
||||
* 456 => array('Id' => 456, 'Title' => 'Don Juan'),
|
||||
* )
|
||||
* $bookCollection->toArray(null, true);
|
||||
* array(
|
||||
* 'Book_0' => array('Id' => 123, 'Title' => 'War And Peace'),
|
||||
* 'Book_1' => array('Id' => 456, 'Title' => 'Don Juan'),
|
||||
* )
|
||||
* </code>
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($keyColumn = null, $usePrefix = false)
|
||||
{
|
||||
$ret = array();
|
||||
foreach ($this as $key => $element) {
|
||||
$key = null === $keyColumn ? $key : $element[$keyColumn];
|
||||
$key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
|
||||
$ret[$key] = $element;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synonym for toArray(), to provide a similar interface to PopelObjectCollection
|
||||
*/
|
||||
public function getArrayCopy($keyColumn = null, $usePrefix = false)
|
||||
{
|
||||
if (null === $keyColumn && false === $usePrefix) {
|
||||
return parent::getArrayCopy();
|
||||
} else {
|
||||
return $this->toArray($keyColumn, $usePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an associative array representation of the collection
|
||||
* The first parameter specifies the column to be used for the key,
|
||||
* And the seconf for the value.
|
||||
* <code>
|
||||
* $res = $coll->toKeyValue('Id', 'Name');
|
||||
* </code>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toKeyValue($keyColumn, $valueColumn)
|
||||
{
|
||||
$ret = array();
|
||||
foreach ($this as $obj) {
|
||||
$ret[$obj[$keyColumn]] = $obj[$valueColumn];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function getWorkerObject()
|
||||
{
|
||||
if (null === $this->workerObject) {
|
||||
if ($this->model == '') {
|
||||
throw new PropelException('You must set the collection model before interacting with it');
|
||||
}
|
||||
$class = $this->getModel();
|
||||
$this->workerObject = new $class();
|
||||
}
|
||||
|
||||
return $this->workerObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,409 @@
|
|||
<?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 for iterating over a list of Propel elements
|
||||
* The collection keys must be integers - no associative array accepted
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @package propel.runtime.collection
|
||||
*/
|
||||
class PropelCollection extends ArrayObject implements Serializable
|
||||
{
|
||||
protected $model = '';
|
||||
protected $iterator;
|
||||
protected $formatter;
|
||||
|
||||
|
||||
// Generic Collection methods
|
||||
|
||||
/**
|
||||
* Get the data in the collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->getArrayCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data in the collection
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->exchangeArray($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of the internal pointer
|
||||
* This position can be later used in seek()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPosition()
|
||||
{
|
||||
return (int) $this->getInternalIterator()->key();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the internal pointer to the beginning of the list
|
||||
* And get the first element in the collection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFirst()
|
||||
{
|
||||
$this->getInternalIterator()->rewind();
|
||||
return $this->getCurrent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the internal pointer is at the beginning of the list
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isFirst()
|
||||
{
|
||||
return $this->getPosition() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the internal pointer backward
|
||||
* And get the previous element in the collection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPrevious()
|
||||
{
|
||||
$pos = $this->getPosition();
|
||||
if ($pos == 0) {
|
||||
return null;
|
||||
} else {
|
||||
$this->getInternalIterator()->seek($pos - 1);
|
||||
return $this->getCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current element in the collection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCurrent()
|
||||
{
|
||||
return $this->getInternalIterator()->current();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the internal pointer forward
|
||||
* And get the next element in the collection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNext()
|
||||
{
|
||||
$this->getInternalIterator()->next();
|
||||
return $this->getCurrent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the internal pointer to the end of the list
|
||||
* And get the last element in the collection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLast()
|
||||
{
|
||||
$count = $this->count();
|
||||
if ($count == 0) {
|
||||
return null;
|
||||
} else {
|
||||
$this->getInternalIterator()->seek($count - 1);
|
||||
return $this->getCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the internal pointer is at the end of the list
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLast()
|
||||
{
|
||||
$count = $this->count();
|
||||
if ($count == 0) {
|
||||
// empty list... so yes, this is the last
|
||||
return true;
|
||||
} else {
|
||||
return $this->getPosition() == $count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the collection is empty
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->count() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current index is an odd integer
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOdd()
|
||||
{
|
||||
return (boolean) ($this->getInternalIterator()->key() % 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current index is an even integer
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEven()
|
||||
{
|
||||
return !$this->isOdd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element from its key
|
||||
* Alias for ArrayObject::offsetGet()
|
||||
*
|
||||
* @param mixed $key
|
||||
*
|
||||
* @return mixed The element
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!$this->offsetExists($key)) {
|
||||
throw new PropelException('Unknown key ' . $key);
|
||||
}
|
||||
return $this->offsetGet($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops an element off the end of the collection
|
||||
*
|
||||
* @return mixed The popped element
|
||||
*/
|
||||
public function pop()
|
||||
{
|
||||
if ($this->count() == 0) {
|
||||
return null;
|
||||
}
|
||||
$ret = $this->getLast();
|
||||
$lastKey = $this->getInternalIterator()->key();
|
||||
$this->offsetUnset((string) $lastKey);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops an element off the beginning of the collection
|
||||
*
|
||||
* @return mixed The popped element
|
||||
*/
|
||||
public function shift()
|
||||
{
|
||||
// the reindexing is complicated to deal with through the iterator
|
||||
// so let's use the simple solution
|
||||
$arr = $this->getArrayCopy();
|
||||
$ret = array_shift($arr);
|
||||
$this->exchangeArray($arr);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend one or more elements to the beginning of the collection
|
||||
*
|
||||
* @param mixed $value the element to prepend
|
||||
*
|
||||
* @return int The number of new elements in the array
|
||||
*/
|
||||
public function prepend($value)
|
||||
{
|
||||
// the reindexing is complicated to deal with through the iterator
|
||||
// so let's use the simple solution
|
||||
$arr = $this->getArrayCopy();
|
||||
$ret = array_unshift($arr, $value);
|
||||
$this->exchangeArray($arr);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element to the collection with the given key
|
||||
* Alias for ArrayObject::offsetSet()
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
return $this->offsetSet($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a specified collection element
|
||||
* Alias for ArrayObject::offsetUnset()
|
||||
*
|
||||
* @param mixed $key
|
||||
*
|
||||
* @return mixed The removed element
|
||||
*/
|
||||
public function remove($key)
|
||||
{
|
||||
if (!$this->offsetExists($key)) {
|
||||
throw new PropelException('Unknown key ' . $key);
|
||||
}
|
||||
return $this->offsetUnset($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the collection
|
||||
*
|
||||
* @return array The previous collection
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return $this->exchangeArray(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this collection contains a specified element
|
||||
*
|
||||
* @param mixed $element the element
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function contains($element)
|
||||
{
|
||||
return in_array($element, $this->getArrayCopy(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search an element in the collection
|
||||
*
|
||||
* @param mixed $element
|
||||
*
|
||||
* @return mixed Returns the key for the element if it is found in the collection, FALSE otherwise
|
||||
*/
|
||||
public function search($element)
|
||||
{
|
||||
return array_search($element, $this->getArrayCopy(), true);
|
||||
}
|
||||
|
||||
// Serializable interface
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
$repr = array(
|
||||
'data' => $this->getArrayCopy(),
|
||||
'model' => $this->model,
|
||||
);
|
||||
return serialize($repr);
|
||||
}
|
||||
|
||||
public function unserialize($data)
|
||||
{
|
||||
$repr = unserialize($data);
|
||||
$this->exchangeArray($repr['data']);
|
||||
$this->model = $repr['model'];
|
||||
}
|
||||
|
||||
// IteratorAggregate method
|
||||
|
||||
/**
|
||||
* Overrides ArrayObject::getIterator() to save the iterator object
|
||||
* for internal use e.g. getNext(), isOdd(), etc.
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
$this->iterator = new ArrayIterator($this);
|
||||
return $this->iterator;
|
||||
}
|
||||
|
||||
public function getInternalIterator()
|
||||
{
|
||||
if (null === $this->iterator) {
|
||||
return $this->getIterator();
|
||||
}
|
||||
return $this->iterator;
|
||||
}
|
||||
|
||||
// Propel collection methods
|
||||
|
||||
/**
|
||||
* Set the model of the elements in the collection
|
||||
*
|
||||
* @param string $model Name of the Propel object classes stored in the collection
|
||||
*/
|
||||
public function setModel($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model of the elements in the collection
|
||||
*
|
||||
* @return string Name of the Propel object class stored in the collection
|
||||
*/
|
||||
public function getModel()
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the peer class of the elements in the collection
|
||||
*
|
||||
* @return string Name of the Propel peer class stored in the collection
|
||||
*/
|
||||
public function getPeerClass()
|
||||
{
|
||||
if ($this->model == '') {
|
||||
throw new PropelException('You must set the collection model before interacting with it');
|
||||
}
|
||||
return constant($this->getModel() . '::PEER');
|
||||
}
|
||||
|
||||
public function setFormatter(PropelFormatter $formatter)
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a connection object for the database containing the elements of the collection
|
||||
*
|
||||
* @param string $type The connection type (Propel::CONNECTION_READ by default; can be Propel::connection_WRITE)
|
||||
*
|
||||
* @return PropelPDO a connection object
|
||||
*/
|
||||
public function getConnection($type = Propel::CONNECTION_READ)
|
||||
{
|
||||
$databaseName = constant($this->getPeerClass() . '::DATABASE_NAME');
|
||||
|
||||
return Propel::getConnection($databaseName, $type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,249 @@
|
|||
<?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 for iterating over a list of Propel objects
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @package propel.runtime.collection
|
||||
*/
|
||||
class PropelObjectCollection extends PropelCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* Save all the elements in the collection
|
||||
*/
|
||||
public function save($con = null)
|
||||
{
|
||||
if (null === $con) {
|
||||
$con = $this->getConnection(Propel::CONNECTION_WRITE);
|
||||
}
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
foreach ($this as $element) {
|
||||
$element->save($con);
|
||||
}
|
||||
$con->commit();
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the elements in the collection
|
||||
*/
|
||||
public function delete($con = null)
|
||||
{
|
||||
if (null === $con) {
|
||||
$con = $this->getConnection(Propel::CONNECTION_WRITE);
|
||||
}
|
||||
$con->beginTransaction();
|
||||
try {
|
||||
foreach ($this as $element) {
|
||||
$element->delete($con);
|
||||
}
|
||||
$con->commit();
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of the primary keys of all the objects in the collection
|
||||
*
|
||||
* @return array The list of the primary keys of the collection
|
||||
*/
|
||||
public function getPrimaryKeys($usePrefix = true)
|
||||
{
|
||||
$ret = array();
|
||||
foreach ($this as $key => $obj) {
|
||||
$key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
|
||||
$ret[$key]= $obj->getPrimaryKey();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the collection from an array
|
||||
* Each object is populated from an array and the result is stored
|
||||
* Does not empty the collection before adding the data from the array
|
||||
*
|
||||
* @param array $arr
|
||||
*/
|
||||
public function fromArray($arr)
|
||||
{
|
||||
$class = $this->getModel();
|
||||
foreach ($arr as $element) {
|
||||
$obj = new $class();
|
||||
$obj->fromArray($element);
|
||||
$this->append($obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representation of the collection
|
||||
* Each object is turned into an array and the result is returned
|
||||
*
|
||||
* @param string $keyColumn If null, the returned array uses an incremental index.
|
||||
* Otherwise, the array is indexed using the specified column
|
||||
* @param boolean $usePrefix If true, the returned array prefixes keys
|
||||
* with the model class name ('Article_0', 'Article_1', etc).
|
||||
*
|
||||
* <code>
|
||||
* $bookCollection->toArray();
|
||||
* array(
|
||||
* 0 => array('Id' => 123, 'Title' => 'War And Peace'),
|
||||
* 1 => array('Id' => 456, 'Title' => 'Don Juan'),
|
||||
* )
|
||||
* $bookCollection->toArray('Id');
|
||||
* array(
|
||||
* 123 => array('Id' => 123, 'Title' => 'War And Peace'),
|
||||
* 456 => array('Id' => 456, 'Title' => 'Don Juan'),
|
||||
* )
|
||||
* $bookCollection->toArray(null, true);
|
||||
* array(
|
||||
* 'Book_0' => array('Id' => 123, 'Title' => 'War And Peace'),
|
||||
* 'Book_1' => array('Id' => 456, 'Title' => 'Don Juan'),
|
||||
* )
|
||||
* </code>
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($keyColumn = null, $usePrefix = false)
|
||||
{
|
||||
$ret = array();
|
||||
$keyGetterMethod = 'get' . $keyColumn;
|
||||
foreach ($this as $key => $obj) {
|
||||
$key = null === $keyColumn ? $key : $obj->$keyGetterMethod();
|
||||
$key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
|
||||
$ret[$key] = $obj->toArray();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representation of the collection
|
||||
*
|
||||
* @param string $keyColumn If null, the returned array uses an incremental index.
|
||||
* Otherwise, the array is indexed using the specified column
|
||||
* @param boolean $usePrefix If true, the returned array prefixes keys
|
||||
* with the model class name ('Article_0', 'Article_1', etc).
|
||||
*
|
||||
* <code>
|
||||
* $bookCollection->getArrayCopy();
|
||||
* array(
|
||||
* 0 => $book0,
|
||||
* 1 => $book1,
|
||||
* )
|
||||
* $bookCollection->getArrayCopy('Id');
|
||||
* array(
|
||||
* 123 => $book0,
|
||||
* 456 => $book1,
|
||||
* )
|
||||
* $bookCollection->getArrayCopy(null, true);
|
||||
* array(
|
||||
* 'Book_0' => $book0,
|
||||
* 'Book_1' => $book1,
|
||||
* )
|
||||
* </code>
|
||||
* @return array
|
||||
*/
|
||||
public function getArrayCopy($keyColumn = null, $usePrefix = false)
|
||||
{
|
||||
if (null === $keyColumn && false === $usePrefix) {
|
||||
return parent::getArrayCopy();
|
||||
}
|
||||
$ret = array();
|
||||
$keyGetterMethod = 'get' . $keyColumn;
|
||||
foreach ($this as $key => $obj) {
|
||||
$key = null === $keyColumn ? $key : $obj->$keyGetterMethod();
|
||||
$key = $usePrefix ? ($this->getModel() . '_' . $key) : $key;
|
||||
$ret[$key] = $obj;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an associative array representation of the collection
|
||||
* The first parameter specifies the column to be used for the key,
|
||||
* And the seconf for the value.
|
||||
* <code>
|
||||
* $res = $coll->toKeyValue('Id', 'Name');
|
||||
* </code>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toKeyValue($keyColumn = 'PrimaryKey', $valueColumn = null)
|
||||
{
|
||||
$ret = array();
|
||||
$keyGetterMethod = 'get' . $keyColumn;
|
||||
$valueGetterMethod = (null === $valueColumn) ? '__toString' : ('get' . $valueColumn);
|
||||
foreach ($this as $obj) {
|
||||
$ret[$obj->$keyGetterMethod()] = $obj->$valueGetterMethod();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an additional query to populate the objects related to the collection objects
|
||||
* by a certain relation
|
||||
*
|
||||
* @param string $relation Relation name (e.g. 'Book')
|
||||
* @param Criteria $criteria Optional Criteria object to filter the related object collection
|
||||
* @param PropelPDO $con Optional connection object
|
||||
*
|
||||
* @return PropelObjectCollection the list of related objects
|
||||
*/
|
||||
public function populateRelation($relation, $criteria = null, $con = null)
|
||||
{
|
||||
if (!Propel::isInstancePoolingEnabled()) {
|
||||
throw new PropelException('populateRelation() needs instance pooling to be enabled prior to populating the collection');
|
||||
}
|
||||
$relationMap = $this->getFormatter()->getTableMap()->getRelation($relation);
|
||||
$symRelationMap = $relationMap->getSymmetricalRelation();
|
||||
|
||||
// query the db for the related objects
|
||||
$useMethod = 'use' . $symRelationMap->getName() . 'Query';
|
||||
$query = PropelQuery::from($relationMap->getRightTable()->getPhpName());
|
||||
if (null !== $criteria) {
|
||||
$query->mergeWith($criteria);
|
||||
}
|
||||
$relatedObjects = $query
|
||||
->$useMethod()
|
||||
->filterByPrimaryKeys($this->getPrimaryKeys())
|
||||
->endUse()
|
||||
->find($con);
|
||||
|
||||
// associate the related objects to the main objects
|
||||
if ($relationMap->getType() == RelationMap::ONE_TO_MANY) {
|
||||
$getMethod = 'get' . $symRelationMap->getName();
|
||||
$addMethod = 'add' . $relationMap->getName();
|
||||
foreach ($relatedObjects as $object) {
|
||||
$mainObj = $object->$getMethod(); // instance pool is used here to avoid a query
|
||||
$mainObj->$addMethod($object);
|
||||
}
|
||||
} elseif ($relationMap->getType() == RelationMap::MANY_TO_ONE) {
|
||||
// nothing to do; the instance pool will catch all calls to getRelatedObject()
|
||||
// and return the object in memory
|
||||
} else {
|
||||
throw new PropelException('populateRelation() does not support this relation type');
|
||||
}
|
||||
|
||||
return $relatedObjects;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,151 @@
|
|||
<?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 for iterating over a statement and returning one Propel object at a time
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @package propel.runtime.collection
|
||||
*/
|
||||
class PropelOnDemandCollection extends PropelCollection
|
||||
{
|
||||
protected
|
||||
$iterator,
|
||||
$currentRow,
|
||||
$currentKey = -1,
|
||||
$isValid = null;
|
||||
|
||||
public function initIterator(PropelFormatter $formatter, PDOStatement $stmt)
|
||||
{
|
||||
$this->iterator = new PropelOnDemandIterator($formatter, $stmt);
|
||||
}
|
||||
|
||||
// IteratorAggregate Interface
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->iterator;
|
||||
}
|
||||
|
||||
// ArrayAccess Interface
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
if ($offset == $this->currentKey) {
|
||||
return true;
|
||||
}
|
||||
throw new PropelException('The On Demand Collection does not allow acces by offset');
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
if ($offset == $this->currentKey) {
|
||||
return $this->currentRow;
|
||||
}
|
||||
throw new PropelException('The On Demand Collection does not allow acces by offset');
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
// Serializable Interface
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection cannot be serialized');
|
||||
}
|
||||
|
||||
public function unserialize($data)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection cannot be serialized');
|
||||
}
|
||||
|
||||
// Countable Interface
|
||||
|
||||
/**
|
||||
* Returns the number of rows in the resultset
|
||||
* Warning: this number is inaccurate for most databases. Do not rely on it for a portable application.
|
||||
*
|
||||
* @return int number of results
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->iterator->count();
|
||||
}
|
||||
|
||||
// ArrayObject methods
|
||||
|
||||
public function append($value)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function prepend($value)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function asort()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function exchangeArray($input)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function getArrayCopy()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection does not allow acces by offset');
|
||||
}
|
||||
|
||||
public function getFlags()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection does not allow acces by offset');
|
||||
}
|
||||
|
||||
public function ksort()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function natcasesort()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function natsort()
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function setFlags($flags)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection does not allow acces by offset');
|
||||
}
|
||||
|
||||
public function uasort($cmp_function)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
|
||||
public function uksort($cmp_function)
|
||||
{
|
||||
throw new PropelException('The On Demand Collection is read only');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
<?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 for iterating over a statement and returning one Propel object at a time
|
||||
*
|
||||
* @author Francois Zaninotto
|
||||
* @package propel.runtime.collection
|
||||
*/
|
||||
class PropelOnDemandIterator implements Iterator
|
||||
{
|
||||
protected
|
||||
$formatter,
|
||||
$stmt,
|
||||
$currentRow,
|
||||
$currentKey = -1,
|
||||
$isValid = null,
|
||||
$enableInstancePoolingOnFinish = false;
|
||||
|
||||
public function __construct(PropelFormatter $formatter, PDOStatement $stmt)
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
$this->stmt = $stmt;
|
||||
$this->enableInstancePoolingOnFinish = Propel::disableInstancePooling();
|
||||
}
|
||||
|
||||
public function closeCursor()
|
||||
{
|
||||
$this->stmt->closeCursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of rows in the resultset
|
||||
* Warning: this number is inaccurate for most databases. Do not rely on it for a portable application.
|
||||
*
|
||||
* @return int number of results
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->stmt->rowCount();
|
||||
}
|
||||
|
||||
// Iterator Interface
|
||||
|
||||
/**
|
||||
* Gets the current Model object in the collection
|
||||
* This is where the hydration takes place.
|
||||
*
|
||||
* @see PropelObjectFormatter::getAllObjectsFromRow()
|
||||
*
|
||||
* @return BaseObject
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return $this->formatter->getAllObjectsFromRow($this->currentRow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current key in the iterator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return $this->currentKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances the curesor in the statement
|
||||
* Closes the cursor if the end of the statement is reached
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->currentRow = $this->stmt->fetch(PDO::FETCH_NUM);
|
||||
$this->currentKey++;
|
||||
$this->isValid = (boolean) $this->currentRow;
|
||||
if (!$this->isValid) {
|
||||
$this->closeCursor();
|
||||
if ($this->enableInstancePoolingOnFinish) {
|
||||
Propel::enableInstancePooling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the iterator by advancing to the first position
|
||||
* This method can only be called once (this is a NoRewindIterator)
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
// check that the hydration can begin
|
||||
if (null === $this->formatter) {
|
||||
throw new PropelException('The On Demand collection requires a formatter. Add it by calling setFormatter()');
|
||||
}
|
||||
if (null === $this->stmt) {
|
||||
throw new PropelException('The On Demand collection requires a statement. Add it by calling setStatement()');
|
||||
}
|
||||
if (null !== $this->isValid) {
|
||||
throw new PropelException('The On Demand collection can only be iterated once');
|
||||
}
|
||||
|
||||
// initialize the current row and key
|
||||
$this->next();
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue