Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
	require_once('LocalRepositoryInterface.php');
	require_once('Local.php');

	class LocalRepository implements LocalRepositoryInterface {
		protected $db;

		public function __construct($db) {
			$this->db = $db;
		}

		public function registerLocal($local) {
			$status = array();

			$queryLocal = "INSERT INTO locale(id_utente_owner, nomelocale, descrizione, tipologia, lat, lon)
    				VALUES ('".$local->id_utente_owner."',
    						'".$local->nomelocale."',
    						'".$local->descrizione."',
    						'".$local->tipologia."',
    						'".$local->lat."',
    						'".$local->lon."')";
			
			//echo "<br/>".$query."<br/>";

			$imgs = $local->imgs;
			$imgsToInsert = array();

			try {
				$this->db->exec($queryLocal);
				$id_locale = $this->db->lastInsertId();

				/*foreach($imgs as $img) {
					$imgsToInsert[] = '("'.$id_locale.'", "'.$img.'")';
				}

				$queryImgs = "INSERT INTO immagini_locali(id_locale, img) VALUES" . implode(',', $imgsToInsert);

				$this->db->exec($queryImgs);*/

				$status["local_id"] = $id_locale;
				$status["return"] = 0;

				return $status;

			} catch (PDOException $e) {
				echo $e->getMessage();

				$status["local_id"] = -1;
				$status["return"] = 3;

				return $status;
			}
		}

		public function setLocalPosition($id_local, $lat, $lon) {
			$query = "UPDATE locale
						SET lat=".$lat.",lon=".$lon.
						"WHERE id=".$id_local;

			try {
				return $this->db->exec($query);
			} catch (PDOException $e) {
				echo $e->getMessage();
				return -1;
			}		
		}

		public function setLocalName($id_local, $name) {
			$query = "UPDATE locale
						SET nomelocale='".$name."'".
						"WHERE id=".$id_local;

			try {
				return $this->db->exec($query);
			} catch (PDOException $e) {
				echo $e->getMessage();
				return -1;
			}		
		}

		public function setLocalDescription($id_local, $description) {
			$query = "UPDATE locale
						SET descrizione='".$description."'".
						"WHERE id=".$id_local;

			try {
				return $this->db->exec($query);
			} catch (PDOException $e) {
				echo $e->getMessage();
				return -1;
			}		
		}

		public function getImages($id_local) {
			$local = new Local();
			$query;

			$sql = "SELECT img 
						FROM immagini_locali 
						WHERE id_locale=".$id_local;

			try {
				$query = $this->db->query($sql);

				if (!$query) return null;

				$rows = $query->fetchAll(PDO::FETCH_ASSOC);

				$local->imgs = array();

				foreach ($rows as $row) {
					array_push($local->imgs, $row["img"]);
				}

				return $local;
			} catch (PDOException $e) {
				echo $e->getMessage();
				return null;
			}	
		}

		/*public function addImage($id_local, $imgs) {
			$sql = "INSERT INTO immagini_locali(id_locale, img)
							VALUES (".$id_local.",'".$img."')";

			try {
				$this->db->exec($sql);
				return 0;
			} catch (PDOException $e) {
				echo $e->getMessage();
				return 1;
			}
		}*/

		public function addImages($id_local, $imgs) {
			try {
				foreach($imgs as $img) {
					$imgsToInsert[] = '("'.$id_local.'", "'.$img.'")';
				}

				$queryImgs = "INSERT INTO immagini_locali(id_locale, img) VALUES" . implode(',', $imgsToInsert);
				//echo "<br/>".$queryImgs."<br/>";

				$this->db->exec($queryImgs);
				return 0;

			} catch (PDOException $e) {
				echo $e->getMessage();
				return 1;
			}
		}

		public function getMinimalLocalInfo($id_local) {
			$local = new Local();
			$query;

			$sql = "SELECT locale.id as id, locale.tipologia as tipologia, locale.descrizione as descrizione, avg(commenti.voto) as stelle
					FROM locale, commenti
					WHERE locale.id=commenti.id_locale AND id_locale=".$id_local."
					GROUP BY locale.id, locale.tipologia, locale.descrizione";

			//echo "<br/>".$sql."<br/>";

			try {
				$query = $this->db->query($sql);

				if (!$query) return null;

				$row = $query->fetch(PDO::FETCH_ASSOC);

				$local->tipologia 	= $row["tipologia"];
				$local->descrizione = $row["descrizione"];
				$local->stelle 		= $row["stelle"];

				return $local;

			} catch (PDOException $e) {
				echo $e->getMessage();
				return null;
			}
		}

		public function deleteImage($id_local, $img) {
			$sql = "DELETE FROM immagini_locali WHERE id_locale=".$id_local." AND img='".$img."'";
			try {
				$this->db->exec($sql);
				return 0;
			} catch (PDOException $e) {
				echo $e->getMessage();
				return 1;
			}
		}

		public function getCloseLocals($tipologia, $lat, $lon, $distance) {
			$local_list = array();

			$harvesinFormulaSQL = "SELECT id, lat, lon, tipologia, nomelocale,
									( 6371 * acos( cos( radians(".$lat.") ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(".$lon.") ) + sin( radians(".$lat.") ) * sin( radians( lat ) ) ) ) AS distance
									FROM locale
									WHERE tipologia='".$tipologia."'
									HAVING distance < ".$distance/1000.0."
									ORDER BY distance";
									//ORDER BY distance LIMIT 0 , 20"; //nel caso in cui si voglia introdurre il limite di locali vicini

			//echo "<br/>".$harvesinFormulaSQL."<br/>";

			try {
				$query = $this->db->query($harvesinFormulaSQL);

				if (!$query) return null;

				$rows = $query->fetchAll(PDO::FETCH_ASSOC);

				foreach ($rows as $row) {
					$local = array();
					$local["id"]			= $row["id"];
					$local["lat"] 			= $row["lat"];
					$local["lon"] 			= $row["lon"];
					$local["tipologia"]		= $row["tipologia"];
					$local["nomelocale"] 	= $row["nomelocale"];

					array_push($local_list, $local);
				}

				return $local_list;

			} catch (PDOException $e) {
				echo $e->getMessage();
				return null;
			}
		}
	}

?>

Commits for Nextrek/Android/SmartCharging/endPoints/LocalRepository.php

Diff revisions: vs.
Revision Author Commited Message
300 Diff Diff FSallustio picture FSallustio Mon 13 Jul, 2015 15:15:58 +0000
287 Diff Diff FSallustio picture FSallustio Mon 13 Jul, 2015 13:08:39 +0000
258 Diff Diff FSallustio picture FSallustio Fri 10 Jul, 2015 09:59:44 +0000

Implementata get_list_locali.php, usando la Harvesine Formula

255 Diff Diff FSallustio picture FSallustio Fri 10 Jul, 2015 09:10:22 +0000

Implementata delete_immagine.php

253 Diff Diff FSallustio picture FSallustio Fri 10 Jul, 2015 08:27:27 +0000

Implementata get_info_small_locale.php

250 Diff Diff FSallustio picture FSallustio Fri 10 Jul, 2015 07:57:50 +0000

Implementata get_immagini.php

242 Diff Diff FSallustio picture FSallustio Thu 09 Jul, 2015 11:18:36 +0000

get_commenti.php implementata + bugfix

240 Diff Diff FSallustio picture FSallustio Thu 09 Jul, 2015 10:08:30 +0000

Implementati add_commento.php, cambia_nome_locale.php e set_descrizione.php

235 Diff Diff FSallustio picture FSallustio Thu 09 Jul, 2015 08:52:31 +0000

Reimplementati registrazione_utente.php e registrazione_locale.php

225 FSallustio picture FSallustio Wed 08 Jul, 2015 09:39:45 +0000

Implementato immagini.php