From 1da0f427e6b0d3401c58c951c32e5d821de0afda Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 13 Feb 2023 22:44:08 +0000 Subject: [PATCH] my_vote field --- ext/numeric_score/main.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index 74cf9f12..b5a65cd0 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -61,6 +61,16 @@ class NumericScoreVote return $votes; } + #[Field(extends: "Post", type: "Int!")] + public static function my_vote(Image $post): int + { + global $database, $user; + return $database->get_one( + "SELECT score FROM numeric_score_votes WHERE image_id=:image_id AND user_id=:user_id", + ['image_id'=>$post->id, "user_id"=>$user->id] + ) ?? 0; + } + #[Mutation] public static function create_vote(int $post_id, int $score): bool {