3 class sml_data_authors extends mw_data{
5 # ----------------------------------------------------------------------------------------
9 public function groupes($id_user = null, $start = null, $alpha = null){
10 $sgbd = $this->sgbd();
12 $groupes = array("list" => array(), "total" => 0);
15 $FROM = " FROM #--sml_authors";
17 $WHERE .= (isset($id_user) ? ($WHERE ? " AND" : " WHERE")." id_user=".$id_user : "");
18 $WHERE .= (isset($alpha) ? ($WHERE ? " AND" : " WHERE")." LEFT(login, 1)=".$this->eq($alpha) : "");
19 $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : "");
20 $sql = "SELECT count(*) as n FROM(".$SELECT.$FROM.$WHERE.") res";
21 $rst = $sgbd->query($sql);
22 if($v_rst = $sgbd->fetch_assoc($rst)) $groupes["total"] = $v_rst["n"];
23 $sgbd->free_result($rst);
24 if($groupes["total"] > 0){
25 $sql = "SELECT * FROM(".$SELECT.$FROM.$WHERE.$LIMIT.") res";
26 $rst = $sgbd->query($sql);
27 while($v_rst = $sgbd->fetch_assoc($rst)){
28 if(!isset($v_rst["image"])) $v_rst["image"] = "";
29 $groupes["list"][$v_rst["id"]] = $v_rst;
30 $groupes["list"][$v_rst["id"]]["image_uri"] = (
32 $env->path("content")."uploads/".$v_rst["image"]
36 $sgbd->free_result($rst);
45 public function groupe($id){
46 $sgbd = $this->sgbd();
50 $sql = "SELECT * from #--sml_authors WHERE id=".$this->eq($id);
51 $rst = $sgbd->query($sql);
52 if($v_rst = $sgbd->fetch_assoc($rst)){
53 if(!isset($v_rst["image"])) $v_rst["image"] = "";
55 $groupe["image_uri"] = (
57 $env->path("content")."uploads/".$groupe["image"]
61 $sgbd->free_result($rst);
69 public function groupe_exists($nom, $other_than_id = null){
70 $sgbd = $this->sgbd();
73 $sql = "SELECT count(*) as n from #--sml_authors WHERE nom=".$this->eq($nom);
74 if(isset($other_than_id)) $sql .= " AND id!=".$this->eq($other_than_id);
75 $rst = $sgbd->query($sql);
76 if($v_rst = $sgbd->fetch_assoc($rst)) $EXISTS = $v_rst["n"];
77 $sgbd->free_result($rst);
85 public function add_groupe($id_user, $nom, $image, $description, $email, $contact_form, $captcha){
86 $sgbd = $this->sgbd();
89 "INSERT INTO #--sml_authors(id_user, nom, image, description, email, contact_form, captcha) VALUES"
90 ."( ".$this->eq($id_user)
92 .", ".$this->eq($image)
93 .", ".$this->eq($description)
94 .", ".$this->eq($email)
95 .", ".$this->eq($contact_form)
96 .", ".$this->eq($captcha)
106 public function set_groupe($id, $nom, $image, $description, $email, $contact_form, $captcha){
107 if(($groupe = $this->groupe($id)) === false) return false;
108 $sgbd = $this->sgbd();
111 "UPDATE #--sml_authors SET"
112 ." nom=".$this->eq($nom)
113 .", image=".$this->eq($image)
114 .", description=".$this->eq($description)
115 .", email=".$this->eq($email)
116 .", contact_form=".$this->eq($contact_form)
117 .", captcha=".$this->eq($captcha)
124 if($nom != $groupe["nom"]){
125 $groupe["nom"] = $nom;
126 if(!$this->maj_source_xml_groupe($groupe)) return false;
131 public function del_groupe($id){
132 $sgbd = $this->sgbd();
134 $sql = "SELECT count(*) as n FROM #--sml_sources_authors WHERE id_author=".$this->eq($id);
135 $rst = $sgbd->query($sql);
136 if($v_rst = $sgbd->fetch_assoc($rst)) $HAS_SOURCES = $v_rst["n"];
137 $sgbd->free_result($rst);
138 if($HAS_SOURCES) return 1;
139 $sql = "DELETE FROM #--sml_authors WHERE id=".$this->eq($id);