Game-Jaming/Backend/Controllers/Polls/1vote.php

39 lines
793 B
PHP
Raw Normal View History

2021-03-05 12:00:07 +00:00
<?php
2021-04-19 07:15:15 +00:00
use Backend\Models\GameData;
2021-03-05 12:00:07 +00:00
use Backend\Models\Vote;
2021-04-19 07:15:15 +00:00
2021-03-12 13:05:31 +00:00
require_once "../../../bootstrap.php";
require_once "Vote.php";
2021-03-05 12:00:07 +00:00
2021-04-19 07:15:15 +00:00
if (isset($_POST['1Vote'])) {
if (VoteCheck($_POST['gameDataId'])) {
2021-03-12 13:05:31 +00:00
$vote = new Vote();
2021-04-19 07:15:15 +00:00
$vote->gameDate()->associate(GameData::find($_POST['gameDataId']));
2021-03-12 13:05:31 +00:00
$vote->points += 1;
2021-04-19 07:15:15 +00:00
if (!empty($_POST['comment'])) {
2021-03-12 13:05:31 +00:00
$vote->comment = $_POST['comment'];
2021-03-19 12:25:27 +00:00
}
2021-04-19 07:15:15 +00:00
if (!$vote->save()) {
2021-03-19 12:25:27 +00:00
http_response_code(500);
2021-04-19 07:15:15 +00:00
} else {
2021-03-19 12:25:27 +00:00
http_response_code(201);
2021-03-12 13:05:31 +00:00
}
2021-04-19 07:15:15 +00:00
} else {
2021-03-23 12:39:44 +00:00
http_response_code(403);
echo json_encode(["message" => "you have already voted"]);
2021-03-05 12:00:07 +00:00
}
2021-04-19 07:15:15 +00:00
} else {
2021-03-23 12:39:44 +00:00
http_response_code(400);
echo json_encode(["message" => "you have already voted"]);
2021-03-05 12:00:07 +00:00
}