adaptations pour pludieurs instances d'applications
[mtweb] / mw / app / data / modules / share / mw_data_config.php
1 <?php
2
3   class mw_data_config extends mw_data{
4
5     function config($key = null){
6       $value = false;
7       if(isset($key)){
8         $value = "";
9         if(
10           (
11             $config = $this->data_read(
12               array(
13                 "table_name" => "config",
14                 "index_name" => "key",
15                 "index_value" => $key
16               )
17             )
18           ) === false
19         ) return false;
20         if(isset($config["value"])) $value = $config["value"];
21       }
22       else{
23         $value = array();
24         if(
25           (
26             $config_list = $this->data_list(
27               array(
28                 "table_name" => "config",
29                 "index_name" => "key"
30               )
31             )
32           ) === false
33         ) return false;
34         foreach($config_list["list"] as $config) $value[$config["key"]] = $config["value"];
35       }
36       return $value;
37     }
38
39     function config_exists($key){
40       if(
41         (
42           $config = $this->data_read(
43             array(
44               "table_name" => "config",
45               "index_name" => "key",
46               "index_value" => $key
47             )
48           )
49         ) === false
50       ) return false;
51       return $config ? 1 : 0;
52     }
53
54     function set_config($key, $value){
55       if(
56         (
57           $config = $this->data_read(
58             array(
59               "table_name" => "config",
60               "index_name" => "key",
61               "index_value" => $key
62             )
63           )
64         ) === false
65       ) return false;
66       if($config){
67         return $this->data_update(
68           array(
69             "table_name" => "config",
70             "index_name" => "key",
71             "index_value" => $key,
72             "values" => array(
73               "value" => $value
74             )
75           )
76         );
77       }
78       else{
79         return $this->data_insert(
80           array(
81             "table_name" => "config",
82             "values" => array(
83               "key" => $key,
84               "value" => $value
85             )
86           )
87         );
88       }
89     }
90
91     function del_config($key){
92       return $this->data_delete(
93         array(
94           "table_name" => "config",
95           "index_name" => "key",
96           "index_value" => $key
97         )
98       );
99     }
100
101   }
102
103 ?>