ActionDisplayChange::display()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\Content;
4
5
use Ffcms\Core\Arch\View;
6
use Ffcms\Core\Exception\NotFoundException;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
10
/**
11
 * Trait ActionDisplayChange
12
 * @package Apps\Controller\Admin\Content
13
 * @property Request $request
14
 * @property Response $response
15
 * @property View $view
16
 */
17
trait ActionDisplayChange
18
{
19
    /**
20
     * Change content display status on user request
21
     * @param $id
22
     * @throws NotFoundException
23
     * @return void
24
     */
25
    public function display(string $id): void
26
    {
27
        $status = (bool)$this->request->query->get('status', 0);
28
        $content = \Apps\ActiveRecord\Content::find($id);
29
        if (!$content) {
30
            throw new NotFoundException(__('Content {%id%} are not exist', ['id' => $id]));
31
        }
32
        // make update query if status is different than required
33
        if ((bool)$content->display !== $status) {
34
            $content->display = $status;
35
            $content->save();
36
        }
37
38
        $this->response->redirect('content/index');
39
    }
40
}
41