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;
|
ADD: Middleware (first part)
Refactoring the code, dropping the `users_trust_level` table, classes, merging methods (for example, getPostId and getPostSlug), and changing the names and types of variables.
* The following classes have been removed: Authorization, DefaultMiddlewareBefore, DefaultMiddlewareBefore, Base, BanController.
* Added: MiddlewareModel, UserData, Designator.
* Fixed N+1 query on the post page
* The detailed page of the sent invites in the admin section has been changed.
etc.
2022-01-04 20:54:03 +01:00
|
|
|
use App\Middleware\Before\UserData;
|
2021-08-18 11:29:16 +02:00
|
|
|
use App\Models\VotesModel;
|
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
|
|
|
{
|
2021-12-19 15:10:26 +01:00
|
|
|
private $uid;
|
|
|
|
|
|
|
|
public function __construct()
|
2021-06-22 18:15:46 +02:00
|
|
|
{
|
ADD: Middleware (first part)
Refactoring the code, dropping the `users_trust_level` table, classes, merging methods (for example, getPostId and getPostSlug), and changing the names and types of variables.
* The following classes have been removed: Authorization, DefaultMiddlewareBefore, DefaultMiddlewareBefore, Base, BanController.
* Added: MiddlewareModel, UserData, Designator.
* Fixed N+1 query on the post page
* The detailed page of the sent invites in the admin section has been changed.
etc.
2022-01-04 20:54:03 +01:00
|
|
|
$this->uid = UserData::getUid();
|
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()
|
|
|
|
{
|
2021-08-18 11:29:16 +02:00
|
|
|
$up_id = Request::getPostInt('up_id');
|
|
|
|
$type = Request::get('type');
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-12-08 12:13:43 +01:00
|
|
|
$allowed = ['post', 'comment', 'answer', 'item'];
|
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);
|
2021-12-19 15:10:26 +01:00
|
|
|
if ($this->uid['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
|
|
|
|
$info = VotesModel::voteStatus($up_id, $this->uid['user_id'], $type);
|
|
|
|
if ($info) return false;
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-06-22 18:15:46 +02:00
|
|
|
$date = date("Y-m-d H:i:s");
|
|
|
|
$ip = Request::getRemoteAddress();
|
2021-08-01 20:43:50 +02:00
|
|
|
|
2021-12-19 15:10:26 +01:00
|
|
|
VotesModel::saveVote($up_id, $ip, $this->uid['user_id'], $date, $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
|
|
|
}
|