X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplfilter.php;h=af8141d4e939f96857a1f32f0eb26b74955af1bb;hb=0e95424b8ceb913f81b0672f0171d2fc0e32bbe2;hp=5c23d1c0798c3520e1df9cc095d14aa6c79a3dc4;hpb=7e001f68b7928d80ccf32b8a8bca55d304476d3e;p=platal.git diff --git a/classes/plfilter.php b/classes/plfilter.php index 5c23d1c..af8141d 100644 --- a/classes/plfilter.php +++ b/classes/plfilter.php @@ -47,110 +47,6 @@ class PlLimit } // }}} -// {{{ class PlSqlJoin -class PlSqlJoin -{ - private $mode; - private $table; - private $condition; - - const MODE_LEFT = 'LEFT'; - const MODE_RIGHT = 'RIGHT'; - const MODE_INNER = 'INNER'; - - private function __construct($mode, $params) - { - $table = array_shift($params); - $condition = call_user_func_array(array('XDB', 'format'), $params); - if ($mode != self::MODE_LEFT && $mode != self::MODE_RIGHT && $mode != self::MODE_INNER) { - Platal::page()->kill("Join mode error: unknown mode $mode"); - return; - } - $this->mode = $mode; - $this->table = $table; - $this->condition = $condition; - } - - public function mode() - { - return $this->mode; - } - - public function table() - { - return $this->table; - } - - public function condition() - { - return $this->condition; - } - - /** Replace all "metas" in the condition with their translation. - * $ME always becomes the alias of the table - * @param $key The name the joined table will have in the final query - * @param $joinMetas An array of meta => conversion to apply to the condition - */ - public function replaceJoinMetas($key, $joinMetas = array()) - { - $joinMetas['$ME'] = $key; - return str_replace(array_keys($joinMetas), $joinMetas, $this->condition); - } - - /** Create a join command from an array of PlSqlJoin - * @param $joins The list of 'join' to convert into an SQL query - * @param $joinMetas An array of ('$META' => 'conversion') to apply to the joins. - */ - public static function formatJoins(array $joins, array $joinMetas) - { - $str = ''; - foreach ($joins as $key => $join) { - if (!($join instanceof PlSqlJoin)) { - Platal::page()->kill("Error: not a join: $join"); - } - $mode = $join->mode(); - $table = $join->table(); - $str .= ' ' . $mode . ' JOIN ' . $table . ' AS ' . $key; - if ($join->condition() != null) { - $str .= ' ON (' . $join->replaceJoinMetas($key, $joinMetas) . ')'; - } - $str .= "\n"; - } - return $str; - } - - /** Build a left join - * @param table The name of the table. - * @param condition The condition of the jointure - */ - public static function left() - { - $params = func_get_args(); - return new PlSqlJoin(self::MODE_LEFT, $params); - } - - /** Build a right join - * @param table The name of the table. - * @param condition The condition of the jointure - */ - public static function right() - { - $params = func_get_args(); - return new PlSqlJoin(self::MODE_RIGHT, $params); - } - - /** Build a inner join - * @param table The name of the table. - * @param condition The condition of the jointure - */ - public static function inner() - { - $params = func_get_args(); - return new PlSqlJoin(self::MODE_INNER, $params); - } -} -// }}} - // {{{ class PlFilterOrder /** Base class for ordering results of a query. * Parameters for the ordering must be given to the constructor ($desc for a