public attr / function, constructeurs __construct
[mtweb] / mw / env / modules / mw_env_models.php
index 0576268..757b53b 100644 (file)
@@ -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")){
 
   }
 
+  // -------------------------------------------------------------------------------------------
+  //                                                                              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;
       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(
       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(
       );
     }
 
-    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)){
       );
     }
 
-    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)){
       );
     }
 
-    function valid(){
+    public function valid(){
       $res = array(
         "VALID" => true,
         "messages" => array()
       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
+  }