diff options
author | Dmitry <dmitry@dhtmlx.com> | 2012-07-10 16:39:55 +0200 |
---|---|---|
committer | Dmitry <dmitry@dhtmlx.com> | 2012-07-10 16:39:55 +0200 |
commit | fb37b3dc462d73faead66b6c3d16cf5541bde57a (patch) | |
tree | a6e18055ddc1fb98fe6ceefece3decc888054b72 /codebase | |
parent | 7a6710c4918b843d303694b4625fbdff2f1ba742 (diff) | |
download | connector-php-fb37b3dc462d73faead66b6c3d16cf5541bde57a.zip connector-php-fb37b3dc462d73faead66b6c3d16cf5541bde57a.tar.gz connector-php-fb37b3dc462d73faead66b6c3d16cf5541bde57a.tar.bz2 |
easy api for filtering
Diffstat (limited to 'codebase')
-rw-r--r-- | codebase/base_connector.php | 14 | ||||
-rw-r--r-- | codebase/db_common.php | 9 |
2 files changed, 20 insertions, 3 deletions
diff --git a/codebase/base_connector.php b/codebase/base_connector.php index 8cf3625..9f0bb85 100644 --- a/codebase/base_connector.php +++ b/codebase/base_connector.php @@ -302,6 +302,7 @@ class Connector { protected $extra_output="";//!< extra info which need to be sent to client side protected $options=array();//!< hash of OptionsConnector protected $as_string = false; + protected $filters; /*! constructor @@ -331,6 +332,7 @@ class Connector { "render_class"=>$render_type ); $this->attributes = array(); + $this->filters = array(); $this->config = new DataConfig(); $this->request = new DataRequestConfig(); @@ -482,6 +484,7 @@ class Connector { $wrap->store(); $wrap = new FilterInterface($this->request); + $this->apply_filters($wrap); $this->event->trigger("beforeFilter",$wrap); $wrap->store(); @@ -797,6 +800,17 @@ class Connector { public function asString($as_string) { $this->as_string = $as_string; } + + public function filter($name, $value = false, $operation = '=') { + $this->filters[] = array('name' => $name, 'value' => $value, 'operation' => $operation); + } + + protected function apply_filters($wrap) { + for ($i = 0; $i < count($this->filters); $i++) { + $f = $this->filters[$i]; + $wrap->add($f['name'], $f['value'], $f['operation']); + } + } } diff --git a/codebase/db_common.php b/codebase/db_common.php index 8b5935a..91d3838 100644 --- a/codebase/db_common.php +++ b/codebase/db_common.php @@ -170,8 +170,11 @@ class DataRequestConfig{ @param operation operation for filtering, optional , LIKE by default */ - public function set_filter($field,$value,$operation=false){ - array_push($this->filters,array("name"=>$field,"value"=>$value,"operation"=>$operation)); + public function set_filter($field,$value=false,$operation=false){ + if ($value === false) + array_push($this->filters,$field); + else + array_push($this->filters,array("name"=>$field,"value"=>$value,"operation"=>$operation)); } /*! sets list of used fields @@ -672,7 +675,7 @@ abstract class DBDataWrapper extends DataWrapper{ public function sequence($sec){ $this->sequence=$sec; } - + /*! create an sql string for filtering rules |