Skip to content

Commit

Permalink
Merge pull request #231 from HanashiDev/next
Browse files Browse the repository at this point in the history
Next: 2.2.5
  • Loading branch information
Hanashi authored Nov 2, 2024
2 parents b258116 + ddbb909 commit f660bc0
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 101 deletions.
6 changes: 5 additions & 1 deletion acptemplates/faqQuestionAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</nav>
</header>

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

{include file='footer'}
4 changes: 2 additions & 2 deletions files/lib/acp/form/FaqCategoryAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ protected function createForm()
#[Override]
protected function finalizeForm()
{
parent::finalizeForm();

$this->form->getDataHandler()->addProcessor(
new CustomFormDataProcessor(
'icon',
Expand All @@ -59,5 +57,7 @@ function (IFormDocument $document, array $data, IStorableObject $object) {
}
)
);

parent::finalizeForm();
}
}
69 changes: 41 additions & 28 deletions files/lib/acp/form/FaqQuestionAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use wcf\data\IStorableObject;
use wcf\data\language\item\LanguageItemList;
use wcf\form\AbstractFormBuilderForm;
use wcf\system\exception\NamedUserException;
use wcf\system\form\builder\container\FormContainer;
use wcf\system\form\builder\container\TabFormContainer;
use wcf\system\form\builder\container\TabMenuFormContainer;
Expand Down Expand Up @@ -60,6 +59,8 @@ class FaqQuestionAddForm extends AbstractFormBuilderForm

protected array $multiLingualAnswers = [];

protected array $categories;

#[Override]
public function readParameters()
{
Expand Down Expand Up @@ -102,31 +103,6 @@ protected function createForm()
{
parent::createForm();

$categoryTree = new FaqCategoryNodeTree('dev.tkirch.wsc.faq.category');
$categoryTree->setMaxDepth(0);
$categoryList = $categoryTree->getIterator();

$categories = [];
foreach ($categoryList as $category) {
$categories[$category->categoryID] = $category;

$childCategories = $category->getAllChildCategories();
if (!\count($childCategories)) {
continue;
}

foreach ($childCategories as $childCategory) {
$childCategory->setPrefix();
$categories[$childCategory->categoryID] = $childCategory;
}
}

if (!\count($categories)) {
throw new NamedUserException(
WCF::getLanguage()->getDynamicVariable('wcf.acp.faq.question.error.noCategory')
);
}

$tabContent = [];
if ($this->isMultilingual) {
foreach ($this->availableLanguages as $language) {
Expand All @@ -137,6 +113,7 @@ protected function createForm()
->label('wcf.acp.faq.question.answer')
->messageObjectType('dev.tkirch.wsc.faq.question')
->attachmentData('dev.tkirch.wsc.faq.question')
->supportSmilies(true)
->required(),
]);
}
Expand All @@ -148,7 +125,7 @@ protected function createForm()
->appendChildren([
SingleSelectionFormField::create('categoryID')
->label('wcf.acp.faq.category')
->options($categories)
->options($this->getCategories())
->required(),
TextFormField::create('question')
->label('wcf.acp.faq.question.question')
Expand All @@ -163,8 +140,8 @@ protected function createForm()
: WysiwygFormContainer::create('answer')
->label('wcf.acp.faq.question.answer')
->messageObjectType('dev.tkirch.wsc.faq.question')
// ->messageLanguageItemPattern('wcf.faq.question.answer\d+')
->attachmentData('dev.tkirch.wsc.faq.question')
->supportSmilies(true)
->required()
),
FormContainer::create('position')
Expand Down Expand Up @@ -239,4 +216,40 @@ protected function setFormAction()

$this->form->action(LinkHandler::getInstance()->getControllerLink(static::class, $parameters));
}

#[Override]
public function assignVariables()
{
parent::assignVariables();

WCF::getTPL()->assign([
'categories' => $this->getCategories(),
]);
}

protected function getCategories(): array
{
if (!isset($this->categories)) {
$categoryTree = new FaqCategoryNodeTree('dev.tkirch.wsc.faq.category');
$categoryTree->setMaxDepth(0);
$categoryList = $categoryTree->getIterator();

$this->categories = [];
foreach ($categoryList as $category) {
$this->categories[$category->categoryID] = $category;

$childCategories = $category->getAllChildCategories();
if (!\count($childCategories)) {
continue;
}

foreach ($childCategories as $childCategory) {
$childCategory->setPrefix();
$this->categories[$childCategory->categoryID] = $childCategory;
}
}
}

return $this->categories;
}
}
11 changes: 10 additions & 1 deletion files/lib/data/faq/QuestionEditor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

namespace wcf\data\faq;

use Override;
use wcf\data\DatabaseObjectEditor;
use wcf\data\IEditableCachedObject;
use wcf\system\cache\builder\FaqQuestionListCacheBuilder;
use wcf\system\WCF;

/**
* @method static Question create(array $parameters = [])
* @method Question getDecoratedObject()
* @mixin Question
*/
final class QuestionEditor extends DatabaseObjectEditor
final class QuestionEditor extends DatabaseObjectEditor implements IEditableCachedObject
{
/**
* @inheritDoc
*/
protected static $baseClass = Question::class;

#[Override]
public static function resetCache()
{
FaqQuestionListCacheBuilder::getInstance()->reset();
}

/**
* Returns the new show order for a object
*/
Expand Down
21 changes: 0 additions & 21 deletions files/lib/data/faq/QuestionList.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace wcf\data\faq;

use wcf\data\attachment\GroupedAttachmentList;
use wcf\data\DatabaseObjectList;

/**
Expand All @@ -18,24 +17,4 @@ final class QuestionList extends DatabaseObjectList
* @inheritDoc
*/
public $sqlOrderBy = 'showOrder, questionID';

private GroupedAttachmentList $attachmentList;

public function readAttachments()
{
if (!empty($this->objectIDs)) {
$this->attachmentList = new GroupedAttachmentList('dev.tkirch.wsc.faq.question');
$this->attachmentList->getConditionBuilder()->add('attachment.objectID IN (?)', [$this->objectIDs]);
$this->attachmentList->readObjects();
}
}

public function getAttachmentList()
{
if (!isset($this->attachmentList)) {
$this->readAttachments();
}

return $this->attachmentList;
}
}
17 changes: 16 additions & 1 deletion files/lib/data/faq/category/FaqCategory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use wcf\system\request\LinkHandler;
use wcf\system\style\FontAwesomeIcon;
use wcf\system\WCF;
use wcf\util\StringUtil;

/**
* @method FaqCategory[] getChildCategories()
Expand Down Expand Up @@ -86,7 +87,17 @@ public function getLink(): string
]);
}

public function getIcon(int $size = 24): string
public function getDescription(): string
{
return WCF::getLanguage()->get($this->description);
}

public function getDescriptionHtml(): string
{
return $this->descriptionUseHtml ? $this->getDescription() : StringUtil::encodeHTML($this->getDescription());
}

public function getIcon(int $size = 24, bool $defaultIcon = false): string
{
if (
isset($this->additionalData['faqIcon'])
Expand All @@ -95,6 +106,10 @@ public function getIcon(int $size = 24): string
return FontAwesomeIcon::fromString($this->additionalData['faqIcon'])->toHtml($size);
}

if ($defaultIcon) {
return FontAwesomeIcon::fromString('circle-question;false')->toHtml($size);
}

return '';
}
}
58 changes: 36 additions & 22 deletions files/lib/page/FaqQuestionListPage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use CuyZ\Valinor\Mapper\MappingError;
use Override;
use wcf\data\attachment\GroupedAttachmentList;
use wcf\data\faq\category\FaqCategory;
use wcf\data\faq\category\FaqCategoryNodeTree;
use wcf\data\faq\QuestionList;
use wcf\http\Helper;
use wcf\system\cache\builder\FaqQuestionListCacheBuilder;
use wcf\system\exception\IllegalLinkException;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\WCF;
Expand All @@ -19,6 +20,8 @@ class FaqQuestionListPage extends AbstractPage
*/
public $neededPermissions = ['user.faq.canViewFAQ'];

protected array $faqs = [];

protected int $showFaqAddDialog = 0;

protected ?FaqCategory $category;
Expand Down Expand Up @@ -49,14 +52,15 @@ public function readParameters()
}

#[Override]
public function assignVariables()
public function readData()
{
parent::assignVariables();
parent::readData();

//get categories
$faqs = [];
$embedObjectIDs = [];
$categoryTree = new FaqCategoryNodeTree('dev.tkirch.wsc.faq.category');
[$questionList, $questionIDs] = FaqQuestionListCacheBuilder::getInstance()->getData();
$attachmentList = $this->getAttachmentList($questionIDs);
foreach ($categoryTree->getIterator() as $category) {
if (!$category->isAccessible()) {
continue;
Expand All @@ -69,23 +73,14 @@ public function assignVariables()
continue;
}

$questionList = new QuestionList();
$questionList->getConditionBuilder()->add('categoryID = ?', [$category->categoryID]);
$questionList->readObjects();

if (!\count($questionList)) {
continue;
}

$faq = [
'id' => $category->categoryID,
'title' => WCF::getLanguage()->get($category->title),
'attachments' => $questionList->getAttachmentList(),
'icon24' => $category->getIcon(24),
'icon64' => $category->getIcon(64),
'category' => $category,
'attachments' => $attachmentList,
'questions' => [],
];

foreach ($questionList->getObjects() as $question) {
$questions = $questionList[$category->categoryID] ?? [];
foreach ($questions as $question) {
if ($question->isAccessible()) {
$faq['questions'][] = $question;
if ($question->hasEmbeddedObjects) {
Expand All @@ -95,22 +90,41 @@ public function assignVariables()
}

if ($category->getParentNode() && $category->getParentNode()->categoryID) {
$faqs[$category->getParentNode()->categoryID]['sub'][$category->categoryID] = $faq;
$this->faqs[$category->getParentNode()->categoryID]['sub'][$category->categoryID] = $faq;
} else {
$faqs[$category->categoryID] = $faq;
$this->faqs[$category->categoryID] = $faq;
}
}

if (\count($embedObjectIDs)) {
if ($embedObjectIDs !== []) {
MessageEmbeddedObjectManager::getInstance()->loadObjects(
'dev.tkirch.wsc.faq.question',
$embedObjectIDs
);
}
}

#[Override]
public function assignVariables()
{
parent::assignVariables();

WCF::getTPL()->assign([
'faqs' => $faqs,
'faqs' => $this->faqs,
'showFaqAddDialog' => $this->showFaqAddDialog,
]);
}

protected function getAttachmentList(array $questionIDs): array|GroupedAttachmentList
{
if ($questionIDs === []) {
return [];
}

$attachmentList = new GroupedAttachmentList('dev.tkirch.wsc.faq.question');
$attachmentList->getConditionBuilder()->add('attachment.objectID IN (?)', [$questionIDs]);
$attachmentList->readObjects();

return $attachmentList;
}
}
5 changes: 4 additions & 1 deletion files/lib/system/box/FaqCategoriesBoxController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ protected function getResetFilterLink(): string
#[Override]
public function hasContent()
{
return SIMPLE_FAQ_VIEW !== 'gallery';
$categoryTree = $this->getNodeTree();
$categoryList = $categoryTree->getIterator();

return SIMPLE_FAQ_VIEW !== 'gallery' && \iterator_count($categoryList);
}
}
Loading

0 comments on commit f660bc0

Please sign in to comment.