marche avec MySql, SQLite ou XML
[mw_sourceml] / app / data / modules / xml / sml_data_authors.php
1 <?php
2
3   class sml_data_authors extends mw_data
4   {
5
6     var $groupes;
7
8     # ----------------------------------------------------------------------------------------
9     #                                                                                  groupes
10     #
11
12     function groupes($id_user = null, $start = null, $alpha = null)
13     { $sgbd = $this->sgbd();
14       $env = $this->env();
15       $groupes = array("list" => array(), "total" => 0);
16       if(true || isset($id_user))
17       { if($rst = $sgbd->open_data("sml_authors"))
18         { while($v_rst = $sgbd->fetch_data($rst))
19           { if(isset($v_rst))
20             { if(!isset($alpha) || (isset($v_rst["nom"]) && substr($v_rst["nom"], 0, 1) == $alpha))
21               { if(!isset($id_user) || (isset($v_rst["id_user"]) && $v_rst["id_user"] == $id_user))
22                 { $groupes["total"]++;
23                   $groupes["list"][$v_rst["id"]] = $v_rst;
24                 }
25               }
26             }
27             else
28             { $groupes = false;
29               break;
30             }
31           }
32           $sgbd->close_data($rst);
33           if($groupes !== false)
34           { $n = -1;
35             foreach($groupes["list"] as $id_groupe => $groupe)
36             { $n++;
37               if(isset($start) && $env->config("max_list") && ($n < $start || $n >= ($start + $env->config("max_list"))))
38               { unset($groupes["list"][$id_groupe]);
39               }
40               else
41               { $groupes["list"][$id_groupe]["image_uri"] =
42                 ( $groupe["image"] ?
43                     $env->path("content")."uploads/".$groupe["image"]
44                   : ""
45                 );
46               }
47             }
48           }
49         }
50         else $groupes = false;
51       }
52       return $groupes;
53     }
54
55     function groupe($id)
56     { if(!isset($this->groupes)) $this->groupes = array();
57       if(isset($this->groupes[$id])) return $this->groupes[$id];
58       $sgbd = $this->sgbd();
59       $env = $this->env();
60       if(($groupe = $sgbd->get_data("sml_authors", $id)) !== null)
61       { $groupe["image_uri"] =
62         ( $groupe["image"] ?
63             $env->path("content")."uploads/".$groupe["image"]
64           : ""
65         );
66       }
67       else $groupe = false;
68       if($groupe != false) $this->groupes[$id] = $groupe;
69       return $groupe;
70     }
71
72     function groupe_exists($nom, $other_than_id = null)
73     { $sgbd = $this->sgbd();
74       $EXISTS = 0;
75       if($rst = $sgbd->open_data("sml_authors"))
76       { while($v_rst = $sgbd->fetch_data($rst))
77         { if(isset($v_rst))
78           { if(isset($v_rst["nom"]) && $v_rst["nom"] == $nom)
79             { if(isset($other_than_id))
80               { if($v_rst["id"] != $other_than_id) $EXISTS++;
81               }
82               else $EXISTS++;
83             }
84           }
85           else
86           { $EXISTS = false;
87             break;
88           }
89         }
90         $sgbd->close_data($rst);
91       }
92       return $EXISTS;
93     }
94
95     function add_groupe($id_user, $nom, $image, $description, $email, $contact_form, $captcha)
96     { $sgbd = $this->sgbd();
97       return $sgbd->add_data
98       ( "sml_authors",
99         array
100         ( "id_user" => $id_user,
101           "nom" => $nom,
102           "image" => $image,
103           "description" => $description,
104           "email" => $email,
105           "contact_form" => $contact_form,
106           "captcha" => $captcha
107         )
108       );
109     }
110
111     function set_groupe($id, $nom, $image, $description, $email, $contact_form, $captcha)
112     { if(($groupe = $this->groupe($id)) !== false)
113       { $sgbd = $this->sgbd();
114         if($nom != $groupe["nom"])
115         { $groupe["nom"] = $nom;
116           if(!$this->maj_source_xml_groupe($groupe)) return false;
117         }
118         return $sgbd->set_data
119         ( "sml_authors",
120           $id,
121           array
122           ( "id_user" => $groupe["id_user"],
123             "nom" => $nom,
124             "image" => $image,
125             "description" => $description,
126             "email" => $email,
127             "contact_form" => $contact_form,
128             "captcha" => $captcha
129           )
130         );
131       }
132       return false;
133     }
134
135     function del_groupe($id)
136     { $OK = true;
137       $USED = false;
138       $sgbd = $this->sgbd();
139       $env = $this->env();
140       if($rst = $sgbd->open_data("sml_sources_authors"))
141       { while($source_author = $sgbd->fetch_data($rst))
142         { if(isset($source_author))
143           { if($source_author["id_author"] == $id)
144             { $USED = true;
145               break;
146             }
147           }
148           else
149           { $OK = false;
150             break;
151           }
152         }
153         $sgbd->close_data($rst);
154       }
155       else $OK = false;
156       if($OK)
157       { if($USED) return 1;
158         return $sgbd->del_data("sml_authors", $id) ? true : false;
159       }
160       return false;
161     }
162
163   }
164
165 ?>