Added global announcement post type.
This commit is contained in:
parent
b3d04b138a
commit
0d6b1be094
3 changed files with 59 additions and 19 deletions
|
@ -63,6 +63,11 @@ define('MSZ_FORUM_ROOT_DATA', [ // should be compatible with the data fetched in
|
|||
'forum_colour' => null,
|
||||
]);
|
||||
|
||||
function forum_is_valid_type(int $type): bool
|
||||
{
|
||||
return in_array($type, MSZ_FORUM_TYPES, true);
|
||||
}
|
||||
|
||||
function forum_may_have_children(int $forumType): bool
|
||||
{
|
||||
return in_array($forumType, MSZ_FORUM_MAY_HAVE_CHILDREN);
|
||||
|
|
|
@ -2,40 +2,70 @@
|
|||
define('MSZ_TOPIC_TYPE_DISCUSSION', 0);
|
||||
define('MSZ_TOPIC_TYPE_STICKY', 1);
|
||||
define('MSZ_TOPIC_TYPE_ANNOUNCEMENT', 2);
|
||||
define('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT', 3);
|
||||
define('MSZ_TOPIC_TYPES', [
|
||||
MSZ_TOPIC_TYPE_DISCUSSION,
|
||||
MSZ_TOPIC_TYPE_STICKY,
|
||||
MSZ_TOPIC_TYPE_ANNOUNCEMENT,
|
||||
MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT,
|
||||
]);
|
||||
|
||||
function forum_topic_create(int $forumId, int $userId, string $title): int
|
||||
define('MSZ_TOPIC_TYPE_ORDER', [ // in which order to display topics, only add types here that should appear above others
|
||||
MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT,
|
||||
MSZ_TOPIC_TYPE_ANNOUNCEMENT,
|
||||
MSZ_TOPIC_TYPE_STICKY,
|
||||
]);
|
||||
|
||||
function forum_topic_is_valid_type(int $type): bool
|
||||
{
|
||||
return in_array($type, MSZ_TOPIC_TYPES, true);
|
||||
}
|
||||
|
||||
function forum_topic_create(int $forumId, int $userId, string $title, int $type = MSZ_TOPIC_TYPE_DISCUSSION): int
|
||||
{
|
||||
if (empty($title) || !forum_topic_is_valid_type($type)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$createTopic = db_prepare('
|
||||
INSERT INTO `msz_forum_topics`
|
||||
(`forum_id`, `user_id`, `topic_title`)
|
||||
(`forum_id`, `user_id`, `topic_title`, `topic_type`)
|
||||
VALUES
|
||||
(:forum_id, :user_id, :topic_title)
|
||||
(:forum_id, :user_id, :topic_title, :topic_type)
|
||||
');
|
||||
$createTopic->bindValue('forum_id', $forumId);
|
||||
$createTopic->bindValue('user_id', $userId);
|
||||
$createTopic->bindValue('topic_title', $title);
|
||||
$createTopic->bindValue('topic_type', $type);
|
||||
|
||||
return $createTopic->execute() ? (int)db_last_insert_id() : 0;
|
||||
}
|
||||
|
||||
function forum_topic_update(int $topicId, string $title): bool
|
||||
function forum_topic_update(int $topicId, ?string $title, ?int $type = null): bool
|
||||
{
|
||||
if ($topicId < 1 || empty($title)) {
|
||||
if ($topicId < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure it's null and not some other kinda empty
|
||||
if (empty($title)) {
|
||||
$title = null;
|
||||
}
|
||||
|
||||
if ($type !== null && !forum_topic_is_valid_type($type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$updateTopic = db_prepare('
|
||||
UPDATE `msz_forum_topics`
|
||||
SET `topic_title` = :topic_title
|
||||
SET `topic_title` = COALESCE(:topic_title, `topic_title`)
|
||||
`topic_type` = COALESCE(:topic_type, `topic_type`)
|
||||
WHERE `topic_id` = :topic_id
|
||||
');
|
||||
$updateTopic->bindValue('topic_id', $topicId);
|
||||
$updateTopic->bindValue('topic_title', $title);
|
||||
$updateTopic->bindValue('topic_type', $type);
|
||||
|
||||
return $updateTopic->execute();
|
||||
}
|
||||
|
||||
|
@ -152,13 +182,18 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
|||
ON lu.`user_id` = lp.`user_id`
|
||||
LEFT JOIN `msz_roles` as lr
|
||||
ON lr.`role_id` = lu.`display_role`
|
||||
WHERE t.`forum_id` = :forum_id
|
||||
WHERE (
|
||||
t.`forum_id` = :forum_id
|
||||
OR t.`topic_type` = %3$d
|
||||
)
|
||||
%1$s
|
||||
ORDER BY t.`topic_type` DESC, t.`topic_bumped` DESC
|
||||
ORDER BY FIELD(t.`topic_type`, %4$s) DESC, t.`topic_bumped` DESC
|
||||
%2$s
|
||||
',
|
||||
$showDeleted ? '' : 'AND t.`topic_deleted` IS NULL',
|
||||
$hasPagination ? 'LIMIT :offset, :take' : ''
|
||||
$hasPagination ? 'LIMIT :offset, :take' : '',
|
||||
MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT,
|
||||
implode(',', array_reverse(MSZ_TOPIC_TYPE_ORDER))
|
||||
));
|
||||
$getTopics->bindValue('forum_id', $forumId);
|
||||
$getTopics->bindValue('user_id', $userId);
|
||||
|
|
|
@ -115,10 +115,10 @@
|
|||
{% if forum_type is null %}
|
||||
{% if forum.forum_archived is defined and forum.forum_archived %}
|
||||
{% set forum_type = 'fas fa-archive' %}
|
||||
{% elseif forum.forum_type is defined and forum.forum_type != 0 %}
|
||||
{% if forum.forum_type == 2 %}
|
||||
{% elseif forum.forum_type is defined and forum.forum_type != constant('MSZ_FORUM_TYPE_DISCUSSION') %}
|
||||
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %}
|
||||
{% set forum_type = 'fas fa-link' %}
|
||||
{% elseif forum.forum_type == 1 %}
|
||||
{% elseif forum.forum_type == constant('MSZ_FORUM_TYPE_CATEGORY') %}
|
||||
{% set forum_type = 'fas fa-folder' %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
|
@ -155,22 +155,22 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if forum.forum_type == 2 %}
|
||||
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_LINK') %}
|
||||
{% if forum.forum_link_clicks is not null %}
|
||||
<div class="forum__category__stats">
|
||||
<div class="forum__category__stat" title="Clicks">{{ forum.forum_link_clicks|number_format }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% elseif forum.forum_type != 1 %}
|
||||
{% elseif forum.forum_type != constant('MSZ_FORUM_TYPE_CATEGORY') %}
|
||||
<div class="forum__category__stats">
|
||||
<div class="forum__category__stat" title="Topics">{{ forum.forum_topic_count|number_format }}</div>
|
||||
<div class="forum__category__stat" title="Posts">{{ forum.forum_post_count|number_format }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if forum.forum_type == 0 or forum.forum_link_clicks is not null %}
|
||||
{% if forum.forum_type == constant('MSZ_FORUM_TYPE_DISCUSSION') or forum.forum_link_clicks is not null %}
|
||||
<div class="forum__category__activity{% if forum.forum_link_clicks is not null %} forum__category__activity--empty{% endif %}">
|
||||
{% if forum.forum_type != 2 %}
|
||||
{% if forum.forum_type != constant('MSZ_FORUM_TYPE_LINK') %}
|
||||
{% if forum.recent_topic_id is null %}
|
||||
<div class="forum__category__activity__none">
|
||||
There are no posts in this forum yet.
|
||||
|
@ -257,10 +257,10 @@
|
|||
{% if topic_type is null %}
|
||||
{% if topic.topic_deleted is defined and topic.topic_deleted is not null %}
|
||||
{% set topic_type = 'fas fa-trash-alt' %}
|
||||
{% elseif topic.topic_type is defined and topic.topic_type != 0 %}
|
||||
{% if topic.topic_type == 2 %}
|
||||
{% elseif topic.topic_type is defined and topic.topic_type != constant('MSZ_TOPIC_TYPE_DISCUSSION') %}
|
||||
{% if topic.topic_type == constant('MSZ_TOPIC_TYPE_ANNOUNCEMENT') or topic.topic_type == constant('MSZ_TOPIC_TYPE_GLOBAL_ANNOUNCEMENT') %}
|
||||
{% set topic_type = 'fas fa-bullhorn' %}
|
||||
{% elseif topic.topic_type == 1 %}
|
||||
{% elseif topic.topic_type == constant('MSZ_TOPIC_TYPE_STICKY') %}
|
||||
{% set topic_type = 'fas fa-thumbtack' %}
|
||||
{% endif %}
|
||||
{% elseif topic.topic_locked is defined and topic.topic_locked is not null %}
|
||||
|
|
Loading…
Add table
Reference in a new issue