1 | <?php |
---|
2 | |
---|
3 | class da_albums extends data |
---|
4 | { |
---|
5 | |
---|
6 | function artiste_albums($id_artiste, $actif = null) |
---|
7 | { $albums = array(); |
---|
8 | try |
---|
9 | { $sql = "SELECT * FROM #--albums WHERE id_artiste=".$this->eq($id_artiste); |
---|
10 | if(isset($actif)) $sql .= " AND actif=".($actif ? "1" : "0"); |
---|
11 | $sql .= " ORDER BY ordre ASC"; |
---|
12 | $rst = $this->sql->query($sql); |
---|
13 | while($v_rst = $this->sql->fetch_assoc($rst)) $albums[$v_rst["id"]] = $v_rst; |
---|
14 | $this->sql->free_result($rst); |
---|
15 | } |
---|
16 | catch(Exception $_e) { $albums = false; } |
---|
17 | return $albums; |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | |
---|
22 | $max === null : la requete recupere tous les resultats |
---|
23 | $max === true : la requete recupere $this->env->config("max_list") resultats |
---|
24 | $max === n : la requete recupere n resultats |
---|
25 | |
---|
26 | **/ |
---|
27 | |
---|
28 | function albums($start = 0, $max = null, $order_by = null, $order = null, $WHERE = "") |
---|
29 | { $albums = array(); |
---|
30 | try |
---|
31 | { $sql = |
---|
32 | "SELECT #--albums.*, #--artistes.nom as artiste, #--artistes.id as id_artiste FROM #--albums, #--artistes" |
---|
33 | ." WHERE #--albums.id_artiste=#--artistes.id" |
---|
34 | .($WHERE ? " AND ".$WHERE : "") |
---|
35 | .(isset($order_by) ? " ORDER BY ".$order_by.(isset($order) ? " ".$order: "") : "") |
---|
36 | .( isset($max) ? |
---|
37 | ( $max === true ? |
---|
38 | ($this->env->config("max_list") ? " LIMIT ".$start.",".$this->env->config("max_list") : "") |
---|
39 | : " LIMIT ".$start.",".$max |
---|
40 | ) |
---|
41 | : "" |
---|
42 | ); |
---|
43 | $rst = $this->sql->query($sql); |
---|
44 | while($v_rst = $this->sql->fetch_assoc($rst)) $albums[$v_rst["id"]] = $v_rst; |
---|
45 | $this->sql->free_result($rst); |
---|
46 | } |
---|
47 | catch(Exception $_e) { $albums = false; } |
---|
48 | return $albums; |
---|
49 | } |
---|
50 | |
---|
51 | function set_artiste_albums($id_artiste, $ordre, $actif) |
---|
52 | { if(($albums = $this->artiste_albums($id_artiste)) !== false) |
---|
53 | { try |
---|
54 | { foreach($albums as $id => $album) |
---|
55 | { $query = |
---|
56 | "UPDATE #--albums SET" |
---|
57 | ." ordre=".$ordre[$id] |
---|
58 | .", actif=".($actif[$id] ? 1 : 0) |
---|
59 | ." WHERE id=".$id; |
---|
60 | $this->sql->query($query); |
---|
61 | } |
---|
62 | } |
---|
63 | catch(Exception $_e) { return false; } |
---|
64 | } |
---|
65 | return true; |
---|
66 | } |
---|
67 | |
---|
68 | function artiste_album($id) |
---|
69 | { $album = array(); |
---|
70 | try |
---|
71 | { $sql = "SELECT * FROM #--albums WHERE id=".$this->eq($id); |
---|
72 | $rst = $this->sql->query($sql); |
---|
73 | if($v_rst = $this->sql->fetch_assoc($rst)) $album = $v_rst; |
---|
74 | $this->sql->free_result($rst); |
---|
75 | } |
---|
76 | catch(Exception $_e) { $album = false; } |
---|
77 | return $album; |
---|
78 | } |
---|
79 | |
---|
80 | function add_artiste_album($id_artiste, $titre, $image, $description, $url, $format, $taille, $date_creation) |
---|
81 | { $id_album; |
---|
82 | try |
---|
83 | { $sql = |
---|
84 | "INSERT INTO #--albums" |
---|
85 | ."( id_artiste" |
---|
86 | .", titre" |
---|
87 | .", image" |
---|
88 | .", description" |
---|
89 | .", url" |
---|
90 | .", format" |
---|
91 | .", taille" |
---|
92 | .", date_creation" |
---|
93 | .", date_publication" |
---|
94 | .", compteur" |
---|
95 | .", actif" |
---|
96 | .") VALUES" |
---|
97 | ."( ".$this->eq($id_artiste) |
---|
98 | .", ".$this->eq($titre) |
---|
99 | .", ".$this->eq($image) |
---|
100 | .", ".$this->eq($description) |
---|
101 | .", ".$this->eq($url) |
---|
102 | .", ".$this->eq($format) |
---|
103 | .", ".$this->eq($taille) |
---|
104 | .", ".$this->eq($date_creation) |
---|
105 | .", NOW()" |
---|
106 | .", 0" |
---|
107 | .", 1" |
---|
108 | .")"; |
---|
109 | $this->sql->query($sql); |
---|
110 | $id_album = $this->sql->insert_id(); |
---|
111 | } |
---|
112 | catch(Exception $_e) { $id_album = false; } |
---|
113 | return $id_album; |
---|
114 | } |
---|
115 | |
---|
116 | function set_artiste_album($id, $titre, $image, $description, $url, $format, $taille, $date_creation) |
---|
117 | { try |
---|
118 | { $sql = |
---|
119 | "UPDATE #--albums SET" |
---|
120 | ." titre=".$this->eq($titre) |
---|
121 | .", image=".$this->eq($image) |
---|
122 | .", description=".$this->eq($description) |
---|
123 | .", url=".$this->eq($url) |
---|
124 | .", format=".$this->eq($format) |
---|
125 | .", taille=".$this->eq($taille) |
---|
126 | .", date_creation=".$this->eq($date_creation) |
---|
127 | ." WHERE id=".$this->eq($id); |
---|
128 | $this->sql->query($sql); |
---|
129 | } |
---|
130 | catch(Exception $_e) { return false; } |
---|
131 | return true; |
---|
132 | } |
---|
133 | |
---|
134 | function del_artiste_album($id) |
---|
135 | { try |
---|
136 | { $sql = "DELETE FROM #--albums WHERE id=".$this->eq($id); |
---|
137 | $this->sql->query($sql); |
---|
138 | } |
---|
139 | catch(Exception $_e) { return false; } |
---|
140 | return true; |
---|
141 | } |
---|
142 | |
---|
143 | function inc_album_compteur($id_album) |
---|
144 | { $url = false; |
---|
145 | try |
---|
146 | { $sql = "SELECT url FROM #--albums WHERE id=".$id_album; |
---|
147 | $rst = $this->sql->query($sql); |
---|
148 | if($v_rst = $this->sql->fetch_assoc($rst)) $url = $v_rst["url"]; |
---|
149 | if($url); |
---|
150 | { $sql = |
---|
151 | "UPDATE #--albums SET compteur=(compteur + 1) WHERE id=".$id_album; |
---|
152 | $this->sql->query($sql); |
---|
153 | } |
---|
154 | } |
---|
155 | catch(Exception $_e) { $url = false; } |
---|
156 | return $url; |
---|
157 | } |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | ?> |
---|