Passed
Push — master ( 81f334...c86e8c )
by Mihail
03:35
created

ActionClear::clear()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 2
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\Content;
4
5
use Apps\Model\Admin\Content\FormContentClear;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Network\Request;
9
use Ffcms\Core\Network\Response;
10
use Apps\ActiveRecord\Content as ContentEntity;
11
12
/**
13
 * Trait ActionClear
14
 * @package Apps\Controller\Admin\Content
15
 * @property Request $request
16
 * @property Response $response
17
 * @property View $view
18
 */
19
trait ActionClear
20
{
21
    /**
22
     * Clear all trashed items
23
     * @return string
24
     * @throws \Ffcms\Core\Exception\SyntaxException
25
     */
26
    public function clear(): ?string
27
    {
28
        // find trashed rows
29
        $records = ContentEntity::onlyTrashed();
30
31
        // init model
32
        $model = new FormContentClear($records);
33
        if ($model->send() && $model->validate()) {
34
            $model->make();
35
            App::$Session->getFlashBag()->add('success', __('Trash content is cleaned'));
36
            $this->response->redirect('content/index');
37
        }
38
39
        // draw response
40
        return $this->view->render('content_clear', [
41
            'model' => $model
42
        ]);
43
    }
44
}
45