* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
+// {{{ class PlLimit
class PlLimit
{
private $count = null;
public function getSql()
{
- if (!is_null($this->count)) {
+ if (!is_null($this->count) && $this->count != 0) {
if (!is_null($this->from) && $this->from != 0) {
return XDB::format('LIMIT {?}, {?}', (int)$this->from, (int)$this->count);
} else {
return '';
}
}
+// }}}
+// {{{ class PlSqlJoin
class PlSqlJoin
{
private $mode;
public function __construct($mode, $table, $condition)
{
if ($mode != self::MODE_LEFT && $mode != self::MODE_RIGHT && $mode != self::MODE_INNER) {
- Platal::page()->kill("Join mode error : unknown mode $mode");
+ Platal::page()->kill("Join mode error: unknown mode $mode");
return;
}
$this->mode = $mode;
{
$str = '';
foreach ($joins as $key => $join) {
- if (! ($join instanceof PlSqlJoin)) {
+ if (!($join instanceof PlSqlJoin)) {
Platal::page()->kill("Error: not a join: $join");
}
$mode = $join->mode();
return $str;
}
}
+// }}}
+// {{{ 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
*/
}
}
+// }}}
?>