-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuestion.class.php
More file actions
155 lines (128 loc) · 4.04 KB
/
Question.class.php
File metadata and controls
155 lines (128 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace wcf\data\faq;
use Override;
use wcf\data\attachment\GroupedAttachmentList;
use wcf\data\category\Category;
use wcf\data\DatabaseObject;
use wcf\data\faq\category\FaqCategory;
use wcf\data\search\ISearchResultObject;
use wcf\data\user\User;
use wcf\page\FaqQuestionPage;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\system\request\IRouteController;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
/**
* @property-read int $questionID unique id of the question
* @property-read string $question content of the question
* @property-read string $answer content of the answer
* @property-read int $categoryID id of the category the question belongs to
* @property-read int $showOrder sort order of the question
* @property-read int $isDisabled is `1` if the question is disabled, otherwise `0`
* @property-read int $hasEmbeddedObjects is `1` if the question has embedded objects, otherwise `0`
* @property-read int $isMultilingual
*/
final class Question extends DatabaseObject implements IRouteController, ISearchResultObject
{
protected FaqCategory $category;
/**
* @inheritDoc
*/
protected static $databaseTableName = 'faq_questions';
/**
* @inheritDoc
*/
protected static $databaseTableIndexName = 'questionID';
private GroupedAttachmentList $attachmentList;
#[Override]
public function getTitle(): string
{
return WCF::getLanguage()->get($this->question);
}
public function getAnswer(): string
{
return WCF::getLanguage()->get($this->answer);
}
public function getFormattedOutput(): string
{
$processor = new HtmlOutputProcessor();
$processor->process($this->getAnswer(), 'dev.tkirch.wsc.faq.question', $this->questionID);
return $processor->getHtml();
}
public function getPlainOutput(): string
{
$processor = new HtmlOutputProcessor();
$processor->setOutputType('text/plain');
$processor->process($this->getAnswer(), 'dev.tkirch.wsc.faq.question', $this->questionID);
return $processor->getHtml();
}
public function getCategory(): FaqCategory
{
if (!isset($this->category)) {
$category = new Category($this->categoryID);
$this->category = new FaqCategory($category);
}
return $this->category;
}
public function isAccessible(?User $user = null): bool
{
if ($this->isDisabled && !WCF::getSession()->getPermission('admin.faq.canViewQuestion')) {
return false;
}
if ($this->getCategory()->categoryID) {
return $this->getCategory()->isAccessible($user);
}
return WCF::getSession()->getPermission('user.faq.canViewFAQ');
}
public function getAttachments(): GroupedAttachmentList
{
if (empty($this->attachmentList)) {
$this->attachmentList = new GroupedAttachmentList('dev.tkirch.wsc.faq.question');
$this->attachmentList->getConditionBuilder()->add('attachment.objectID = ?', [$this->questionID]);
$this->attachmentList->readObjects();
}
return $this->attachmentList;
}
#[Override]
public function getUserProfile()
{
return null;
}
#[Override]
public function getSubject()
{
return $this->getTitle();
}
#[Override]
public function getTime()
{
return 0;
}
#[Override]
public function getLink($query = '')
{
return LinkHandler::getInstance()->getControllerLink(FaqQuestionPage::class, [
'object' => $this,
]);
}
#[Override]
public function getObjectTypeName()
{
return 'dev.tkirch.wsc.faq.question';
}
#[Override]
public function getFormattedMessage()
{
return $this->getFormattedOutput();
}
#[Override]
public function getContainerTitle()
{
return '';
}
#[Override]
public function getContainerLink()
{
return '';
}
}