* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
+// {{{ class PlLimit
class PlLimit
{
private $count = null;
return '';
}
}
+// }}}
+// {{{ class PlSqlJoin
class PlSqlJoin
{
private $mode;
const MODE_RIGHT = 'RIGHT';
const MODE_INNER = 'INNER';
- public function __construct($mode, $table, $condition)
+ 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;
}
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
abstract class PlFilterOrder
{
protected $desc = false;
return $sel;
}
- abstract protected function getSortTokens(&$pf);
+ abstract protected function getSortTokens(PlFilter &$pf);
}
+// }}}
+
+// {{{ class PFO_Random
+class PFO_Random extends PlFilterOrder
+{
+ private $seed = null;
+
+ public function __construct($seed = null, $desc = false)
+ {
+ parent::__construct($desc);
+ $this->seed = $seed;
+ }
+
+ protected function getSortTokens(PlFilter &$pf)
+ {
+ if ($this->seed == null) {
+ return 'RAND()';
+ } else {
+ return XDB::format('RAND({?})', $this->seed);
+ }
+ }
+}
+// }}}
// {{{ interface PlFilterCondition
interface PlFilterCondition
}
// }}}
-
+// {{{ class PlFilter
abstract class PlFilter
{
/** Filters objects matching the PlFilter
* @param $objects The objects to filter
* @param $limit The portion of the matching objects to show
*/
- public abstract function filter(array $objects, PlLimit &$limit);
+ public abstract function filter(array $objects, $limit = null);
public abstract function setCondition(PlFilterCondition &$cond);
/** Get objects, selecting only those within a limit
* @param $limit The portion of the matching objects to select
*/
- public abstract function get(PlLimit &$limit);
+ public abstract function get($limit = null);
/** PRIVATE FUNCTIONS
*/
}
}
+// }}}
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>