. */ class Staple_Query_Delete extends Staple_Query { const IGNORE = 'IGNORE'; const LOW_PRIORITY = 'LOW_PRIORITY'; const QUICK = 'QUICK'; /** * Additional Query Flags * @var array[string] */ protected $flags = array(); /** * Array of Staple_Query_Join objects that represent table joins on the query * @var array[Staple_Query_Join] */ protected $joins = array(); public function __construct($table = NULL, mysqli $db = NULL) { parent::__construct($table, $db); } public function addFlag($flag) { switch($flag) { case self::ALL: case self::DISTINCT: case self::DISTINCTROW: case self::HIGH_PRIORITY: case self::STRAIGHT_JOIN: case self::SQL_SMALL_RESULT: case self::SQL_BIG_RESULT: case self::SQL_BUFFER_RESULT: case self::SQL_CACHE: case self::SQL_NO_CACHE: case self::SQL_CALC_FOUND_ROWS: $this->flags[] = $flag; break; } return $this; } public function clearFlags() { $this->flags = array(); return $this; } /** * @param mixed $table * @param string $alias */ public function setTable($table) { //@todo expand to include multiple tables $this->table = (string)$table; return $this; } /*-----------------------------------------------JOIN FUNCTIONS-----------------------------------------------*/ public function addJoin(Staple_Query_Join $join) { $this->joins[] = $join; } public function removeJoin($table) { foreach($this->joins as $key=>$join) { if($join->getTable() == $table) { unset($this->joins[$key]); return true; } } return false; } public function leftJoin($table, $condition) { $this->addJoin(Staple_Query_Join::left($table, $condition)); return $this; } public function innerJoin($table, $condition) { $this->addJoin(Staple_Query_Join::inner($table, $condition)); return $this; } public function getJoins() { return $this->joins; } /*-----------------------------------------------BUILD FUNCTION-----------------------------------------------*/ /** * * @see Staple_Query::build() */ function build() { $stmt = 'DELETE '; //Flags if(count($this->flags) > 0) { $stmt .= ' '.implode(' ', $this->flags); } //FROM CLAUSE $stmt .= "FROM ".$this->table; //JOINS if(count($this->joins) > 0) { $stmt .= "\n".implode("\n", $this->joins); } //WHERE CLAUSE if(count($this->where) > 0) { $stmt .= "\nWHERE ".implode(' AND ', $this->where); } return $stmt; } } ?>