X-Git-Url: http://git.dj3c1t.com/index.cgi?a=blobdiff_plain;f=mw%2Fenv%2Fmodules%2Fmw_env_models.php;fp=mw%2Fenv%2Fmodules%2Fmw_env_models.php;h=757b53b95c3ce115f5a1d5f04a4fc589ba13171c;hb=5abc9d5fca28ef86dee6148bb96780d1a7b670f3;hp=0576268a58e1d889b92c66fcd68ed445d9a1087f;hpb=ed558d720ebf6985290c99297f5b1d2c86d1f60a;p=mtweb diff --git a/mw/env/modules/mw_env_models.php b/mw/env/modules/mw_env_models.php index 0576268..757b53b 100644 --- a/mw/env/modules/mw_env_models.php +++ b/mw/env/modules/mw_env_models.php @@ -2,7 +2,7 @@ class mw_env_models extends mw_env{ - function get_model($model_name, $default_values = array(), $RETURN_INSERT_ID = false){ + public function get_model($model_name, $default_values = array(), $RETURN_INSERT_ID = false){ $model_class_name = "mw_model_".$model_name; if(!class_exists($model_class_name)){ if($this->app_file_exists("data/models/".$model_name.".php")){ @@ -17,19 +17,33 @@ } + // ------------------------------------------------------------------------------------------- + // class mw_model + // + class mw_model{ - var $env; - var $model_name; - var $attributs; + public $env; + public $model_name; + public $attributs; + public $RETURN_INSERT_ID; - var $RETURN_INSERT_ID; + public function __construct(&$env, $model_name, $default_values = array(), $RETURN_INSERT_ID = false){ + $this->env = &$env; + $this->model_name = $model_name; + $this->attributs = array(); + $this->RETURN_INSERT_ID = $RETURN_INSERT_ID; + foreach($default_values as $attribut_name => $attribut_value){ + $set_function = "set_".$attribut_name; + $this->$set_function($attribut_value); + } + } - function env(){ + public function env(){ return $this->env; } - function get_values(){ + public function get_values(){ $values = array(); foreach($this->attributs as $attribut_name => $attribut){ $values[$attribut_name] = isset($attribut["value"]) ? $attribut["value"] : null; @@ -37,18 +51,7 @@ return $values; } - function mw_model(&$env, $model_name, $default_values = array(), $RETURN_INSERT_ID = false){ - $this->env = &$env; - $this->model_name = $model_name; - $this->attributs = array(); - $this->RETURN_INSERT_ID = $RETURN_INSERT_ID; - foreach($default_values as $attribut_name => $attribut_value){ - $set_function = "set_".$attribut_name; - $this->$set_function($attribut_value); - } - } - - function load($index_name, $index_value){ + public function load($index_name, $index_value){ if(!isset($this->model_name)) return false; $data = $this->env->data(); if( @@ -69,40 +72,7 @@ return true; } - function __call($method_name, $arguments){ - $r = false; - if(substr($method_name, 0, 4) == "get_"){ - if( - ($attribut_name = substr($method_name, 4)) - ){ - if(isset($this->attributs[$attribut_name]["value"])){ - $r = $this->attributs[$attribut_name]["value"]; - } - else $r = null; - } - } - elseif(substr($method_name, 0, 4) == "set_"){ - if( - ($attribut_name = substr($method_name, 4)) - && isset($arguments[0]) - ){ - if(!isset($this->attributs[$attribut_name])) $this->attributs[$attribut_name] = array(); - $this->attributs[$attribut_name]["value"] = $arguments[0]; - $r = true; - } - } - elseif(substr($method_name, 0, 6) == "valid_"){ - if( - ($attribut_name = substr($method_name, 6)) - && isset($arguments[0]) - ){ - $r = true; - } - } - return $r; - } - - function insert(){ + public function insert(){ if(!isset($this->model_name)) return false; $data = $this->env->data(); return $data->data_insert( @@ -114,7 +84,7 @@ ); } - function update($index_name, $index_value = null){ + public function update($index_name, $index_value = null){ if(!isset($this->model_name)) return false; $data = $this->env->data(); if(!isset($index_value)){ @@ -132,7 +102,7 @@ ); } - function delete($index_name, $index_value = null){ + public function delete($index_name, $index_value = null){ if(!isset($this->model_name)) return false; $data = $this->env->data(); if(!isset($index_value)){ @@ -149,7 +119,7 @@ ); } - function valid(){ + public function valid(){ $res = array( "VALID" => true, "messages" => array() @@ -165,6 +135,37 @@ return $res; } - } + public function __call($method_name, $arguments){ + $r = false; + if(substr($method_name, 0, 4) == "get_"){ + if( + ($attribut_name = substr($method_name, 4)) + ){ + if(isset($this->attributs[$attribut_name]["value"])){ + $r = $this->attributs[$attribut_name]["value"]; + } + else $r = null; + } + } + elseif(substr($method_name, 0, 4) == "set_"){ + if( + ($attribut_name = substr($method_name, 4)) + && isset($arguments[0]) + ){ + if(!isset($this->attributs[$attribut_name])) $this->attributs[$attribut_name] = array(); + $this->attributs[$attribut_name]["value"] = $arguments[0]; + $r = true; + } + } + elseif(substr($method_name, 0, 6) == "valid_"){ + if( + ($attribut_name = substr($method_name, 6)) + && isset($arguments[0]) + ){ + $r = true; + } + } + return $r; + } -?> \ No newline at end of file + }