public function undoEstimation($tableName, $columnName, $resourceId) { $db = DataBase::getPdo(); $q = "DELETE FROM {$tableName} WHERE {$columnName} = ?;"; $stm = $db->prepare($q); $stm->bindValue(1, $resourceId); $res = $stm->execute(); if ($res) { if ($stm->rowCount() == 1) { return $this->makeResponse(true); } else { return $this->makeResponse(false, 'action is already done'); } } else { return $this->makeResponse(false, 'unknown error'); } }
public function getData($day) { $db = DataBase::getPdo(); $getAvalableDays = "SELECT DISTINCT publishing_date FROM posts;"; $stm = $db->query($getAvalableDays); $available = []; # array_map(function($e){return $e["publishing_date"];}, $stm->fetchAll()); while ($row = $stm->fetch()) { array_push($available, $row["publishing_date"]); } if (!in_array($day, $available)) { return ['result' => 'error', 'message' => 'cannot find specified date', 'available' => $available]; } #$q = "SELECT id, likes, dislikes FROM posts WHERE publishing_date = '2015-10-12';"; $q = "SELECT id, likes, dislikes FROM posts WHERE publishing_date = ?;"; $stm = $db->prepare($q); $stm->bindValue(1, $day); $stm->execute(); $posts = $stm->fetchAll(); $commentsWithAuthorsToPosts = []; $q = <<<EOD \t\t\tSELECT COUNT(id) as comments_count, \t\t\tCOUNT( DISTINCT author) as unique_author \t\t\tFROM comments WHERE post_id = ?; EOD; foreach ($posts as &$row) { #$comments = $db->query( $stm = $db->prepare($q); $stm->bindValue(1, $row["id"]); $stm->execute(); #$commentsWithAuthorsToPosts[$row["id"]] = $stm->fetch(); $c = $stm->fetch(); $row["unique_authors"] = $c["unique_author"]; $row["comments_count"] = $c["comments_count"]; } return ['postsStat' => $posts, 'available' => $available]; }
public static function getList($postId) { $db = DataBase::getPdo(); $q = 'SELECT content, author, id, publishing_date, publishing_time, likes, dislikes FROM comments WHERE post_id = ?;'; $stm = $db->prepare($q); $stm->bindValue(1, $postId); $stm->execute(); return $stm->fetchAll(); }
public static function get($id) { $db = DataBase::getPdo(); $q = <<<EOD \t\tSELECT content, title, author, \t\tpublishing_date, publishing_time, \t\tjson_attrs, \t\tlikes, dislikes, \t\tfavorites, id \t\tFROM posts WHERE id = :id; EOD; $stm = $db->prepare($q); $stm->execute(['id' => $id]); $result = $stm->fetch(); if ($result) { $result['karma'] = static::s_karma($id); return $result; } return $stm->fetch(); }