Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 17 additions & 108 deletions acptemplates/faqQuestionList.tpl
Original file line number Diff line number Diff line change
@@ -1,129 +1,38 @@
{include file='header' pageTitle='wcf.acp.menu.link.faq.questions.list'}

<script data-relocate="true">
require(['WoltLabSuite/Core/Ui/Sortable/List'], function (UiSortableList) {
new UiSortableList({
containerId: 'questionList',
className: 'wcf\\data\\faq\\QuestionAction',
offset: {$startIndex}
});
});
</script>

<header class="contentHeader">
<div class="contentHeaderTitle">
<h1 class="contentTitle">{lang}wcf.acp.menu.link.faq.questions.list{/lang}</h1>
</div>

<nav class="contentHeaderNavigation">
<ul>
{if $gridView->countRows() > 1}
<li>
<button type="button" class="button jsChangeShowOrder">{icon name='up-down'} <span>{lang}wcf.global.changeShowOrder{/lang}</span></button>
</li>
{/if}
<li><a href="{link controller='FaqQuestionAdd'}{/link}" class="button">{icon name='plus' size=16} <span>{lang}wcf.acp.menu.link.faq.questions.add{/lang}</span></a></li>

{event name='contentHeaderNavigation'}
</ul>
</nav>
</header>

<form method="post" action="{link controller='FaqQuestionList'}{/link}">
<section class="section">
<h2 class="sectionTitle">{lang}wcf.global.filter{/lang}</h2>

<div class="row rowColGap formGrid">
<dl class="col-xs-12 col-md-4">
<dt></dt>
<dd>
<select name="categoryID" id="categoryID">
<option value="0">{lang}wcf.acp.faq.category{/lang}</option>

{foreach from=$categoryNodeList item=category}
<option value="{$category->categoryID}"{if $category->categoryID == $categoryID} selected{/if}>{if $category->getDepth() > 1}{unsafe:"&nbsp;&nbsp;&nbsp;&nbsp;"|str_repeat:($category->getDepth() - 1)}{/if}{$category->getTitle()}</option>
{/foreach}
</select>
</dd>
</dl>

<dl class="col-xs-12 col-md-4">
<dt></dt>
<dd>
<input type="text" id="question" name="question" value="{$question}" placeholder="{lang}wcf.faq.question.question.title{/lang}" class="long">
</dd>
</dl>

<dl class="col-xs-12 col-md-4">
<dt></dt>
<dd>
<input type="text" id="answer" name="answer" value="{$answer}" placeholder="{lang}wcf.faq.question.answer.title{/lang}" class="long">
</dd>
</dl>

{event name='filterFields'}
</div>

<div class="formSubmit">
<input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
{csrfToken}
</div>
</section>
</form>

{hascontent}
<div class="paginationTop">
{content}
{assign var='linkParameters' value=''}
{if $categoryID}{capture append=linkParameters}&categoryID={$categoryID}{/capture}{/if}
{if $question}{capture append=linkParameters}&question={unsafe:$question|rawurlencode}{/capture}{/if}
{if $answer}{capture append=linkParameters}&answer={unsafe:$answer|rawurlencode}{/capture}{/if}

{pages print=true assign=pagesLinks controller="FaqQuestionList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$linkParameters"}
{/content}
</div>
{/hascontent}

{if $objects|count}
<div class="section sortableListContainer" id="questionList">
<ol class="sortableList jsObjectActionContainer jsReloadPageWhenEmpty" data-object-id="0" start="{($pageNo - 1) * $itemsPerPage + 1}" data-object-action-class-name="wcf\data\faq\QuestionAction">
{foreach from=$objects item=question}
<li class="sortableNode sortableNoNesting jsQuestion jsObjectActionObject" data-object-id="{$question->questionID}">
<span class="sortableNodeLabel">
({$question->getCategory()->getTitle()})&nbsp;
<a href="{link controller='FaqQuestionEdit' object=$question}{/link}">{$question->getTitle()}</a>
<div class="section">
{unsafe:$gridView->render()}
</div>

<span class="statusDisplay sortableButtonContainer">
{objectAction action="toggle" isDisabled=$question->isDisabled}
<a href="{link controller='FaqQuestionAdd' duplicateID=$question->questionID isMultilingual=$question->isMultilingual}{/link}" title="{lang}wcf.acp.faqQuestion.copy{/lang}" class="jsTooltip">{icon name='copy' size=16}</a>
<a href="{link controller='FaqQuestionEdit' object=$question}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip">{icon name='pencil' size=16}</a>
{objectAction action="delete" objectTitle=$question->getTitle()}

{event name='itemButtons'}
</span>
</span>
</li>
{/foreach}
</ol>
</div>

<div class="formSubmit">
<button class="button buttonPrimary" data-type="submit">{lang}wcf.global.button.saveSorting{/lang}</button>
</div>
<script data-relocate="true">
require(["WoltLabSuite/Core/Component/ChangeShowOrder"], ({ setup }) => {
{jsphrase name='wcf.global.changeShowOrder'}

<footer class="contentFooter">
{hascontent}
<div class="paginationBottom">
{content}{unsafe:$pagesLinks}{/content}
</div>
{/hascontent}

<nav class="contentFooterNavigation">
<ul>
<li><a href="{link controller='FaqQuestionAdd'}{/link}" class="button">{icon name='plus' size=16} <span>{lang}wcf.acp.menu.link.faq.questions.add{/lang}</span></a></li>

{event name='contentFooterNavigation'}
</ul>
</nav>
</footer>
{else}
<p class="info">{lang}wcf.global.noItems{/lang}</p>
{/if}
setup(
document.querySelector('.jsChangeShowOrder'),
'hanashi/questions/show-order',
);
});
</script>

{include file='faqQuestionAddDialog'}

Expand Down
72 changes: 6 additions & 66 deletions files/lib/acp/page/FaqQuestionListPage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace wcf\acp\page;

use Override;
use wcf\data\category\CategoryNodeTree;
use wcf\data\faq\QuestionList;
use wcf\page\SortablePage;
use wcf\page\AbstractGridViewPage;
use wcf\system\gridView\AbstractGridView;
use wcf\system\gridView\admin\FaqQuestionGridView;
use wcf\system\WCF;
use wcf\util\StringUtil;

class FaqQuestionListPage extends SortablePage
final class FaqQuestionListPage extends AbstractGridViewPage
{
/**
* @inheritDoc
Expand All @@ -21,77 +20,22 @@ class FaqQuestionListPage extends SortablePage
*/
public $neededPermissions = ['admin.faq.canViewQuestion'];

/**
* @inheritDoc
*/
public $objectListClassName = QuestionList::class;

/**
* @inheritDoc
*/
public $validSortFields = ['questionID', 'categoryID', 'showOrder'];

/**
* category id
*/
public int $categoryID = 0;

/**
* question
*/
public string $question = '';

/**
* answer
*/
public string $answer = '';

public int $showFaqAddDialog = 0;

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

if (isset($_REQUEST['categoryID'])) {
$this->categoryID = (int)$_REQUEST['categoryID'];
}
if (!empty($_REQUEST['question'])) {
$this->question = StringUtil::trim($_REQUEST['question']);
}
if (!empty($_REQUEST['answer'])) {
$this->answer = StringUtil::trim($_REQUEST['answer']);
}
if (!empty($_REQUEST['showFaqAddDialog'])) {
$this->showFaqAddDialog = 1;
}
}

#[Override]
protected function initObjectList()
protected function createGridView(): AbstractGridView
{
parent::initObjectList();

if ($this->categoryID) {
$this->objectList->getConditionBuilder()->add(
'faq_questions.categoryID = ?',
[$this->categoryID]
);
}

if (!empty($this->question)) {
$this->objectList->getConditionBuilder()->add(
'faq_questions.question LIKE ?',
['%' . WCF::getDB()->escapeLikeValue($this->question) . '%']
);
}

if (!empty($this->answer)) {
$this->objectList->getConditionBuilder()->add(
'faq_questions.answer LIKE ?',
['%' . WCF::getDB()->escapeLikeValue($this->answer) . '%']
);
}
return new FaqQuestionGridView();
}

#[Override]
Expand All @@ -100,10 +44,6 @@ public function assignVariables()
parent::assignVariables();

WCF::getTPL()->assign([
'categoryID' => $this->categoryID,
'question' => $this->question,
'answer' => $this->answer,
'categoryNodeList' => (new CategoryNodeTree('dev.tkirch.wsc.faq.category'))->getIterator(),
'showFaqAddDialog' => $this->showFaqAddDialog,
]);
}
Expand Down
10 changes: 10 additions & 0 deletions files/lib/bootstrap/dev.tkirch.wsc.faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use wcf\event\acp\menu\item\ItemCollecting;
use wcf\event\endpoint\ControllerCollecting;
use wcf\event\worker\RebuildWorkerCollecting;
use wcf\system\endpoint\controller\hanashi\questions\ChangeShowOrder;
use wcf\system\endpoint\controller\hanashi\questions\DeleteQuestion;
use wcf\system\endpoint\controller\hanashi\questions\DisableQuestion;
use wcf\system\endpoint\controller\hanashi\questions\EnableQuestion;
use wcf\system\endpoint\controller\hanashi\questions\GetShowOrder;
use wcf\system\endpoint\controller\hanashi\questions\search\GetSearch;
use wcf\system\endpoint\controller\hanashi\questions\search\RenderSearch;
use wcf\system\event\EventHandler;
Expand Down Expand Up @@ -83,6 +88,11 @@ static function (RebuildWorkerCollecting $event) {
EventHandler::getInstance()->register(
ControllerCollecting::class,
static function (ControllerCollecting $event) {
$event->register(new DeleteQuestion());
$event->register(new DisableQuestion());
$event->register(new EnableQuestion());
$event->register(new GetShowOrder());
$event->register(new ChangeShowOrder());
$event->register(new RenderSearch());
$event->register(new GetSearch());
}
Expand Down
26 changes: 13 additions & 13 deletions files/lib/data/faq/QuestionEditor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public function updateShowOrder(int $showOrder): int

//check showOrder
if ($showOrder < $this->showOrder) {
$sql = "UPDATE " . static::getDatabaseTableName() . "
SET showOrder = showOrder + 1
WHERE showOrder >= ?
AND showOrder < ?";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "UPDATE wcf1_faq_questions
SET showOrder = showOrder + 1
WHERE showOrder >= ?
AND showOrder < ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$showOrder,
$this->showOrder,
Expand All @@ -56,11 +56,11 @@ public function updateShowOrder(int $showOrder): int
}

//update databse
$sql = "UPDATE " . static::getDatabaseTableName() . "
SET showOrder = showOrder - 1
WHERE showOrder <= ?
AND showOrder > ?";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "UPDATE wcf1_faq_questions
SET showOrder = showOrder - 1
WHERE showOrder <= ?
AND showOrder > ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$showOrder,
$this->showOrder,
Expand All @@ -76,9 +76,9 @@ public function updateShowOrder(int $showOrder): int
*/
public static function getShowOrder(): int
{
$sql = "SELECT MAX(showOrder) AS showOrder
FROM " . static::getDatabaseTableName();
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "SELECT MAX(showOrder) AS showOrder
FROM wcf1_faq_questions";
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
$row = $statement->fetchArray();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace wcf\event\interaction\admin;

use wcf\event\IPsr14Event;
use wcf\system\interaction\admin\FaqQuestionsInteractions;

final class FaqQuestionsInteractionCollecting implements IPsr14Event
{
public function __construct(public readonly FaqQuestionsInteractions $provider)
{
}
}
2 changes: 1 addition & 1 deletion files/lib/page/FaqQuestionListPage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function readParameters()
EOT
);

$this->category = FaqCategory::getCategory($queryParameters['id']);
$this->category = FaqCategory::getCategory((int)$queryParameters['id']);
} catch (MappingError) {
throw new IllegalLinkException();
}
Expand Down
2 changes: 1 addition & 1 deletion files/lib/system/bbcode/FaqBBCode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getParsedTag(array $openingTag, $content, array $closingTag, BBC
$collapse = true;
}

return WCF::getTPL()->fetch('faqBBCode', 'wcf', [
return WCF::getTPL()->render('wcf', 'faqBBCode', [
'question' => $question,
'collapseQuestion' => $collapse,
], true);
Expand Down
Loading