|
@@ -11,9 +11,81 @@ |
11 |
11 |
|
$this->db = $db; |
12 |
12 |
|
} |
13 |
13 |
|
|
|
14 |
+ |
public function getComment($id_user, $id_local) { |
|
15 |
+ |
$status = array(); |
|
16 |
+ |
|
|
17 |
+ |
$queryComment = "SELECT c.id AS id_commento, id_locale, id_user, voto, descrizione, data, img, username, u.avatar as avatar |
|
18 |
+ |
FROM commenti as c |
|
19 |
+ |
LEFT JOIN immagini_commenti as i ON c.id=i.id_commento |
|
20 |
+ |
LEFT JOIN utente as u ON c.id_user=u.id |
|
21 |
+ |
WHERE id_user=".$id_user." AND id_locale=".$id_local; |
|
22 |
+ |
|
|
23 |
+ |
//echo "<br/>".$queryComment."<br/>"; |
|
24 |
+ |
|
|
25 |
+ |
$comment; |
|
26 |
+ |
|
|
27 |
+ |
try { |
|
28 |
+ |
$query = $this->db->query($queryComment); |
|
29 |
+ |
|
|
30 |
+ |
if (!$query) { |
|
31 |
+ |
$status = createErrorMessage(1, "Errore DB"); |
|
32 |
+ |
$status["comment"] = null; |
|
33 |
+ |
return $status; |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
$row = ($query->rowCount()>0) ? $query->fetch() : null; |
|
37 |
+ |
|
|
38 |
+ |
if (is_null($row)) { |
|
39 |
+ |
$status["return"] = 0; |
|
40 |
+ |
$status["comment"] = null; |
|
41 |
+ |
return $status; |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
//$comment_id = $row["id_commento"]; |
|
45 |
+ |
|
|
46 |
+ |
$imgRow = (!is_null($row["img"])) ? IMAGE_SERVER.IMAGES_PATH.$row["img"] : null; |
|
47 |
+ |
|
|
48 |
+ |
if (!isset($comment)) { |
|
49 |
+ |
$comment = new Comment(); |
|
50 |
+ |
$comment->id = $row["id_commento"]; |
|
51 |
+ |
$comment->id_locale = $id_local; |
|
52 |
+ |
$comment->id_user = (!is_null($row["id_user"]) && $row["id_user"]!="") ? $row["id_user"] : -1; |
|
53 |
+ |
$comment->user_avatar = (!is_null($row["avatar"]) && $row["avatar"]!="") ? IMAGE_SERVER.AVATAR_PATH.$row["avatar"] : ""; |
|
54 |
+ |
$comment->username = $row["username"]; |
|
55 |
+ |
$comment->voto = $row["voto"]; |
|
56 |
+ |
$comment->descrizione = $row["descrizione"]; |
|
57 |
+ |
$comment->data = $row["data"]; |
|
58 |
+ |
$comment->imgs = (!is_null($imgRow)) ? array($imgRow) : array(); |
|
59 |
+ |
} else if (!is_null($imgRow)) { |
|
60 |
+ |
array_push($comment->imgs, $imgRow); |
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
$status["return"] = 0; |
|
64 |
+ |
$status["comment"] = $comment; |
|
65 |
+ |
return $status; |
|
66 |
+ |
|
|
67 |
+ |
} catch (PDOException $e) { |
|
68 |
+ |
echo $e->getMessage(); |
|
69 |
+ |
$status = createErrorMessage(1, "Errore DB"); |
|
70 |
+ |
$status["comment"] = null; |
|
71 |
+ |
return $status; |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
} |
|
75 |
+ |
|
14 |
76 |
|
public function addComment($comment) { |
15 |
77 |
|
$status = array(); |
16 |
78 |
|
|
|
79 |
+ |
$previousComment = $this->getComment($comment->id_user, $comment->id_locale); |
|
80 |
+ |
|
|
81 |
+ |
if ($previousComment["return"] != 0) { //errore nella getComment() |
|
82 |
+ |
return $previousComment; |
|
83 |
+ |
} else if ($previousComment["return"] == 0 && !is_null($previousComment["comment"])) { |
|
84 |
+ |
$status = createErrorMessage(1, "Commento gi� inserito dall'utente"); |
|
85 |
+ |
$status["id"] = -1; |
|
86 |
+ |
return $status; |
|
87 |
+ |
} |
|
88 |
+ |
|
17 |
89 |
|
$queryComment = "INSERT INTO commenti(id_locale, id_user, voto, descrizione, data) |
18 |
90 |
|
VALUES ('".$comment->id_locale."', |
19 |
91 |
|
'".$comment->id_user."', |