• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visavi / rotor / 28340133337

28 Jun 2026 11:47PM UTC coverage: 16.561% (+0.09%) from 16.474%
28340133337

push

github

visavi
Ядро и модули переведены на datetime, удалена константа SITETIME

18 of 95 new or added lines in 31 files covered. (18.95%)

7 existing lines in 6 files now uncovered.

989 of 5972 relevant lines covered (16.56%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.88
/app/Http/Controllers/RatingController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Http\Controllers;
6

7
use App\Classes\Validator;
8
use App\Models\Rating;
9
use App\Models\User;
10
use Illuminate\Http\JsonResponse;
11
use Illuminate\Http\RedirectResponse;
12
use Illuminate\Http\Request;
13
use Illuminate\View\View;
14

15
class RatingController extends Controller
16
{
17
    public ?User $user;
18

19
    /**
20
     * Конструктор
21
     */
22
    public function __construct()
3✔
23
    {
24
        $this->middleware('check.user');
3✔
25

26
        $this->middleware(function ($request, $next) {
3✔
27
            $this->user = getUser();
×
28

29
            return $next($request);
×
30
        });
3✔
31
    }
32

33
    /**
34
     * Изменение рейтинга
35
     */
36
    public function index(string $login, Request $request, Validator $validator): View|RedirectResponse
×
37
    {
38
        $vote = $request->input('vote');
×
39
        $user = getUserByLogin($login);
×
40

41
        if (! $user) {
×
42
            abort(404, __('validator.user'));
×
43
        }
44

45
        if ($this->user->id === $user->id) {
×
46
            abort(200, __('ratings.reputation_yourself'));
×
47
        }
48

49
        if ($this->user->point < setting('editratingpoint')) {
×
50
            abort(200, __('ratings.reputation_point', ['point' => plural(setting('editratingpoint'), setting('scorename'))]));
×
51
        }
52

53
        // Голосовать за того же пользователя можно через 90 дней
54
        $getRating = Rating::query()
×
55
            ->where('user_id', $this->user->id)
×
56
            ->where('recipient_id', $user->id)
×
NEW
57
            ->where('created_at', '>', now()->subMonths(3))
×
58
            ->first();
×
59

60
        if ($getRating) {
×
61
            abort(200, __('ratings.reputation_already_changed'));
×
62
        }
63

64
        if ($request->isMethod('post')) {
×
65
            $text = $request->input('text');
×
66

67
            $validator->length($text, 5, 250, ['text' => __('validator.text')]);
×
68

69
            if ($vote === 'minus' && $this->user->rating < 1) {
×
70
                $validator->addError(__('ratings.reputation_positive'));
×
71
            }
72

73
            if ($validator->isValid()) {
×
74
                $text = antimat($text);
×
75

76
                Rating::query()->create([
×
77
                    'user_id'      => $this->user->id,
×
78
                    'recipient_id' => $user->id,
×
79
                    'text'         => $text,
×
80
                    'vote'         => $vote === 'plus' ? '+' : '-',
×
81
                ]);
×
82

83
                if ($vote === 'plus') {
×
84
                    $user->increment('posrating');
×
85
                    $user->update(['rating' => $user->posrating - $user->negrating]);
×
86
                } else {
87
                    $user->increment('negrating');
×
88
                    $user->update(['rating' => $user->posrating - $user->negrating]);
×
89
                }
90

91
                $message = textNotice('rating', ['login' => $this->user->login, 'rating' => $user->rating, 'comment' => $text, 'vote' => __('main.' . $vote)]);
×
92
                $user->sendMessage(null, $message);
×
93

94
                setFlash('success', __('ratings.reputation_success_changed'));
×
95

96
                return redirect('users/' . $user->login);
×
97
            }
98

99
            setInput($request->all());
×
100
            setFlash('danger', $validator->getErrors());
×
101
        }
102

103
        return view('ratings/index', compact('user', 'vote'));
×
104
    }
105

106
    /**
107
     *  Полученные голоса
108
     */
109
    public function received(string $login): View
×
110
    {
111
        $user = getUserByLogin($login);
×
112

113
        if (! $user) {
×
114
            abort(404, __('validator.user'));
×
115
        }
116

117
        $ratings = Rating::query()
×
118
            ->where('recipient_id', $user->id)
×
119
            ->orderByDesc('created_at')
×
120
            ->with('user')
×
121
            ->paginate(setting('ratinglist'));
×
122

123
        return view('ratings/rathistory', compact('ratings', 'user'));
×
124
    }
125

126
    /**
127
     *  Отданные голоса
128
     */
129
    public function gave(string $login): View
×
130
    {
131
        $user = getUserByLogin($login);
×
132

133
        if (! $user) {
×
134
            abort(404, __('validator.user'));
×
135
        }
136

137
        $ratings = Rating::query()
×
138
            ->where('user_id', $user->id)
×
139
            ->orderByDesc('created_at')
×
140
            ->with('recipient')
×
141
            ->paginate(setting('ratinglist'));
×
142

143
        return view('ratings/rathistory_gave', compact('ratings', 'user'));
×
144
    }
145

146
    /**
147
     *  Удаление истории
148
     */
149
    public function delete(Request $request, Validator $validator): JsonResponse
×
150
    {
151
        $id = int($request->input('id'));
×
152

153
        $validator
×
154
            ->true($request->ajax(), __('validator.not_ajax'))
×
155
            ->true(isAdmin(User::ADMIN), __('main.page_only_admins'))
×
156
            ->notEmpty($id, [__('validator.deletion')]);
×
157

158
        if ($validator->isValid()) {
×
159
            $rating = Rating::query()->find($id);
×
160

161
            if ($rating) {
×
162
                $rating->delete();
×
163
            }
164

165
            return response()->json(['success' => true]);
×
166
        }
167

168
        return response()->json([
×
169
            'success' => false,
×
170
            'message' => current($validator->getErrors()),
×
171
        ]);
×
172
    }
173
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc