00001 <?php
00002
00003
00004
00005
00006
00007
00008 class FilterText implements IDBQueryModifier {
00009
00010
00011
00012
00013 protected $filter_object;
00014
00015
00016
00017 protected $adapter;
00018 protected $page_data;
00019
00020
00021
00022
00023
00024
00025
00026 public function __construct($page_data, $filtercolumn, $filtername, $operator, $adapter = false) {
00027 $this->adapter = ($adapter instanceof IFilterTextAdapter) ? $adapter : new FilterTextDefaultAdapter($page_data, String::plain_ascii($filtername));
00028 $this->page_data = $page_data;
00029 $this->filter_object = new DBFilterColumn(
00030 $filtercolumn,
00031 $this->adapter->get_value(),
00032 tr($filtername, 'app'),
00033 $operator
00034 );
00035 }
00036
00037
00038
00039
00040 public function apply($query) {
00041 if ($this->get_filter_value()) {
00042 $this->filter_object->apply($query);
00043 }
00044 }
00045
00046
00047
00048
00049
00050
00051 public function get_filter_title() {
00052 return $this->filter_object->get_title();
00053 }
00054
00055
00056
00057
00058
00059
00060 public function get_filter_value() {
00061 return $this->filter_object->get_value();
00062 }
00063
00064
00065
00066
00067
00068
00069 public function prepare_view($view) {
00070 $var_name = $this->get_view_var_name();
00071 $textfilter_data = Arr::force($view->retrieve($var_name), false);
00072 $textfilter_data[] = array(
00073 'title' => $this->get_filter_title(),
00074 'value' => $this->get_filter_value(),
00075 'filter_object' => $this->filter_object,
00076 'adapter' => $this->adapter,
00077 'page_data' => $this->page_data
00078 );
00079 $view->assign($var_name, $textfilter_data);
00080 }
00081
00082
00083
00084
00085
00086
00087 protected function get_view_var_name() {
00088 return 'filtertext_data';
00089 }
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 class FilterTextDefaultAdapter implements IFilterTextAdapter {
00102 protected $param;
00103 protected $page_data;
00104
00105 public function __construct($page_data, $param, $prefix = 'filter_') {
00106 $this->page_data = $page_data;
00107 $this->param = $prefix . $param;
00108 }
00109
00110
00111
00112
00113
00114
00115 public function get_value() {
00116 $reset = $this->page_data->get_get()->get_item($this->get_reset_param(), false);
00117 return ($reset) ? '' : $this->page_data->get_get()->get_item($this->get_param(), '');
00118 }
00119
00120 public function get_param() {
00121 return $this->param;
00122 }
00123
00124 public function get_reset_param() {
00125 return $this->param . '_reset_filter';
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 public static function apply_to_url($url, $value, $parameter) {
00139 $url->replace_query_parameter($parameter, $value);
00140 }
00141 }
00142