1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Front\Profile; |
||
4 | |||
5 | use Apps\ActiveRecord\Blacklist; |
||
6 | use Apps\Model\Front\Profile\FormIgnoreDelete; |
||
7 | use Ffcms\Core\App; |
||
8 | use Ffcms\Core\Arch\View; |
||
9 | use Ffcms\Core\Exception\ForbiddenException; |
||
10 | use Ffcms\Core\Exception\NotFoundException; |
||
11 | use Ffcms\Core\Helper\Type\Any; |
||
12 | use Ffcms\Core\Network\Response; |
||
13 | |||
14 | /** |
||
15 | * Class ActionUnblock |
||
16 | * @package Apps\Controller\Front\Profile |
||
17 | * @property Response $response |
||
18 | * @property View $view |
||
19 | */ |
||
20 | trait ActionUnblock |
||
21 | { |
||
22 | /** |
||
23 | * Unblock always blocked user |
||
24 | * @param string $targetId |
||
25 | * @return string |
||
26 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
27 | * @throws ForbiddenException |
||
28 | * @throws NotFoundException |
||
29 | * @throws \Exception |
||
30 | */ |
||
31 | public function unblock(string $targetId): ?string |
||
32 | { |
||
33 | // check if user is auth |
||
34 | if (!App::$User->isAuth()) { |
||
35 | throw new ForbiddenException(); |
||
36 | } |
||
37 | |||
38 | // check if target is defined |
||
39 | if (!Any::isInt($targetId) || $targetId < 1 || !App::$User->isExist($targetId)) { |
||
40 | throw new NotFoundException(); |
||
41 | } |
||
42 | |||
43 | $user = App::$User->identity(); |
||
44 | |||
45 | // check if target user in blacklist of current user |
||
46 | if (!Blacklist::have($user->getId(), $targetId)) { |
||
47 | throw new NotFoundException(); |
||
48 | } |
||
49 | |||
50 | $model = new FormIgnoreDelete($user, $targetId); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
51 | if ($model->send() && $model->validate()) { |
||
52 | $model->make(); |
||
53 | $this->response->redirect('profile/ignore'); |
||
54 | } |
||
55 | |||
56 | return $this->view->render('profile/unblock', [ |
||
57 | 'model' => $model |
||
58 | ]); |
||
59 | } |
||
60 | } |
||
61 |