00001 <?php
00002 require_once dirname(__FILE__) . '/dbfilter.cls.php';
00003
00004
00005
00006
00007
00008
00009
00010
00011 class DBFilterGroup implements IDBQueryModifier {
00012
00013
00014
00015 protected $filters = array();
00016 protected $name = '';
00017 protected $group_key = '';
00018 protected $key_default_filter = '';
00019 protected $key_current_filter = '';
00020
00021
00022
00023
00024
00025
00026 public function __construct($key = '', $name = '', $filters = array(), $default = '') {
00027 $this->name = $name;
00028 $this->group_key = $key;
00029 foreach($filters as $key => $value) {
00030 $this->add_filter(strval($key), $value);
00031 }
00032 $this->set_default_key($default);
00033 $this->set_current_key($default);
00034 }
00035
00036
00037
00038
00039 public function get_name() {
00040 return $this->name;
00041 }
00042
00043
00044
00045
00046 public function get_group_id() {
00047 return $this->group_key;
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 public function add_filter($key, $filter) {
00057 $filter->set_key($key);
00058 $this->filters[$key] = $filter;
00059 }
00060
00061
00062
00063
00064 public function get_filter($key) {
00065 return Arr::get_item($this->filters, $key, false);
00066 }
00067
00068
00069
00070
00071 public function get_keys() {
00072 return array_keys($this->filters);
00073 }
00074
00075
00076
00077
00078 public function get_filters() {
00079 return array_values($this->filters);
00080 }
00081
00082
00083
00084
00085 public function count() {
00086 return count($this->filters);
00087 }
00088
00089
00090
00091
00092 public function set_default_key($key) {
00093 $this->key_default_filter = $key;
00094 foreach($this->filters as $f) {
00095 $f->set_is_default($f->get_key() == $key);
00096 }
00097 }
00098
00099
00100
00101
00102 public function get_default_key() {
00103 return $this->key_default_filter;
00104 }
00105
00106
00107
00108
00109 public function set_current_key($key) {
00110 $this->key_current_filter = $key;
00111 }
00112
00113
00114
00115
00116 public function get_current_key() {
00117 return $this->key_current_filter;
00118 }
00119
00120
00121
00122
00123
00124
00125 public function get_current_filter() {
00126 $ret = $this->get_filter($this->get_current_key());
00127 if ($ret == false) {
00128 $ret = $this->get_filter($this->get_default_key());
00129 }
00130 return $ret;
00131 }
00132
00133
00134
00135
00136 public function apply($query) {
00137 $query->apply_modifier($this->get_current_filter());
00138 }
00139 }