class mw_data_crud extends mw_data{
# ----------------------------------------------------------------------------------------
+ # call_crud
+ #
+
+ function call_data_crud($method_name, $arguments){
+ $r = false;
+ $sgbd = $this->sgbd();
+ // add_<table_name>(array $values)
+ if(
+ (substr($method_name, 0, 4) == "add_")
+ && ($table_name = substr($method_name, 4))
+ && ($sgbd->table_exists("#--".$table_name))
+ ){
+ $r = $this->data_insert(
+ array(
+ "values" => $arguments[0],
+ "table_name" => $table_name
+ )
+ );
+ }
+ // get_<table_name>(string $index_name, string $index_value)
+ elseif(
+ (substr($method_name, 0, 4) == "get_")
+ && ($table_name = substr($method_name, 4))
+ && ($sgbd->table_exists("#--".$table_name))
+ ){
+ $r = $this->data_read(
+ array(
+ "table_name" => $table_name,
+ "index_name" => $arguments[0],
+ "index_value" => $arguments[1]
+ )
+ );
+ }
+ // list_<table_name>(array $params)
+ elseif(
+ (substr($method_name, 0, 5) == "list_")
+ && ($table_name = substr($method_name, 5))
+ && ($sgbd->table_exists("#--".$table_name))
+ ){
+ $params = $arguments[0];
+ $params["table_name"] = $table_name;
+ $r = $this->data_list($params);
+ }
+ // set_<table_name>(string index_name, string index_value, array $values)
+ elseif(
+ (substr($method_name, 0, 4) == "set_")
+ && ($table_name = substr($method_name, 4))
+ && ($sgbd->table_exists("#--".$table_name))
+ ){
+ $r = $this->data_update(
+ array(
+ "table_name" => $table_name,
+ "index_name" => $arguments[0],
+ "index_value" => $arguments[1],
+ "values" => $arguments[2]
+ )
+ );
+ }
+ // del_<table_name>(string $index_name, string $index_value)
+ elseif(
+ (substr($method_name, 0, 4) == "del_")
+ && ($table_name = substr($method_name, 4))
+ && ($sgbd->table_exists("#--".$table_name))
+ ){
+ $r = $this->data_delete(
+ array(
+ "table_name" => $table_name,
+ "index_name" => $arguments[0],
+ "index_value" => $arguments[1]
+ )
+ );
+ }
+ return $r;
+ }
+
+ # ----------------------------------------------------------------------------------------
# insert
#
$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;
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{
$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"] : "";
$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;
+ $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 || !$values) return false;
try{
$sql = "UPDATE `#--".$table_name."`";
}
$set = $set ? " SET ".$set : "";
$where = " WHERE `".$index_name."`=".$this->eq($index_value);
- $sgbd->query($sql);
+ $sgbd->query($sql.$set.$where);
}
catch(Exception $e) { return false; }
return true;
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);
function empty_class_call($inst, $method_name, $arguments){
$r = false;
- $args = "";
- foreach($arguments as $i => $arg) $args .= ($args ? ", " : "")."\$arguments[".$i."]";
- if(isset($inst->modules)) foreach($inst->modules as $module_name => $module){
- if(method_exists($module, $method_name)){
- eval("\$r = \$module->".$method_name."(".$args.");");
+ if(($module = $this->get_module_for_method($inst, $method_name)) !== false){
+ $args = ""; foreach($arguments as $i => $arg) $args .= ($args ? ", " : "")."\$arguments[".$i."]";
+ eval("\$r = \$module->".$method_name."(".$args.");");
+ }
+ else $r = $this->call_default($inst, $method_name, $arguments);
+ return $r;
+ }
+
+ function get_module_for_method($inst, $method_name){
+ $module = false;
+ if(isset($inst->modules)) foreach($inst->modules as $module_name => $module_impl){
+ if(method_exists($module_impl, $method_name)){
+ $module = $module_impl;
break;
}
else{
- $r = $this->empty_class_call($module, $method_name, $arguments);
- if($r !== false) break;
+ $module = $this->get_module_for_method($module_impl, $method_name);
+ if($module !== false) break;
}
}
- return $r;
+ return $module;
+ }
+
+ function call_default($inst, $method_name, $arguments){
+ return false;
}
}