X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fapp%2Fdata%2Fmodules%2Fsql%2Fmw_data_crud.php;h=f438ef1785742e1c3869295a39de6218d9e2645c;hb=refs%2Ftags%2Fmtweb.0.9.0;hp=9ac527ed574495027fe7dcdaa912b8c79a1051e5;hpb=7ad1ac4f506df343ef4127d7c56a846edd307374;p=mtweb diff --git a/mw/app/data/modules/sql/mw_data_crud.php b/mw/app/data/modules/sql/mw_data_crud.php index 9ac527e..f438ef1 100644 --- a/mw/app/data/modules/sql/mw_data_crud.php +++ b/mw/app/data/modules/sql/mw_data_crud.php @@ -3,6 +3,21 @@ class mw_data_crud extends mw_data{ # ---------------------------------------------------------------------------------------- + # description + # + + function data_desc($params = array()){ + $sgbd = $this->sgbd(); + $table_name = isset($params["table_name"]) ? $params["table_name"] : ""; + if(!$table_name) return false; + try{ + $desc = $sgbd->desc_table("#--".$table_name); + } + catch(Exception $e){ $desc = false; } + return $desc; + } + + # ---------------------------------------------------------------------------------------- # insert # @@ -20,7 +35,7 @@ $attributs_values .= ($attributs_values ? ", " : "").$this->eq($attribut_value); } $attributs_names = $attributs_names ? "(".$attributs_names.")" : ""; - $attributs_values = $attributs_values ? " VALUES (".$attributs_names.")" : ""; + $attributs_values = $attributs_values ? " VALUES (".$attributs_values.")" : ""; try{ $sgbd->query("INSERT INTO `#--".$table_name."`".$attributs_names.$attributs_values); $res = $return_insert_id ? $sgbd->insert_id() : true; @@ -36,8 +51,8 @@ function data_read($params = array()){ $sgbd = $this->sgbd(); $table_name = isset($params["table_name"]) ? $params["table_name"] : ""; - $index_name = isset($params[""]) ? $params["index_name"] : ""; - $index_value = isset($params[""]) ? $params["index_value"] : ""; + $index_name = isset($params["index_name"]) ? $params["index_name"] : ""; + $index_value = isset($params["index_value"]) ? $params["index_value"] : ""; if(!$table_name || !$index_name || !$index_value) return false; $item = array(); try{ @@ -51,6 +66,49 @@ } # ---------------------------------------------------------------------------------------- + # update + # + + function data_update($params = array()){ + $sgbd = $this->sgbd(); + $table_name = isset($params["table_name"]) ? $params["table_name"] : false; + $values = (isset($params["values"]) && is_array($params["values"])) ? $params["values"] : false; + $index_name = isset($params["index_name"]) ? $params["index_name"] : false; + $index_value = isset($params["index_value"]) && (strlen($params["index_value"]) > 0) ? $params["index_value"] : false; + if(!$table_name || !$index_name || !$index_value || !$values) return false; + try{ + $sql = "UPDATE `#--".$table_name."`"; + $set = ""; + foreach($values as $attribut_name => $attribut_value){ + $set .= ($set ? ", " : "")."`".$attribut_name."`=".$this->eq($attribut_value); + } + $set = $set ? " SET ".$set : ""; + $where = " WHERE `".$index_name."`=".$this->eq($index_value); + $sgbd->query($sql.$set.$where); + } + catch(Exception $e) { return false; } + return true; + } + + # ---------------------------------------------------------------------------------------- + # delete + # + + function data_delete($params = array()){ + $sgbd = $this->sgbd(); + $table_name = isset($params["table_name"]) ? $params["table_name"] : false; + $index_name = isset($params["index_name"]) ? $params["index_name"] : false; + $index_value = isset($params["index_value"]) ? $params["index_value"] : false; + if(!$table_name || !$index_name || !$index_value) return false; + try{ + $sql = "DELETE FROM `#--".$table_name."` WHERE `".$index_name."`=".$this->eq($index_value); + $sgbd->query($sql); + } + catch(Exception $e) { debug($e->getMessage()); return false; } + return true; + } + + # ---------------------------------------------------------------------------------------- # list # @@ -58,10 +116,45 @@ $sgbd = $this->sgbd(); $table_name = isset($params["table_name"]) ? $params["table_name"] : ""; if(!$table_name) return false; - $index_name = isset($params["index_name"]) ? $params["table_index"] : ""; + $index_name = isset($params["index_name"]) ? $params["index_name"] : ""; $select = "SELECT `#--".$table_name."`.*"; $from = " FROM `#--".$table_name."`"; $where = isset($params["where"]) ? " WHERE ".$params["where"] : ""; + if(isset($params["filters"])){ + foreach($params["filters"] as $filter){ + $and_where = ""; + if(isset($filter[0]) && isset($filter[1])){ + switch(strtolower($filter[1])){ + case "eq": + if(isset($filter[2])){ + $and_where .= ($where ? " AND " : " WHERE ").$filter[0]."=".$this->eq($filter[2]); + break; + } + case "lt": + if(isset($filter[2])){ + $and_where .= ($where ? " AND " : " WHERE ").$filter[0]."<".$this->eq($filter[2]); + break; + } + case "lte": + if(isset($filter[2])){ + $and_where .= ($where ? " AND " : " WHERE ").$filter[0].">=".$this->eq($filter[2]); + break; + } + case "gt": + if(isset($filter[2])){ + $and_where .= ($where ? " AND " : " WHERE ").$filter[0].">".$this->eq($filter[2]); + break; + } + case "gte": + if(isset($filter[2])){ + $and_where .= ($where ? " AND " : " WHERE ").$filter[0].">=".$this->eq($filter[2]); + break; + } + } + } + $where .= $and_where; + } + } $order = isset($params["order_by"]) ? " ORDER BY ".$params["order_by"].(isset($params["order"]) ? " ".$params["order"] : "") : ""; @@ -88,45 +181,6 @@ return $list; } - # ---------------------------------------------------------------------------------------- - # update - # - - function data_update($params = array()){ - $sgbd = $this->sgbd(); - $table_name = isset($params["table_name"]) ? $params["table_name"] : false; - $values = (isset($params["values"]) && is_array($params["values"])) ? $params["values"] : false; - $index_name = isset($params[""]) ? $params["index_name"] : false; - $index_value = isset($params[""]) ? $params["index_value"] : false; - if(!$table_name || !$index_name || !$index_value || !$values) return false; - try{ - $sql = "UPDATE `#--".$table_name."`"; - $set = ""; - foreach($values as $attribut_name => $attribut_value){ - $set .= ($set ? ", " : "")."`".$attribut_name."`=".$this->eq($attribut_value); - } - $set = $set ? " SET ".$set : ""; - $where = " WHERE `".$index_name."`=".$this->eq($index_value); - $sgbd->query($sql); - } - catch(Exception $e) { return false; } - return true; - } - - # ---------------------------------------------------------------------------------------- - # delete - # - - function data_delete($params = array()){ - $sgbd = $this->sgbd(); - try{ - $sql = "DELETE FROM `#--".$table_name."` WHERE `".$index_name."`=".$this->eq($index_value); - $sgbd->query($sql); - } - catch(Exception $e) { return false; } - return true; - } - } ?> \ No newline at end of file