nouveau module "models" dans l'environnement
[mtweb] / mw / app / data / modules / share / mw_data_config.php
diff --git a/mw/app/data/modules/share/mw_data_config.php b/mw/app/data/modules/share/mw_data_config.php
new file mode 100644 (file)
index 0000000..2a8ae51
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+  class mw_data_config extends mw_data{
+
+    function config($key = null){
+      $value = false;
+      if(isset($key)){
+        $value = "";
+        if(
+          (
+            $config = $this->data_read(
+              array(
+                "table_name" => "config",
+                "index_name" => "key",
+                "index_value" => $key
+              )
+            )
+          ) === false
+        ) return false;
+        if(isset($config["value"])) $value = $config["value"];
+      }
+      else{
+        $value = array();
+        if(
+          (
+            $config_list = $this->data_list(
+              array(
+                "table_name" => "config",
+                "index_name" => "key"
+              )
+            )
+          ) === false
+        ) return false;
+        foreach($config_list["list"] as $config) $value[$config["key"]] = $config["value"];
+      }
+      return $value;
+    }
+
+    function config_exists($key){
+      if(
+        (
+          $config = $this->data_read(
+            array(
+              "table_name" => "config",
+              "index_name" => "key",
+              "index_value" => $key
+            )
+          )
+        ) === false
+      ) return false;
+      return $config ? 1 : 0;
+    }
+
+    function set_config($key, $value){
+      if(
+        (
+          $config = $this->data_read(
+            array(
+              "table_name" => "config",
+              "index_name" => "key",
+              "index_value" => $key
+            )
+          )
+        ) === false
+      ) return false;
+      if($config){
+        return $this->data_update(
+          array(
+            "table_name" => "config",
+            "index_name" => "key",
+            "index_value" => $key,
+            "values" => array(
+              "value" => $value
+            )
+          )
+        );
+      }
+      else{
+        return $this->data_insert(
+          array(
+            "table_name" => "config",
+            "values" => array(
+              "key" => $key,
+              "value" => $value
+            )
+          )
+        );
+      }
+    }
+
+    function del_config($key){
+      return $this->data_delete(
+        array(
+          "table_name" => "config",
+          "index_name" => "key",
+          "index_value" => $key
+        )
+      );
+    }
+
+  }
+
+?>
\ No newline at end of file