Created
March 26, 2011 15:42
-
-
Save CriticalPursuits/888386 to your computer and use it in GitHub Desktop.
DQ extends Doctrine_Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This is a simple short-hand wrapper for Doctrine_Query. It provides | |
* a shorter class name and a few additional functions. | |
*/ | |
class DQ extends Doctrine_Query | |
{ | |
/** | |
* Returns a DQ object to get started | |
* | |
* @return DQ | |
*/ | |
public static function create($conn = null) { | |
return new DQ($conn); | |
} | |
/** | |
* This function will wrap the current dql where statement | |
* in parenthesis. This allows more complex dql statements | |
* It can be called multiple times during the creation of the dql | |
* where clause. | |
* | |
* @return $this | |
*/ | |
public function whereParenWrap() { | |
$where = $this->_dqlParts['where']; | |
if (count($where) > 0) { | |
array_unshift($where, '('); | |
array_push($where, ')'); | |
$this->_dqlParts['where'] = $where; | |
} | |
return $this; | |
} | |
/** | |
* Create and andWhere if the where parameter is not empty | |
* | |
* @param string $where where string | |
* @param parameters $params | |
* | |
* @return DQ this object | |
*/ | |
public function andWhereIf($where, $params = array()) { | |
return empty($where) | |
? $this | |
: $this->andWhere($where, $params); | |
} | |
/** | |
* Create and orWhere if the where parameter is not empty | |
* | |
* @param string $where where string | |
* @param parameters $params | |
* | |
* @return DQ this object | |
*/ | |
public function orWhereIf($where, $params = array()) { | |
return empty($where) | |
? $this | |
: $this->orWhere($where, $params); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment