-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuestionEditor.class.php
More file actions
87 lines (76 loc) · 2.36 KB
/
QuestionEditor.class.php
File metadata and controls
87 lines (76 loc) · 2.36 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
<?php
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 implements IEditableCachedObject
{
/**
* @inheritDoc
*/
protected static $baseClass = Question::class;
#[Override]
public static function resetCache()
{
FaqQuestionListCacheBuilder::getInstance()->reset();
}
/**
* Returns the new show order for a object
*/
public function updateShowOrder(int $showOrder): int
{
if ($showOrder === null) {
$showOrder = \PHP_INT_MAX;
}
//check showOrder
if ($showOrder < $this->showOrder) {
$sql = "UPDATE wcf1_faq_questions
SET showOrder = showOrder + 1
WHERE showOrder >= ?
AND showOrder < ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$showOrder,
$this->showOrder,
]);
} elseif ($showOrder > $this->showOrder) {
//get max show order
$maxShowOrder = self::getShowOrder() - 1;
//get show order
if ($showOrder > $maxShowOrder) {
$showOrder = $maxShowOrder;
}
//update databse
$sql = "UPDATE wcf1_faq_questions
SET showOrder = showOrder - 1
WHERE showOrder <= ?
AND showOrder > ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$showOrder,
$this->showOrder,
]);
}
//return show order
return $showOrder;
}
/**
* Returns the show order for a new object
*/
public static function getShowOrder(): int
{
$sql = "SELECT MAX(showOrder) AS showOrder
FROM wcf1_faq_questions";
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
$row = $statement->fetchArray();
return !empty($row) ? ($row['showOrder'] + 1) : 1;
}
}