public function add($marker_id, $user_id, $comment) { try { $stmt = $this->db->prepare('INSERT INTO comments(marker_id, user_id, comment, status_id) VALUES (:marker_id, :user_id, :comment, :status_id);'); $stmt->bindValue(':marker_id', $marker_id, PDO::PARAM_INT); $stmt->bindValue(':user_id', $user_id, PDO::PARAM_INT); $stmt->bindValue(':comment', $comment, PDO::PARAM_STR); $stmt->bindValue(':status_id', profanityFilter($comment), PDO::PARAM_INT); $stmt->execute(); $result = array('comment_id' => $this->db->lastInsertId(), 'affected' => $stmt->rowCount()); return $result; } catch (\PDOException $e) { if ($e->errorInfo[1] == 1062) { throw new \Exception('Komentarz już istnieje.', 400); } else { throw new \Exception('Nie można dodać komentarza.', 500); } } }
public function update($marker_id, $type_id, $address, $description) { try { $stmt = $this->db->prepare('UPDATE markers SET status_id=:status_id, type_id=:type_id, address=:address, description=:description WHERE marker_id=:marker_id;'); $stmt->bindValue(':marker_id', $marker_id, PDO::PARAM_INT); $stmt->bindValue(':type_id', $type_id, PDO::PARAM_INT); $stmt->bindValue(':address', $address, PDO::PARAM_STR); $stmt->bindValue(':description', $description, PDO::PARAM_STR); $stmt->bindValue(':status_id', profanityFilter($description), PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() == 0) { throw new \Exception('Nie znaleziono zgłoszenia o podanym identyfikatorze lub nie wprowadzono zmian.', 404); } $result = array('affected' => $stmt->rowCount()); return $result; } catch (\PDOException $e) { throw new \Exception('Nie można edytować zgłoszenia.', 500); } }