953ccfe936a61dd3e1df544c008c5ee7055fa9d4
[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                 if(!isset($groupes["list"][$id_groupe]["image"])) $groupes["list"][$id_groupe]["image"] = "";
42                 $groupes["list"][$id_groupe]["image_uri"] =
43                 ( $groupes["list"][$id_groupe]["image"] ?
44                     $env->path("content")."uploads/".$groupes["list"][$id_groupe]["image"]
45                   : ""
46                 );
47               }
48             }
49           }
50         }
51         else $groupes = false;
52       }
53       return $groupes;
54     }
55
56     function groupe($id){
57       if(!isset($this->groupes)) $this->groupes = array();
58       if(isset($this->groupes[$id])) return $this->groupes[$id];
59       $sgbd = $this->sgbd();
60       $env = $this->env();
61       if(($groupe = $sgbd->get_data("sml_authors", $id)) !== null){
62         if(!isset($groupe["image"])) $groupe["image"] = "";
63         $groupe["image_uri"] =
64         ( $groupe["image"] ?
65             $env->path("content")."uploads/".$groupe["image"]
66           : ""
67         );
68       }
69       else $groupe = false;
70       if($groupe != false) $this->groupes[$id] = $groupe;
71       return $groupe;
72     }
73
74     function groupe_exists($nom, $other_than_id = null)
75     { $sgbd = $this->sgbd();
76       $EXISTS = 0;
77       if($rst = $sgbd->open_data("sml_authors"))
78       { while($v_rst = $sgbd->fetch_data($rst))
79         { if(isset($v_rst))
80           { if(isset($v_rst["nom"]) && $v_rst["nom"] == $nom)
81             { if(isset($other_than_id))
82               { if($v_rst["id"] != $other_than_id) $EXISTS++;
83               }
84               else $EXISTS++;
85             }
86           }
87           else
88           { $EXISTS = false;
89             break;
90           }
91         }
92         $sgbd->close_data($rst);
93       }
94       return $EXISTS;
95     }
96
97     function add_groupe($id_user, $nom, $image, $description, $email, $contact_form, $captcha)
98     { $sgbd = $this->sgbd();
99       return $sgbd->add_data
100       ( "sml_authors",
101         array
102         ( "id_user" => $id_user,
103           "nom" => $nom,
104           "image" => $image,
105           "description" => $description,
106           "email" => $email,
107           "contact_form" => $contact_form,
108           "captcha" => $captcha
109         )
110       );
111     }
112
113     function set_groupe($id, $nom, $image, $description, $email, $contact_form, $captcha)
114     { if(($groupe = $this->groupe($id)) !== false)
115       { $sgbd = $this->sgbd();
116         if($nom != $groupe["nom"])
117         { $groupe["nom"] = $nom;
118           if(!$this->maj_source_xml_groupe($groupe)) return false;
119         }
120         return $sgbd->set_data
121         ( "sml_authors",
122           $id,
123           array
124           ( "id_user" => $groupe["id_user"],
125             "nom" => $nom,
126             "image" => $image,
127             "description" => $description,
128             "email" => $email,
129             "contact_form" => $contact_form,
130             "captcha" => $captcha
131           )
132         );
133       }
134       return false;
135     }
136
137     function del_groupe($id)
138     { $OK = true;
139       $USED = false;
140       $sgbd = $this->sgbd();
141       $env = $this->env();
142       if($rst = $sgbd->open_data("sml_sources_authors"))
143       { while($source_author = $sgbd->fetch_data($rst))
144         { if(isset($source_author))
145           { if($source_author["id_author"] == $id)
146             { $USED = true;
147               break;
148             }
149           }
150           else
151           { $OK = false;
152             break;
153           }
154         }
155         $sgbd->close_data($rst);
156       }
157       else $OK = false;
158       if($OK)
159       { if($USED) return 1;
160         return $sgbd->del_data("sml_authors", $id) ? true : false;
161       }
162       return false;
163     }
164
165   }
166
167 ?>