Skip to content

Instantly share code, notes, and snippets.

@CriticalPursuits
Created March 26, 2011 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CriticalPursuits/888386 to your computer and use it in GitHub Desktop.
Save CriticalPursuits/888386 to your computer and use it in GitHub Desktop.
DQ extends Doctrine_Query
<?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