2021-06-22 18:15:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-08-18 20:47:18 +02:00
|
|
|
use Hleb\Scheme\App\Controllers\MainController;
|
2021-06-22 18:15:46 +02:00
|
|
|
use Hleb\Constructor\Handlers\Request;
|
2021-08-18 11:29:16 +02:00
|
|
|
use App\Models\VotesModel;
|
2022-02-10 07:42:33 +01:00
|
|
|
use UserData;
|
2021-06-22 18:15:46 +02:00
|
|
|
|
2021-08-18 20:47:18 +02:00
|
|
|
class VotesController extends MainController
|
2021-06-22 18:15:46 +02:00
|
|
|
{
|
2022-01-17 19:17:58 +01:00
|
|
|
private $user;
|
2021-12-19 15:10:26 +01:00
|
|
|
|
|
|
|
public function __construct()
|
2021-06-22 18:15:46 +02:00
|
|
|
{
|
2022-01-17 19:17:58 +01:00
|
|
|
$this->user = UserData::get();
|
2021-12-19 15:10:26 +01:00
|
|
|
}
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-12-19 15:10:26 +01:00
|
|
|
public function index()
|
|
|
|
{
|
2022-03-05 23:21:14 +01:00
|
|
|
$up_id = Request::getPostInt('content_id');
|
|
|
|
$type = Request::getPost('type');
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2022-03-26 15:06:31 +01:00
|
|
|
$allowed = ['post', 'comment', 'answer', 'item', 'reply'];
|
2021-12-19 15:10:26 +01:00
|
|
|
if (!in_array($type, $allowed)) return false;
|
|
|
|
if ($up_id <= 0) return false;
|
|
|
|
|
|
|
|
// Проверяем, чтобы участник не голосовал за свой контент
|
|
|
|
// We check that the participant does not vote for their content
|
2021-12-08 12:13:43 +01:00
|
|
|
// $type = post / answer / comment / item
|
2021-06-24 09:29:03 +02:00
|
|
|
$author_id = VotesModel::authorId($up_id, $type);
|
2022-01-17 19:17:58 +01:00
|
|
|
if ($this->user['id'] == $author_id) return false;
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-12-19 15:10:26 +01:00
|
|
|
// Проверяем, голосовал ли пользователь
|
|
|
|
// We check whether the user voted
|
2022-01-17 19:17:58 +01:00
|
|
|
$info = VotesModel::voteStatus($up_id, $this->user['id'], $type);
|
2021-12-19 15:10:26 +01:00
|
|
|
if ($info) return false;
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-06-22 18:15:46 +02:00
|
|
|
$ip = Request::getRemoteAddress();
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2022-03-12 16:17:52 +01:00
|
|
|
VotesModel::saveVote($up_id, $ip, $this->user['id'], $type);
|
2021-06-24 09:29:03 +02:00
|
|
|
VotesModel::saveVoteContent($up_id, $type);
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-06-22 18:15:46 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-08-01 20:43:50 +02:00
|
|
|
}
|