Subversion Repository Public Repository

Nextrek

Diff Revisions 699 vs 701 for /Android/SmartCharging/endPoints/repositories/CommentRepository.php

Diff revisions: vs.
  @@ -76,22 +76,31 @@
76 76 public function addComment($comment) {
77 77 $status = array();
78 78
79 + $toUpdate = false;
80 +
79 81 $previousComment = $this->getComment($comment->id_user, $comment->id_locale);
80 82
81 83 if ($previousComment["return"] != 0) { //errore nella getComment()
82 84 return $previousComment;
83 - } else if ($previousComment["return"] == 0 && !is_null($previousComment["comment"])) {
85 + } /*else if ($previousComment["return"] == 0 && !is_null($previousComment["comment"])) {
84 86 $status = createErrorMessage(1, "Commento gi� inserito dall'utente");
85 87 $status["id"] = -1;
86 88 return $status;
87 - }
89 + }*/
88 90
89 - $queryComment = "INSERT INTO commenti(id_locale, id_user, voto, descrizione, data)
91 + if ($previousComment["return"] == 0 && !is_null($previousComment["comment"])) { //commento da sovrascrivere
92 + $queryComment = "UPDATE commenti
93 + SET descrizione='".$comment->descrizione."',voto='".$comment->voto."', data='".$comment->data."'
94 + WHERE id=".$previousComment["comment"]->id;
95 + $toUpdate = true;
96 + } else {
97 + $queryComment = "INSERT INTO commenti(id_locale, id_user, voto, descrizione, data)
90 98 VALUES ('".$comment->id_locale."',
91 99 '".$comment->id_user."',
92 100 '".$comment->voto."',
93 101 '".$comment->descrizione."',
94 102 '".$comment->data."')";
103 + }
95 104
96 105 //echo "<br/>".$queryComment."<br/>";
97 106
  @@ -100,7 +109,7 @@
100 109
101 110 try {
102 111 $this->db->exec($queryComment);
103 - $id_commento = $this->db->lastInsertId();
112 + $id_commento = ($toUpdate) ? $previousComment["comment"]->id : $this->db->lastInsertId();
104 113
105 114 /*foreach($imgs as $img) {
106 115 $imgsToInsert[] = '("'.$id_commento.'", "'.$img.'")';