|
@@ -1,6 +1,7 @@ |
1 |
1 |
|
<?php |
2 |
2 |
|
require_once('LocalRepositoryInterface.php'); |
3 |
3 |
|
require_once(dirname(__FILE__).'/../classes/Local.php'); |
|
4 |
+ |
require_once(dirname(__FILE__)."/../utilities.php"); |
4 |
5 |
|
|
5 |
6 |
|
class LocalRepository implements LocalRepositoryInterface { |
6 |
7 |
|
protected $db; |
|
@@ -33,6 +34,8 @@ |
33 |
34 |
|
$this->db->exec($queryLocal); |
34 |
35 |
|
$id_locale = $this->db->lastInsertId(); |
35 |
36 |
|
|
|
37 |
+ |
$queryUser = "UPDATE utente SET is_owner=1 WHERE id=".$local->id_utente_owner; |
|
38 |
+ |
|
36 |
39 |
|
/*foreach($imgs as $img) { |
37 |
40 |
|
$imgsToInsert[] = '("'.$id_locale.'", "'.$img.'")'; |
38 |
41 |
|
} |
|
@@ -41,6 +44,8 @@ |
41 |
44 |
|
|
42 |
45 |
|
$this->db->exec($queryImgs);*/ |
43 |
46 |
|
|
|
47 |
+ |
$this->db->exec($queryUser); |
|
48 |
+ |
|
44 |
49 |
|
$status["local_id"] = $id_locale; |
45 |
50 |
|
$status["return"] = 0; |
46 |
51 |
|
|
|
@@ -48,9 +53,9 @@ |
48 |
53 |
|
|
49 |
54 |
|
} catch (PDOException $e) { |
50 |
55 |
|
echo $e->getMessage(); |
51 |
|
- |
|
|
56 |
+ |
$risposta = createErrorMessage(3, "Errore DB"); |
52 |
57 |
|
$status["local_id"] = -1; |
53 |
|
- |
$status["return"] = 3; |
|
58 |
+ |
//$status["return"] = 3; |
54 |
59 |
|
|
55 |
60 |
|
return $status; |
56 |
61 |
|
} |
|
@@ -153,7 +158,8 @@ |
153 |
158 |
|
|
154 |
159 |
|
} catch (PDOException $e) { |
155 |
160 |
|
echo $e->getMessage(); |
156 |
|
- |
$status["return"] = 1; |
|
161 |
+ |
$risposta = createErrorMessage(1, "Errore DB"); |
|
162 |
+ |
//$status["return"] = 1; |
157 |
163 |
|
return $status; |
158 |
164 |
|
} |
159 |
165 |
|
|
|
@@ -179,7 +185,7 @@ |
179 |
185 |
|
$local->imgs = array(); |
180 |
186 |
|
|
181 |
187 |
|
foreach ($rows as $row) { |
182 |
|
- |
array_push($local->imgs, IMAGES_PATH.$row["img"]); |
|
188 |
+ |
array_push($local->imgs, IMAGE_SERVER.IMAGES_PATH.$row["img"]); |
183 |
189 |
|
} |
184 |
190 |
|
|
185 |
191 |
|
return $local; |
|
@@ -259,6 +265,47 @@ |
259 |
265 |
|
} |
260 |
266 |
|
} |
261 |
267 |
|
|
|
268 |
+ |
public function getFullLocalInfo($id_local) { |
|
269 |
+ |
$local = new Local(); |
|
270 |
+ |
$queryLocal; |
|
271 |
+ |
|
|
272 |
+ |
$sqlLocal = "SELECT l.id as id, u.id_utente_owner as id_utente_owner, u.username as username_owner, |
|
273 |
+ |
l.nomelocale as nomelocale, l.descrizione as descrizione, l.tipologia as tipologia, |
|
274 |
+ |
l.lat as lat, l.lon as lon, l.indirizzo as indirizzo, l.email as email, |
|
275 |
+ |
l.telefono as telefono, l.sito as sito |
|
276 |
+ |
FROM locale l ,utente u |
|
277 |
+ |
WHERE l.id=".$id_local." AND u.id=l.id_utente_owner"; |
|
278 |
+ |
|
|
279 |
+ |
//echo "<br/>".$sql."<br/>"; |
|
280 |
+ |
|
|
281 |
+ |
try { |
|
282 |
+ |
$queryLocal = $this->db->query($sqlLocal); |
|
283 |
+ |
|
|
284 |
+ |
if (!$queryLocal) return null; |
|
285 |
+ |
|
|
286 |
+ |
$rowLocal = $queryLocal->fetch(PDO::FETCH_ASSOC); |
|
287 |
+ |
|
|
288 |
+ |
$local->id = $rowLocal["id"]; |
|
289 |
+ |
$local->id_utente_owner = $rowLocal["id_utente_owner"]; |
|
290 |
+ |
$local->username_owner = $rowLocal["username_owner"]; |
|
291 |
+ |
$local->nomelocale = $rowLocal["nomelocale"]; |
|
292 |
+ |
$local->descrizione = $rowLocal["descrizione"]; |
|
293 |
+ |
$local->tipologia = $rowLocal["tipologia"]; |
|
294 |
+ |
$local->lat = $rowLocal["lat"]; |
|
295 |
+ |
$local->lon = $rowLocal["lon"]; |
|
296 |
+ |
$local->indirizzo = (!is_null($rowLocal["indirizzo"])) ? $rowLocal["indirizzo"] : ""; |
|
297 |
+ |
$local->email = $rowLocal["email"]; |
|
298 |
+ |
$local->telefono = $rowLocal["telefono"]; |
|
299 |
+ |
$local->sito = $rowLocal["sito"]; |
|
300 |
+ |
|
|
301 |
+ |
return $local; |
|
302 |
+ |
|
|
303 |
+ |
} catch (PDOException $e) { |
|
304 |
+ |
echo $e->getMessage(); |
|
305 |
+ |
return null; |
|
306 |
+ |
} |
|
307 |
+ |
} |
|
308 |
+ |
|
262 |
309 |
|
public function deleteImage($id_local, $img) { |
263 |
310 |
|
$sql = "DELETE FROM immagini_locali WHERE id_locale=".$id_local." AND img='".$img."'"; |
264 |
311 |
|
try { |
|
@@ -319,7 +366,7 @@ |
319 |
366 |
|
public function getLocalsByUser($user_id) { |
320 |
367 |
|
$local_list = array(); |
321 |
368 |
|
|
322 |
|
- |
$sql = "SELECT id, lat, lon, indirizzo, tipologia, nomelocale, telefono, email, sito |
|
369 |
+ |
$sql = "SELECT id, lat, lon, indirizzo, tipologia, nomelocale, telefono, email, sito, descrizione |
323 |
370 |
|
FROM locale |
324 |
371 |
|
WHERE id_utente_owner=".$user_id; |
325 |
372 |
|
|
|
@@ -343,6 +390,7 @@ |
343 |
390 |
|
$local["telefono"] = $row["telefono"]; |
344 |
391 |
|
$local["email"] = $row["email"]; |
345 |
392 |
|
$local["sito"] = $row["sito"]; |
|
393 |
+ |
$local["descrizione"] = $row["descrizione"]; |
346 |
394 |
|
|
347 |
395 |
|
array_push($local_list, $local); |
348 |
396 |
|
} |