59a7cc02c0a2eb618c8a4efcf5af9c00a56cd921
[mtweb] / mw / app / data / modules / share / mw_data_auto_crud.php
1 <?php
2
3   class mw_data_auto_crud extends mw_data{
4
5     function call_data_auto_crud($method_name, $arguments){
6       $r = false;
7       $sgbd = $this->sgbd();
8       // desc_<table_name>()
9       if(
10             (substr($method_name, 0, 5) == "desc_")
11         &&  ($table_name = substr($method_name, 5))
12         &&  ($sgbd->table_exists("#--".$table_name))
13       ){
14         $r = $this->data_desc(
15           array(
16             "table_name" => $table_name
17           )
18         );
19       }
20       // add_<table_name>(array $values)
21       if(
22             (substr($method_name, 0, 4) == "add_")
23         &&  ($table_name = substr($method_name, 4))
24         &&  ($sgbd->table_exists("#--".$table_name))
25       ){
26         $r = $this->data_insert(
27           array(
28             "table_name" => $table_name,
29             "values" => $arguments[0]
30           )
31         );
32       }
33       // get_<table_name>(string $index_name, string $index_value)
34       elseif(
35             (substr($method_name, 0, 4) == "get_")
36         &&  ($table_name = substr($method_name, 4))
37         &&  ($sgbd->table_exists("#--".$table_name))
38       ){
39         $r = $this->data_read(
40           array(
41             "table_name" => $table_name,
42             "index_name" => $arguments[0],
43             "index_value" => $arguments[1]
44           )
45         );
46       }
47       // list_<table_name>(array $params)
48       elseif(
49             (substr($method_name, 0, 5) == "list_")
50         &&  ($table_name = substr($method_name, 5))
51         &&  ($sgbd->table_exists("#--".$table_name))
52       ){
53         $params = $arguments[0];
54         $params["table_name"] = $table_name;
55         $r = $this->data_list($params);
56       }
57       // set_<table_name>(string index_name, string index_value, array $values)
58       elseif(
59             (substr($method_name, 0, 4) == "set_")
60         &&  ($table_name = substr($method_name, 4))
61         &&  ($sgbd->table_exists("#--".$table_name))
62       ){
63         $r = $this->data_update(
64           array(
65             "table_name" => $table_name,
66             "index_name" => $arguments[0],
67             "index_value" => $arguments[1],
68             "values" => $arguments[2]
69           )
70         );
71       }
72       // del_<table_name>(string $index_name, string $index_value)
73       elseif(
74             (substr($method_name, 0, 4) == "del_")
75         &&  ($table_name = substr($method_name, 4))
76         &&  ($sgbd->table_exists("#--".$table_name))
77       ){
78         $r = $this->data_delete(
79           array(
80             "table_name" => $table_name,
81             "index_name" => $arguments[0],
82             "index_value" => $arguments[1]
83           )
84         );
85       }
86       return $r;
87     }
88
89   }
90
91 ?>