Subversion Repository Public Repository

Nextrek

Diff Revisions 225 vs 235 for /Android/SmartCharging/endPoints/LocalRepository.php

Diff revisions: vs.
  @@ -1,6 +1,5 @@
1 1 <?php
2 2 require('LocalRepositoryInterface.php');
3 - require('Local.php');
4 3
5 4 class LocalRepository implements LocalRepositoryInterface {
6 5 protected $db;
  @@ -9,32 +8,47 @@
9 8 $this->db = $db;
10 9 }
11 10
12 - public function registerLocal($local, $password) {
13 - $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
11 + public function registerLocal($local) {
12 + $status = array();
14 13
15 - $query = "INSERT INTO locale(nominativo, cell, email, nomelocale, descrizione, tipologia, img1, img2, username, password, lat, lon)
16 - VALUES ('".$local->nominativo."',
17 - '".$local->cell."',
18 - '".$local->email."',
14 + $queryLocal = "INSERT INTO locale(id_utente_owner, nomelocale, descrizione, tipologia, lat, lon)
15 + VALUES ('".$local->id_utente_owner."',
19 16 '".$local->nomelocale."',
20 17 '".$local->descrizione."',
21 18 '".$local->tipologia."',
22 - '".$local->img1."',
23 - '".$local->img2."',
24 - '".$local->username."',
25 - '".$hashedPwd."',
26 19 '".$local->lat."',
27 20 '".$local->lon."')";
28 21
29 - //echo "<br/>".$query."<br/>";
22 + //echo "<br/>".$query."<br/>";
23 +
24 + $imgs = $local->imgs;
25 + $imgsToInsert = array();
30 26
31 27 try {
32 - $this->db->exec($query);
33 - return $this->db->lastInsertId();
28 + $this->db->exec($queryLocal);
29 + $id_locale = $this->db->lastInsertId();
30 +
31 + foreach($imgs as $img) {
32 + $imgsToInsert[] = '("'.$id_locale.'", "'.$img.'")';
33 + }
34 +
35 + $queryImgs = "INSERT INTO immagini_locali(id_locale, img) VALUES" . implode(',', $imgsToInsert);
36 + echo "<br/>".$queryImgs."<br/>";
37 +
38 + $this->db->exec($queryImgs);
39 +
40 + $status["local_id"] = $id_locale;
41 + $status["return"] = 0;
42 +
43 + return $status;
34 44
35 - //echo "New record created successfully";
36 45 } catch (PDOException $e) {
37 46 echo $e->getMessage();
47 +
48 + $status["local_id"] = -1;
49 + $status["return"] = 3;
50 +
51 + return $status;
38 52 }
39 53 }
40 54
  @@ -54,9 +68,9 @@
54 68 $local = new Local();
55 69 $query;
56 70
57 - $sql = "SELECT img1, img2
58 - FROM locale
59 - WHERE id=".$id_local;
71 + $sql = "SELECT img
72 + FROM immagini_locali
73 + WHERE id_locale=".$id_local;
60 74
61 75 try {
62 76 $query = $this->db->query($sql);
  @@ -65,9 +79,10 @@
65 79
66 80 $rows = $query->fetchAll(PDO::FETCH_ASSOC);
67 81
82 + $local->imgs = array();
83 +
68 84 foreach ($rows as $row) {
69 - $local->img1 = $row["img1"];
70 - $local->img2 = $row["img2"];
85 + array_push($local->imgs, $row["img"]);
71 86 }
72 87
73 88 return $local;