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