Skip to content

Commit f660bc0

Browse files
authored
Merge pull request #231 from HanashiDev/next
Next: 2.2.5
2 parents b258116 + ddbb909 commit f660bc0

14 files changed

+180
-101
lines changed

acptemplates/faqQuestionAdd.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
</nav>
1515
</header>
1616

17-
{unsafe:$form->getHtml()}
17+
{if $categories|count}
18+
{unsafe:$form->getHtml()}
19+
{else}
20+
<woltlab-core-notice type="error">{lang}wcf.acp.faq.question.error.noCategory{/lang}</woltlab-core-notice>
21+
{/if}
1822

1923
{include file='footer'}

files/lib/acp/form/FaqCategoryAddForm.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ protected function createForm()
3939
#[Override]
4040
protected function finalizeForm()
4141
{
42-
parent::finalizeForm();
43-
4442
$this->form->getDataHandler()->addProcessor(
4543
new CustomFormDataProcessor(
4644
'icon',
@@ -59,5 +57,7 @@ function (IFormDocument $document, array $data, IStorableObject $object) {
5957
}
6058
)
6159
);
60+
61+
parent::finalizeForm();
6262
}
6363
}

files/lib/acp/form/FaqQuestionAddForm.class.php

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use wcf\data\IStorableObject;
1212
use wcf\data\language\item\LanguageItemList;
1313
use wcf\form\AbstractFormBuilderForm;
14-
use wcf\system\exception\NamedUserException;
1514
use wcf\system\form\builder\container\FormContainer;
1615
use wcf\system\form\builder\container\TabFormContainer;
1716
use wcf\system\form\builder\container\TabMenuFormContainer;
@@ -60,6 +59,8 @@ class FaqQuestionAddForm extends AbstractFormBuilderForm
6059

6160
protected array $multiLingualAnswers = [];
6261

62+
protected array $categories;
63+
6364
#[Override]
6465
public function readParameters()
6566
{
@@ -102,31 +103,6 @@ protected function createForm()
102103
{
103104
parent::createForm();
104105

105-
$categoryTree = new FaqCategoryNodeTree('dev.tkirch.wsc.faq.category');
106-
$categoryTree->setMaxDepth(0);
107-
$categoryList = $categoryTree->getIterator();
108-
109-
$categories = [];
110-
foreach ($categoryList as $category) {
111-
$categories[$category->categoryID] = $category;
112-
113-
$childCategories = $category->getAllChildCategories();
114-
if (!\count($childCategories)) {
115-
continue;
116-
}
117-
118-
foreach ($childCategories as $childCategory) {
119-
$childCategory->setPrefix();
120-
$categories[$childCategory->categoryID] = $childCategory;
121-
}
122-
}
123-
124-
if (!\count($categories)) {
125-
throw new NamedUserException(
126-
WCF::getLanguage()->getDynamicVariable('wcf.acp.faq.question.error.noCategory')
127-
);
128-
}
129-
130106
$tabContent = [];
131107
if ($this->isMultilingual) {
132108
foreach ($this->availableLanguages as $language) {
@@ -137,6 +113,7 @@ protected function createForm()
137113
->label('wcf.acp.faq.question.answer')
138114
->messageObjectType('dev.tkirch.wsc.faq.question')
139115
->attachmentData('dev.tkirch.wsc.faq.question')
116+
->supportSmilies(true)
140117
->required(),
141118
]);
142119
}
@@ -148,7 +125,7 @@ protected function createForm()
148125
->appendChildren([
149126
SingleSelectionFormField::create('categoryID')
150127
->label('wcf.acp.faq.category')
151-
->options($categories)
128+
->options($this->getCategories())
152129
->required(),
153130
TextFormField::create('question')
154131
->label('wcf.acp.faq.question.question')
@@ -163,8 +140,8 @@ protected function createForm()
163140
: WysiwygFormContainer::create('answer')
164141
->label('wcf.acp.faq.question.answer')
165142
->messageObjectType('dev.tkirch.wsc.faq.question')
166-
// ->messageLanguageItemPattern('wcf.faq.question.answer\d+')
167143
->attachmentData('dev.tkirch.wsc.faq.question')
144+
->supportSmilies(true)
168145
->required()
169146
),
170147
FormContainer::create('position')
@@ -239,4 +216,40 @@ protected function setFormAction()
239216

240217
$this->form->action(LinkHandler::getInstance()->getControllerLink(static::class, $parameters));
241218
}
219+
220+
#[Override]
221+
public function assignVariables()
222+
{
223+
parent::assignVariables();
224+
225+
WCF::getTPL()->assign([
226+
'categories' => $this->getCategories(),
227+
]);
228+
}
229+
230+
protected function getCategories(): array
231+
{
232+
if (!isset($this->categories)) {
233+
$categoryTree = new FaqCategoryNodeTree('dev.tkirch.wsc.faq.category');
234+
$categoryTree->setMaxDepth(0);
235+
$categoryList = $categoryTree->getIterator();
236+
237+
$this->categories = [];
238+
foreach ($categoryList as $category) {
239+
$this->categories[$category->categoryID] = $category;
240+
241+
$childCategories = $category->getAllChildCategories();
242+
if (!\count($childCategories)) {
243+
continue;
244+
}
245+
246+
foreach ($childCategories as $childCategory) {
247+
$childCategory->setPrefix();
248+
$this->categories[$childCategory->categoryID] = $childCategory;
249+
}
250+
}
251+
}
252+
253+
return $this->categories;
254+
}
242255
}

files/lib/data/faq/QuestionEditor.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@
22

33
namespace wcf\data\faq;
44

5+
use Override;
56
use wcf\data\DatabaseObjectEditor;
7+
use wcf\data\IEditableCachedObject;
8+
use wcf\system\cache\builder\FaqQuestionListCacheBuilder;
69
use wcf\system\WCF;
710

811
/**
912
* @method static Question create(array $parameters = [])
1013
* @method Question getDecoratedObject()
1114
* @mixin Question
1215
*/
13-
final class QuestionEditor extends DatabaseObjectEditor
16+
final class QuestionEditor extends DatabaseObjectEditor implements IEditableCachedObject
1417
{
1518
/**
1619
* @inheritDoc
1720
*/
1821
protected static $baseClass = Question::class;
1922

23+
#[Override]
24+
public static function resetCache()
25+
{
26+
FaqQuestionListCacheBuilder::getInstance()->reset();
27+
}
28+
2029
/**
2130
* Returns the new show order for a object
2231
*/

files/lib/data/faq/QuestionList.class.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace wcf\data\faq;
44

5-
use wcf\data\attachment\GroupedAttachmentList;
65
use wcf\data\DatabaseObjectList;
76

87
/**
@@ -18,24 +17,4 @@ final class QuestionList extends DatabaseObjectList
1817
* @inheritDoc
1918
*/
2019
public $sqlOrderBy = 'showOrder, questionID';
21-
22-
private GroupedAttachmentList $attachmentList;
23-
24-
public function readAttachments()
25-
{
26-
if (!empty($this->objectIDs)) {
27-
$this->attachmentList = new GroupedAttachmentList('dev.tkirch.wsc.faq.question');
28-
$this->attachmentList->getConditionBuilder()->add('attachment.objectID IN (?)', [$this->objectIDs]);
29-
$this->attachmentList->readObjects();
30-
}
31-
}
32-
33-
public function getAttachmentList()
34-
{
35-
if (!isset($this->attachmentList)) {
36-
$this->readAttachments();
37-
}
38-
39-
return $this->attachmentList;
40-
}
4120
}

files/lib/data/faq/category/FaqCategory.class.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use wcf\system\request\LinkHandler;
1414
use wcf\system\style\FontAwesomeIcon;
1515
use wcf\system\WCF;
16+
use wcf\util\StringUtil;
1617

1718
/**
1819
* @method FaqCategory[] getChildCategories()
@@ -86,7 +87,17 @@ public function getLink(): string
8687
]);
8788
}
8889

89-
public function getIcon(int $size = 24): string
90+
public function getDescription(): string
91+
{
92+
return WCF::getLanguage()->get($this->description);
93+
}
94+
95+
public function getDescriptionHtml(): string
96+
{
97+
return $this->descriptionUseHtml ? $this->getDescription() : StringUtil::encodeHTML($this->getDescription());
98+
}
99+
100+
public function getIcon(int $size = 24, bool $defaultIcon = false): string
90101
{
91102
if (
92103
isset($this->additionalData['faqIcon'])
@@ -95,6 +106,10 @@ public function getIcon(int $size = 24): string
95106
return FontAwesomeIcon::fromString($this->additionalData['faqIcon'])->toHtml($size);
96107
}
97108

109+
if ($defaultIcon) {
110+
return FontAwesomeIcon::fromString('circle-question;false')->toHtml($size);
111+
}
112+
98113
return '';
99114
}
100115
}

files/lib/page/FaqQuestionListPage.class.php

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use CuyZ\Valinor\Mapper\MappingError;
66
use Override;
7+
use wcf\data\attachment\GroupedAttachmentList;
78
use wcf\data\faq\category\FaqCategory;
89
use wcf\data\faq\category\FaqCategoryNodeTree;
9-
use wcf\data\faq\QuestionList;
1010
use wcf\http\Helper;
11+
use wcf\system\cache\builder\FaqQuestionListCacheBuilder;
1112
use wcf\system\exception\IllegalLinkException;
1213
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
1314
use wcf\system\WCF;
@@ -19,6 +20,8 @@ class FaqQuestionListPage extends AbstractPage
1920
*/
2021
public $neededPermissions = ['user.faq.canViewFAQ'];
2122

23+
protected array $faqs = [];
24+
2225
protected int $showFaqAddDialog = 0;
2326

2427
protected ?FaqCategory $category;
@@ -49,14 +52,15 @@ public function readParameters()
4952
}
5053

5154
#[Override]
52-
public function assignVariables()
55+
public function readData()
5356
{
54-
parent::assignVariables();
57+
parent::readData();
5558

5659
//get categories
57-
$faqs = [];
5860
$embedObjectIDs = [];
5961
$categoryTree = new FaqCategoryNodeTree('dev.tkirch.wsc.faq.category');
62+
[$questionList, $questionIDs] = FaqQuestionListCacheBuilder::getInstance()->getData();
63+
$attachmentList = $this->getAttachmentList($questionIDs);
6064
foreach ($categoryTree->getIterator() as $category) {
6165
if (!$category->isAccessible()) {
6266
continue;
@@ -69,23 +73,14 @@ public function assignVariables()
6973
continue;
7074
}
7175

72-
$questionList = new QuestionList();
73-
$questionList->getConditionBuilder()->add('categoryID = ?', [$category->categoryID]);
74-
$questionList->readObjects();
75-
76-
if (!\count($questionList)) {
77-
continue;
78-
}
79-
8076
$faq = [
81-
'id' => $category->categoryID,
82-
'title' => WCF::getLanguage()->get($category->title),
83-
'attachments' => $questionList->getAttachmentList(),
84-
'icon24' => $category->getIcon(24),
85-
'icon64' => $category->getIcon(64),
77+
'category' => $category,
78+
'attachments' => $attachmentList,
79+
'questions' => [],
8680
];
8781

88-
foreach ($questionList->getObjects() as $question) {
82+
$questions = $questionList[$category->categoryID] ?? [];
83+
foreach ($questions as $question) {
8984
if ($question->isAccessible()) {
9085
$faq['questions'][] = $question;
9186
if ($question->hasEmbeddedObjects) {
@@ -95,22 +90,41 @@ public function assignVariables()
9590
}
9691

9792
if ($category->getParentNode() && $category->getParentNode()->categoryID) {
98-
$faqs[$category->getParentNode()->categoryID]['sub'][$category->categoryID] = $faq;
93+
$this->faqs[$category->getParentNode()->categoryID]['sub'][$category->categoryID] = $faq;
9994
} else {
100-
$faqs[$category->categoryID] = $faq;
95+
$this->faqs[$category->categoryID] = $faq;
10196
}
10297
}
10398

104-
if (\count($embedObjectIDs)) {
99+
if ($embedObjectIDs !== []) {
105100
MessageEmbeddedObjectManager::getInstance()->loadObjects(
106101
'dev.tkirch.wsc.faq.question',
107102
$embedObjectIDs
108103
);
109104
}
105+
}
106+
107+
#[Override]
108+
public function assignVariables()
109+
{
110+
parent::assignVariables();
110111

111112
WCF::getTPL()->assign([
112-
'faqs' => $faqs,
113+
'faqs' => $this->faqs,
113114
'showFaqAddDialog' => $this->showFaqAddDialog,
114115
]);
115116
}
117+
118+
protected function getAttachmentList(array $questionIDs): array|GroupedAttachmentList
119+
{
120+
if ($questionIDs === []) {
121+
return [];
122+
}
123+
124+
$attachmentList = new GroupedAttachmentList('dev.tkirch.wsc.faq.question');
125+
$attachmentList->getConditionBuilder()->add('attachment.objectID IN (?)', [$questionIDs]);
126+
$attachmentList->readObjects();
127+
128+
return $attachmentList;
129+
}
116130
}

files/lib/system/box/FaqCategoriesBoxController.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ protected function getResetFilterLink(): string
4646
#[Override]
4747
public function hasContent()
4848
{
49-
return SIMPLE_FAQ_VIEW !== 'gallery';
49+
$categoryTree = $this->getNodeTree();
50+
$categoryList = $categoryTree->getIterator();
51+
52+
return SIMPLE_FAQ_VIEW !== 'gallery' && \iterator_count($categoryList);
5053
}
5154
}

0 commit comments

Comments
 (0)