diff options
author | Dmitry <dmitry@dhtmlx.com> | 2012-07-10 17:19:45 +0200 |
---|---|---|
committer | Dmitry <dmitry@dhtmlx.com> | 2012-07-10 17:19:45 +0200 |
commit | 39a85a6361a2de94c5528344ec88eaed614d743b (patch) | |
tree | eb93300681ec90adee33a4838e662965d26abea3 /codebase | |
parent | fb37b3dc462d73faead66b6c3d16cf5541bde57a (diff) | |
download | connector-php-39a85a6361a2de94c5528344ec88eaed614d743b.zip connector-php-39a85a6361a2de94c5528344ec88eaed614d743b.tar.gz connector-php-39a85a6361a2de94c5528344ec88eaed614d743b.tar.bz2 |
easy sort api
Diffstat (limited to 'codebase')
-rw-r--r-- | codebase/base_connector.php | 19 | ||||
-rw-r--r-- | codebase/db_common.php | 12 |
2 files changed, 27 insertions, 4 deletions
diff --git a/codebase/base_connector.php b/codebase/base_connector.php index 9f0bb85..b3dddb9 100644 --- a/codebase/base_connector.php +++ b/codebase/base_connector.php @@ -109,7 +109,10 @@ class SortInterface extends EventInterface{ direction of sorting */ public function add($name,$dir){ - $this->request->set_sort($name,$dir); + if ($dir === false) + $this->request->set_sort($name); + else + $this->request->set_sort($name,$dir); } public function store(){ $this->request->set_sort_by($this->rules); @@ -303,6 +306,7 @@ class Connector { protected $options=array();//!< hash of OptionsConnector protected $as_string = false; protected $filters; + protected $sorts; /*! constructor @@ -333,6 +337,7 @@ class Connector { ); $this->attributes = array(); $this->filters = array(); + $this->sorts = array(); $this->config = new DataConfig(); $this->request = new DataRequestConfig(); @@ -480,6 +485,7 @@ class Connector { die(); } $wrap = new SortInterface($this->request); + $this->apply_sorts($wrap); $this->event->trigger("beforeSort",$wrap); $wrap->store(); @@ -811,6 +817,17 @@ class Connector { $wrap->add($f['name'], $f['value'], $f['operation']); } } + + public function sort($name, $direction = false) { + $this->sorts[] = array('name' => $name, 'direction' => $direction); + } + + protected function apply_sorts($wrap) { + for ($i = 0; $i < count($this->sorts); $i++) { + $s = $this->sorts[$i]; + $wrap->add($s['name'], $s['direction']); + } + } } diff --git a/codebase/db_common.php b/codebase/db_common.php index 91d3838..2ae9b22 100644 --- a/codebase/db_common.php +++ b/codebase/db_common.php @@ -157,8 +157,12 @@ class DataRequestConfig{ if (!$field && !$order) $this->sort_by=array(); else{ - $order=strtolower($order)=="asc"?"ASC":"DESC"; - $this->sort_by[]=array("name"=>$field,"direction" => $order); + if ($order===false) + $this->sort_by[] = $field; + else { + $order=strtolower($order)=="asc"?"ASC":"DESC"; + $this->sort_by[]=array("name"=>$field,"direction" => $order); + } } } /*! sets filtering rule @@ -713,7 +717,9 @@ abstract class DBDataWrapper extends DataWrapper{ if (!sizeof($by)) return ""; $out = array(); for ($i=0; $i < sizeof($by); $i++) - if ($by[$i]["name"]) + if (is_string($by[$i])) + $out[] = $by[$i]; + else if ($by[$i]["name"]) $out[]=$this->escape_name($by[$i]["name"])." ".$by[$i]["direction"]; return implode(",",$out); } |