3 class mw_data_xml_crud extends mw_data{
5 # ----------------------------------------------------------------------------------------
9 public function data_insert($params = array()){
10 $table_name = isset($params["table_name"]) ? $params["table_name"] : "";
11 if(!$table_name) return false;
12 $values = (isset($params["values"]) && is_array($params["values"])) ? $params["values"] : false;
13 if(!$values) return false;
14 $sgbd = $this->sgbd();
15 if(($id = $sgbd->add_data($table_name, $values)) === false) return false;
19 # ----------------------------------------------------------------------------------------
23 public function data_read($params = array()){
24 $sgbd = $this->sgbd();
25 $table_name = isset($params["table_name"]) ? $params["table_name"] : "";
26 $index_name = isset($params["index_name"]) ? $params["index_name"] : "";
27 $index_value = isset($params["index_value"]) ? $params["index_value"] : "";
28 if(!$table_name || !$index_name || !$index_value) return false;
30 if($rst = $sgbd->open_data($table_name)){
31 while($v_rst = $sgbd->fetch_data($rst)){
33 if(isset($v_rst[$index_name]) && ($v_rst[$index_name] == $index_value)){
38 $sgbd->close_data($rst);
42 $sgbd->close_data($rst);
48 # ----------------------------------------------------------------------------------------
52 public function data_update($params = array()){
53 $sgbd = $this->sgbd();
54 $table_name = isset($params["table_name"]) ? $params["table_name"] : false;
55 $values = (isset($params["values"]) && is_array($params["values"])) ? $params["values"] : false;
56 $index_name = isset($params["index_name"]) ? $params["index_name"] : false;
57 $index_value = isset($params["index_value"]) && (strlen($params["index_value"]) > 0) ? $params["index_value"] : false;
58 if(!$table_name || !$index_name || !$index_value || !$values) return false;
59 if($rst = $sgbd->open_data($table_name)){
60 while($v_rst = $sgbd->fetch_data($rst)){
62 if(isset($v_rst["id"]) && isset($v_rst[$index_name]) && ($v_rst[$index_name] == $index_value)){
63 foreach($values as $attribut_name => $attribut_value){
64 $v_rst[$attribut_name] = $attribut_value;
65 if(!$sgbd->set_data($table_name, $v_rst["id"], $v_rst)){
66 $sgbd->close_data($rst);
73 $sgbd->close_data($rst);
77 $sgbd->close_data($rst);
83 # ----------------------------------------------------------------------------------------
87 public function data_delete($params = array()){
88 $sgbd = $this->sgbd();
89 $table_name = isset($params["table_name"]) ? $params["table_name"] : false;
90 $index_name = isset($params["index_name"]) ? $params["index_name"] : false;
91 $index_value = isset($params["index_value"]) && (strlen($params["index_value"]) > 0) ? $params["index_value"] : false;
92 if(!$table_name || !$index_name || !$index_value) return false;
93 if($rst = $sgbd->open_data($table_name)){
94 while($v_rst = $sgbd->fetch_data($rst)){
96 if(isset($v_rst["id"]) && isset($v_rst[$index_name]) && ($v_rst[$index_name] == $index_value)){
97 if(!$sgbd->del_data($table_name, $v_rst["id"])){
98 $sgbd->close_data($rst);
104 $sgbd->close_data($rst);
108 $sgbd->close_data($rst);
114 # ----------------------------------------------------------------------------------------
118 public function data_list($params = array()){
119 $sgbd = $this->sgbd();
120 $table_name = isset($params["table_name"]) ? $params["table_name"] : "";
121 if(!$table_name) return false;
122 $index_name = isset($params["index_name"]) ? $params["index_name"] : "";
123 $order_by = isset($params["order_by"]) ? $params["order_by"] : null;
124 $order = isset($params["order"]) ? $params["order"] : "ASC";
125 $limit = isset($params["limit"]) ? $params["limit"] : null;
126 $offset = isset($params["offset"]) ? $params["offset"] : null;
127 $list = array("list" => array(), "total" => 0);
128 $filters = isset($params["filters"]) ? $params["filters"] : array();
129 $list = array("list" => array(), "total" => 0);
131 if($rst = $sgbd->open_data($table_name)){
132 while($v_rst = $sgbd->fetch_data($rst)){
133 if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst;
139 $sgbd->close_data($rst);
140 if($res === false) return false;
141 if(isset($order_by)) $res = $this->ordonne($res, $order_by, $order);
142 foreach($res as $id_res => $v_rst){
144 foreach($filters as $filter){
145 $FILTER_MATCH = false;
146 if(isset($filter[0]) && isset($v_rst[$filter[0]]) && isset($filter[1])){
147 switch(strtolower($filter[1])){
149 if(isset($filter[2])){
150 $FILTER_MATCH = ($v_rst[$filter[0]] == $filter[2]);
154 if(isset($filter[2])){
155 $FILTER_MATCH = ($v_rst[$filter[0]] < $filter[2]);
159 if(isset($filter[2])){
160 $FILTER_MATCH = ($v_rst[$filter[0]] <= $filter[2]);
164 if(isset($filter[2])){
165 $FILTER_MATCH = ($v_rst[$filter[0]] > $filter[2]);
169 if(isset($filter[2])){
170 $FILTER_MATCH = ($v_rst[$filter[0]] >= $filter[2]);
182 if(isset($offset)) $MATCH = $list["total"] > $offset;
183 if($MATCH && isset($limit)) $MATCH = $list["total"] <= $limit;
185 if($MATCH) $list["list"][$v_rst[$index_name ? $index_name : "id"]] = $v_rst;
186 if(isset($limit) && ($list["total"] > $limit)) break;