* added new fetchOne() method for convenience
* some whitespace cleanups
This commit is contained in:
parent
97e82445d7
commit
c662f4d99f
@ -904,9 +904,46 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
|
||||
|
||||
return $str;
|
||||
}
|
||||
/**
|
||||
* fetchArray
|
||||
* Convenience method to execute using array fetching as hydration mode.
|
||||
*
|
||||
* @param string $params
|
||||
* @return array
|
||||
*/
|
||||
public function fetchArray($params = array()) {
|
||||
return $this->execute($params, self::HYDRATE_ARRAY);
|
||||
}
|
||||
/**
|
||||
* fetchOne
|
||||
* Convenience method to execute the query and return the first item
|
||||
* of the collection.
|
||||
*
|
||||
* @param string $params Parameters
|
||||
* @param int $hydrationMode Hydration mode
|
||||
* @return mixed Array or Doctrine_Collection or false if no result.
|
||||
*/
|
||||
public function fetchOne($params = array(), $hydrationMode = null)
|
||||
{
|
||||
if (is_null($hydrationMode)) {
|
||||
$hydrationMode = $this->_hydrationMode;
|
||||
}
|
||||
|
||||
$collection = $this->execute($params, $hydrationMode);
|
||||
|
||||
switch ($hydrationMode) {
|
||||
case self::HYDRATE_RECORD:
|
||||
if (count($collection) > 0) {
|
||||
return $collection->getFirst();
|
||||
}
|
||||
case self::HYDRATE_ARRAY:
|
||||
if (!empty($collection[0])) {
|
||||
return $collection[0];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* parseData
|
||||
* parses the data returned by statement object
|
||||
|
Loading…
x
Reference in New Issue
Block a user