1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\Faq\Actions; |
4
|
|
|
|
5
|
|
|
use Backend\Core\Engine\Base\ActionAdd as BackendBaseActionAdd; |
6
|
|
|
use Backend\Core\Engine\Form as BackendForm; |
7
|
|
|
use Backend\Core\Language\Language as BL; |
8
|
|
|
use Backend\Core\Engine\Meta as BackendMeta; |
9
|
|
|
use Backend\Core\Engine\Model as BackendModel; |
10
|
|
|
use Backend\Modules\Faq\Engine\Model as BackendFaqModel; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This is the add-action, it will display a form to create a new category |
14
|
|
|
*/ |
15
|
|
|
class AddCategory extends BackendBaseActionAdd |
16
|
|
|
{ |
17
|
|
|
public function execute(): void |
18
|
|
|
{ |
19
|
|
|
// only one category allowed, so we redirect |
20
|
|
|
if (!$this->get('fork.settings')->get('Faq', 'allow_multiple_categories', true)) { |
21
|
|
|
$this->redirect(BackendModel::createUrlForAction('Categories') . '&error=only-one-category-allowed'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
parent::execute(); |
25
|
|
|
$this->loadForm(); |
26
|
|
|
$this->validateForm(); |
27
|
|
|
$this->parse(); |
28
|
|
|
$this->display(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function parse(): void |
32
|
|
|
{ |
33
|
|
|
parent::parse(); |
34
|
|
|
|
35
|
|
|
$url = BackendModel::getUrlForBlock($this->url->getModule(), 'Category'); |
36
|
|
|
$url404 = BackendModel::getUrl(BackendModel::ERROR_PAGE_ID); |
37
|
|
|
if ($url404 != $url) { |
38
|
|
|
$this->template->assign('detailURL', SITE_URL . $url); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
private function loadForm(): void |
43
|
|
|
{ |
44
|
|
|
$this->form = new BackendForm('addCategory'); |
45
|
|
|
$this->form->addText('title')->makeRequired(); |
46
|
|
|
|
47
|
|
|
$this->meta = new BackendMeta($this->form, null, 'title', true); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function validateForm(): void |
51
|
|
|
{ |
52
|
|
|
if ($this->form->isSubmitted()) { |
53
|
|
|
$this->meta->setUrlCallback('Backend\Modules\Faq\Engine\Model', 'getUrlForCategory'); |
54
|
|
|
|
55
|
|
|
$this->form->cleanupFields(); |
56
|
|
|
|
57
|
|
|
// validate fields |
58
|
|
|
$this->form->getField('title')->isFilled(BL::err('TitleIsRequired')); |
59
|
|
|
$this->meta->validate(); |
60
|
|
|
|
61
|
|
|
if ($this->form->isCorrect()) { |
62
|
|
|
// build item |
63
|
|
|
$item = []; |
64
|
|
|
$item['title'] = $this->form->getField('title')->getValue(); |
65
|
|
|
$item['language'] = BL::getWorkingLanguage(); |
66
|
|
|
$item['meta_id'] = $this->meta->save(); |
67
|
|
|
$item['sequence'] = BackendFaqModel::getMaximumCategorySequence() + 1; |
68
|
|
|
|
69
|
|
|
// save the data |
70
|
|
|
$item['id'] = BackendFaqModel::insertCategory($item); |
71
|
|
|
|
72
|
|
|
// everything is saved, so redirect to the overview |
73
|
|
|
$this->redirect( |
74
|
|
|
BackendModel::createUrlForAction('Categories') . '&report=added-category&var=' . |
75
|
|
|
rawurlencode($item['title']) . '&highlight=row-' . $item['id'] |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|