1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Admin\Comments; |
||
4 | |||
5 | use Apps\ActiveRecord\CommentAnswer; |
||
6 | use Apps\ActiveRecord\CommentPost; |
||
7 | use Ffcms\Core\Arch\View; |
||
8 | use Ffcms\Core\Exception\NotFoundException; |
||
9 | use Ffcms\Core\Network\Request; |
||
10 | use Ffcms\Core\Network\Response; |
||
11 | |||
12 | /** |
||
13 | * Trait ActionDisplay |
||
14 | * @package Apps\Controller\Admin\Comments |
||
15 | * @property Request $request |
||
16 | * @property Response $response |
||
17 | * @property View $view |
||
18 | */ |
||
19 | trait ActionDisplay |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Change moderate status in comment/answer and redirect back |
||
24 | * @param string $type |
||
25 | * @param int $id |
||
26 | * @throws NotFoundException |
||
27 | */ |
||
28 | public function display($type, $id) |
||
29 | { |
||
30 | /** @var CommentPost|CommentAnswer|null $record */ |
||
31 | $record = null; |
||
32 | switch ($type) { |
||
33 | case self::TYPE_COMMENT: |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
34 | $record = CommentPost::find($id); |
||
35 | break; |
||
36 | case self::TYPE_ANSWER: |
||
0 ignored issues
–
show
|
|||
37 | $record = CommentAnswer::find($id); |
||
38 | break; |
||
39 | } |
||
40 | |||
41 | if (!$record) { |
||
42 | throw new NotFoundException('No comments found'); |
||
43 | } |
||
44 | |||
45 | $record->moderate = !$record->moderate; |
||
46 | $record->save(); |
||
47 | |||
48 | if ($type === self::TYPE_ANSWER) { |
||
49 | $this->response->redirect('comments/answerlist'); |
||
50 | } |
||
51 | |||
52 | $this->response->redirect('comments/index'); |
||
53 | } |
||
54 | } |
||
55 |