1 | <?php |
||
2 | |||
3 | namespace Apps\Controller\Admin\Content; |
||
4 | |||
5 | use Apps\ActiveRecord\ContentCategory; |
||
6 | use Apps\Model\Admin\Content\FormCategoryUpdate; |
||
7 | use Ffcms\Core\App; |
||
8 | use Ffcms\Core\Arch\View; |
||
9 | use Ffcms\Core\Exception\SyntaxException; |
||
10 | use Ffcms\Core\Network\Request; |
||
11 | use Ffcms\Core\Network\Response; |
||
12 | |||
13 | /** |
||
14 | * Trait ActionCategoryUpdate |
||
15 | * @package Apps\Controller\Admin\Content |
||
16 | * @property Request $request |
||
17 | * @property Response $response |
||
18 | * @property View $view |
||
19 | */ |
||
20 | trait ActionCategoryUpdate |
||
21 | { |
||
22 | /** |
||
23 | * Show category edit and create |
||
24 | * @param string|null $id |
||
25 | * @return string |
||
26 | * @throws SyntaxException |
||
27 | */ |
||
28 | public function categoryUpdate(?string $id = null): ?string |
||
29 | { |
||
30 | // get owner id for new rows |
||
31 | $parentId = $this->request->query->get('parent', null); |
||
32 | |||
33 | // get relation and pass to model |
||
34 | $record = ContentCategory::findOrNew($id); |
||
35 | $isNew = $record->id === null; |
||
36 | $model = new FormCategoryUpdate($record, $parentId); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
37 | |||
38 | // if model is submited |
||
39 | if ($model->send() && $model->validate()) { |
||
40 | $model->save(); |
||
41 | // if is new - redirect to list after submit |
||
42 | if ($isNew) { |
||
43 | $this->response->redirect('content/categories'); |
||
44 | } |
||
45 | // show notify message |
||
46 | App::$Session->getFlashBag()->add('success', __('Category is successful updated')); |
||
47 | } |
||
48 | |||
49 | // draw response view and pass model properties |
||
50 | return $this->view->render('content/category_update', [ |
||
51 | 'model' => $model |
||
52 | ]); |
||
53 | } |
||
54 | } |
||
55 |