|
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\Helper\Type\Any; |
|
11
|
|
|
use Ffcms\Core\Network\Request; |
|
12
|
|
|
use Ffcms\Core\Network\Response; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait ActionCategoryUpdate |
|
16
|
|
|
* @package Apps\Controller\Admin\Content |
|
17
|
|
|
* @property Request $request |
|
18
|
|
|
* @property Response $response |
|
19
|
|
|
* @property View $view |
|
20
|
|
|
*/ |
|
21
|
|
|
trait ActionCategoryUpdate |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Show category edit and create |
|
25
|
|
|
* @param string|null $id |
|
26
|
|
|
* @return string |
|
27
|
|
|
* @throws SyntaxException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function categoryUpdate(?string $id = null): ?string |
|
30
|
|
|
{ |
|
31
|
|
|
if (!Any::isInt($id) || $id < 1) { |
|
32
|
|
|
throw new SyntaxException('Wrong id'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// get owner id for new rows |
|
36
|
|
|
$parentId = (int)$this->request->query->get('parent'); |
|
37
|
|
|
|
|
38
|
|
|
// get relation and pass to model |
|
39
|
|
|
$record = ContentCategory::findOrNew($id); |
|
40
|
|
|
$isNew = $record->id === null; |
|
41
|
|
|
$model = new FormCategoryUpdate($record, $parentId); |
|
42
|
|
|
|
|
43
|
|
|
// if model is submited |
|
44
|
|
|
if ($model->send() && $model->validate()) { |
|
45
|
|
|
$model->save(); |
|
46
|
|
|
// if is new - redirect to list after submit |
|
47
|
|
|
if ($isNew) { |
|
48
|
|
|
$this->response->redirect('content/categories'); |
|
49
|
|
|
} |
|
50
|
|
|
// show notify message |
|
51
|
|
|
App::$Session->getFlashBag()->add('success', __('Category is successful updated')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// draw response view and pass model properties |
|
55
|
|
|
return $this->view->render('category_update', [ |
|
56
|
|
|
'model' => $model |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|