1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Admin\Content; |
||
4 | |||
5 | use Apps\ActiveRecord\Content as ContentEntity; |
||
6 | use Apps\Model\Admin\Content\FormContentGlobDelete; |
||
7 | use Ffcms\Core\App; |
||
8 | use Ffcms\Core\Arch\View; |
||
9 | use Ffcms\Core\Exception\NotFoundException; |
||
10 | use Ffcms\Core\Helper\Type\Any; |
||
11 | use Ffcms\Core\Network\Request; |
||
12 | use Ffcms\Core\Network\Response; |
||
13 | |||
14 | /** |
||
15 | * Trait ActionGlobDelete |
||
16 | * @package Apps\Controller\Admin\Content |
||
17 | * @property Request $request |
||
18 | * @property Response $response |
||
19 | * @property View $view |
||
20 | */ |
||
21 | trait ActionGlobDelete |
||
22 | { |
||
23 | /** |
||
24 | * Show content global delete |
||
25 | * @return string |
||
26 | * @throws NotFoundException |
||
27 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
28 | */ |
||
29 | public function globDelete(): ?string |
||
30 | { |
||
31 | // get content ids from request |
||
32 | $ids = $this->request->query->get('selected'); |
||
33 | |||
34 | // check if input is array |
||
35 | if (!Any::isArray($ids) || count($ids) < 1) { |
||
36 | throw new NotFoundException(__('Nothing to delete is founded')); |
||
37 | } |
||
38 | |||
39 | // get all records as object from db |
||
40 | $records = ContentEntity::find($ids); |
||
41 | if ($records->count() < 1) { |
||
42 | throw new NotFoundException(__('Nothing to delete is founded')); |
||
43 | } |
||
44 | |||
45 | // init model and pass objects |
||
46 | $model = new FormContentGlobDelete($records); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
47 | |||
48 | // check if delete is submited |
||
49 | if ($model->send() && $model->validate()) { |
||
50 | $model->make(); |
||
51 | App::$Session->getFlashBag()->add('success', __('Content are successful removed')); |
||
52 | $this->response->redirect('content/index'); |
||
53 | } |
||
54 | |||
55 | // return response |
||
56 | return $this->view->render('content/content_glob_delete', [ |
||
57 | 'model' => $model |
||
58 | ]); |
||
59 | } |
||
60 | } |
||
61 |