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\Helper\Url; |
13
|
|
|
use Ffcms\Core\Network\Response; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ActionUnblock |
17
|
|
|
* @package Apps\Controller\Front\Profile |
18
|
|
|
* @property Response $response |
19
|
|
|
* @property View $view |
20
|
|
|
*/ |
21
|
|
|
trait ActionUnblock |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Unblock always blocked user |
25
|
|
|
* @param string $targetId |
26
|
|
|
* @return string |
27
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
28
|
|
|
* @throws ForbiddenException |
29
|
|
|
* @throws NotFoundException |
30
|
|
|
* @throws \Exception |
31
|
|
|
*/ |
32
|
|
|
public function unblock($targetId) |
33
|
|
|
{ |
34
|
|
|
// check if user is auth |
35
|
|
|
if (!App::$User->isAuth()) { |
36
|
|
|
throw new ForbiddenException(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// check if target is defined |
40
|
|
View Code Duplication |
if (!Any::isInt($targetId) || $targetId < 1 || !App::$User->isExist($targetId)) { |
|
|
|
|
41
|
|
|
throw new NotFoundException(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$user = App::$User->identity(); |
45
|
|
|
|
46
|
|
|
// check if target user in blacklist of current user |
47
|
|
|
if (!Blacklist::have($user->getId(), $targetId)) { |
48
|
|
|
throw new NotFoundException(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$model = new FormIgnoreDelete($user, $targetId); |
52
|
|
|
if ($model->send() && $model->validate()) { |
53
|
|
|
$model->make(); |
54
|
|
|
$this->response->redirect(Url::to('profile/ignore')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->view->render('unblock', [ |
58
|
|
|
'model' => $model |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.