Passed
Push — master ( c57047...e9f946 )
by Mihail
06:06
created

ActionDisplayChange::display()   A

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