From: Riton Date: Fri, 5 Nov 2010 20:39:48 +0000 (+0100) Subject: Added interface PlExportable and implemented it on PlFilter, PlFilterCondition and... X-Git-Tag: core/1.1.2~27 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=8e87570c0fee12a7528ee7857abe88bf74d2613c;p=platal.git Added interface PlExportable and implemented it on PlFilter, PlFilterCondition and PlFilterOrder Classes which implement PlExportable must expose an export() method. It should return an associative array representing the instance. Signed-off-by: Riton Signed-off-by: Florent Bruneau --- diff --git a/classes/plexportable.php b/classes/plexportable.php new file mode 100644 index 0000000..0f1545d --- /dev/null +++ b/classes/plexportable.php @@ -0,0 +1,39 @@ + diff --git a/classes/plfilter.php b/classes/plfilter.php index af8141d..1a6d525 100644 --- a/classes/plfilter.php +++ b/classes/plfilter.php @@ -53,7 +53,7 @@ class PlLimit * descending order). * The getSortTokens function is used to get actual ordering part of the query. */ -abstract class PlFilterOrder +abstract class PlFilterOrder implements PlExportable { protected $desc = false; public function __construct($desc = false) @@ -131,11 +131,19 @@ class PFO_Random extends PlFilterOrder return XDB::format('RAND({?})', $this->seed); } } + + public function export() + { + $export = array('type' => 'random',); + if ($this->seed !== null) + $export['seed'] = $this->seed; + return $export; + } } // }}} // {{{ interface PlFilterCondition -interface PlFilterCondition +interface PlFilterCondition extends PlExportable { const COND_TRUE = 'TRUE'; const COND_FALSE = 'FALSE'; @@ -160,6 +168,11 @@ abstract class PFC_OneChild implements PlFilterCondition { $this->child =& $cond; } + + public function export() + { + return array('child' => $child->export()); + } } // }}} @@ -197,6 +210,14 @@ abstract class PFC_NChildren implements PlFilterCondition return '(' . implode(') ' . $op . ' (', $cond) . ')'; } } + + public function export() + { + $export = array(); + foreach ($this->children as $child) + $export[] = $child->export(); + return array('children' => $export); + } } // }}} @@ -207,6 +228,11 @@ class PFC_True implements PlFilterCondition { return self::COND_TRUE; } + + public function export() + { + return array('type' => 'true'); + } } // }}} @@ -217,6 +243,11 @@ class PFC_False implements PlFilterCondition { return self::COND_FALSE; } + + public function export() + { + return array('type' => 'false'); + } } // }}} @@ -234,6 +265,13 @@ class PFC_Not extends PFC_OneChild return 'NOT (' . $val . ')'; } } + + public function export() + { + $export = parent::export(); + $export['type'] = 'not'; + return $export; + } } // }}} @@ -260,6 +298,12 @@ class PFC_And extends PFC_NChildren return $this->catConds($conds, 'AND', $true); } } + + public function export() { + $export = parent::export(); + $export['type'] = 'and'; + return $export; + } } // }}} @@ -286,11 +330,17 @@ class PFC_Or extends PFC_NChildren return $this->catConds($conds, 'OR', $true); } } + + public function export() { + $export = parent::export(); + $export['type'] = 'or'; + return $export; + } } // }}} // {{{ class PlFilter -abstract class PlFilter +abstract class PlFilter implements PlExportable { /** Filters objects matching the PlFilter * @param $objects The objects to filter