aboutsummaryrefslogtreecommitdiff
path: root/lib/modules
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2025-07-04 06:13:27 +0000
committerRasmus Fuhse <fuhse@data-quest.de>2025-07-04 06:13:27 +0000
commitd25a23a626b43baab9714c8a4a68a20144cb3f00 (patch)
treeea948244609f587a3fb9f1e5ab89fd996b30d73c /lib/modules
parentaacbfe703e9e45fd9e8c11a60c3f1ad77593d981 (diff)
Resolve "Forum 3"
Closes #5146 Merge request studip/studip!3845
Diffstat (limited to 'lib/modules')
-rw-r--r--lib/modules/CoreForum.php211
1 files changed, 60 insertions, 151 deletions
diff --git a/lib/modules/CoreForum.php b/lib/modules/CoreForum.php
index c9a23d1..0c2b5e5 100644
--- a/lib/modules/CoreForum.php
+++ b/lib/modules/CoreForum.php
@@ -1,189 +1,92 @@
<?php
-/*
- * Forum.php - Forum
+/**
+ * Forum: Discussion of specific topics within courses
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * @author Till Glöggler <till.gloeggler@elan-ev.de>
- * @copyright 2011 ELAN e.V. <http://www.elan-ev.de>
- * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
- * @category Stud.IP
+ * @author Murtaza Sultani <sultani@data-quest.de>
+ * @author Rasmus Fuhse <fuhse@data-quest.de>
+ * @license GPL2 or any later version
+ * @since Stud.IP 6.1
*/
-// Notifications
-NotificationCenter::addObserver('CoreForum', 'overviewDidClear', 'OverviewDidClear');
-NotificationCenter::addObserver('CoreForum', 'removeAbosForUserAndCourse', 'UserDidLeaveCourse');
-
-NotificationCenter::addObserver('ForumActivity', 'newEntry', 'ForumAfterInsert');
-NotificationCenter::addObserver('ForumActivity', 'updateEntry', 'ForumAfterUpdate');
-NotificationCenter::addObserver('ForumActivity', 'deleteEntry', 'ForumBeforeDelete');
+use Forum\ForumPosting;
-NotificationCenter::addObserver('ForumIssue', 'unlinkIssue', 'ForumBeforeDelete');
-
-class CoreForum extends CorePlugin implements ForumModule
+class CoreForum extends CorePlugin implements StudipModule
{
- /* interface method */
public function getTabNavigation($course_id)
{
- $navigation = new Navigation(_('Forum'), 'dispatch.php/course/forum/index');
- $navigation->setImage(Icon::create('forum', 'info_alt'));
+ $navigation = new Navigation(_('Forum'), 'dispatch.php/course/forum/topics');
- // add main third-level navigation-item
- $navigation->addSubNavigation('index', new Navigation(_('Übersicht'), 'dispatch.php/course/forum/index'));
+ $navigation->setImage(Icon::create('forum', 'info_alt'));
- if (ForumPerm::has('fav_entry', $course_id)) {
- $navigation->addSubNavigation('newest', new Navigation(_("Neue Beiträge"), 'dispatch.php/course/forum/index/newest'));
- $navigation->addSubNavigation('latest', new Navigation(_("Letzte Beiträge"), 'dispatch.php/course/forum/index/latest'));
- $navigation->addSubNavigation('favorites', new Navigation(_('Gemerkte Beiträge'), 'dispatch.php/course/forum/index/favorites'));
+ $navigation->addSubNavigation(
+ 'topics',
+ new Navigation(_('Themenübersicht'), 'dispatch.php/course/forum/topics')
+ );
- // mass-administrate the forum
- if (ForumPerm::has('admin', $course_id)) {
- $navigation->addSubNavigation('admin', new Navigation(_('Administration'), 'dispatch.php/course/forum/admin'));
- }
+ if (!CourseConfig::get($course_id)->FORUM_HIDE_CATEGORIES_NAVIGATION) {
+ $navigation->addSubNavigation(
+ 'categories',
+ new Navigation(_('Kategorien'), 'dispatch.php/course/forum/categories')
+ );
}
- return ['forum2' => $navigation];
+ $navigation->addSubNavigation(
+ 'subscriptions',
+ new Navigation(_('Abonnierte Diskussionen'), 'dispatch.php/course/forum/subscriptions')
+ );
+
+ return ['forum' => $navigation];
}
- /* interface method */
- public function getIconNavigation($course_id, $last_visit, $user_id = null)
+ public function getIconNavigation($course_id, $last_visit, $user_id)
{
+ $recent_posts_count = 0;
+ $navigation_title = _('Forum');
+
if ($GLOBALS['perm']->have_studip_perm('user', $course_id)) {
- $num_entries = ForumVisit::getCount($course_id, ForumVisit::getVisit($course_id));
- $text = ForumHelpers::getVisitText($num_entries, $course_id);
- } else {
- $num_entries = 0;
- $text = 'Forum';
+ $recent_posts = ForumPosting::getRecentPosts($course_id, $last_visit);
+ $recent_posts_count = array_sum(array_column($recent_posts, 'posts'));
+
+ if ($recent_posts_count > 0) {
+ $navigation_title = sprintf(_('%s neue Beiträge seit Ihrem letzten Besuch.'), $recent_posts_count);
+ } else {
+ $navigation_title = _('Keine neuen Beiträge seit Ihrem letzten Besuch.');
+ }
}
- $navigation = new Navigation('forum', 'dispatch.php/course/forum/index/enter_seminar');
- $navigation->setBadgeNumber($num_entries);
- $navigation->setLinkAttributes(['title' => $text]);
+ $navigation = new Navigation(_("Forum"));
+ $navigation->setBadgeNumber($recent_posts_count);
+
+ $navigation->setLinkAttributes(['title' => $navigation_title]);
- if ($num_entries > 0) {
+ if ($recent_posts_count > 0) {
$navigation->setImage(Icon::create('forum', Icon::ROLE_ATTENTION));
+ $navigation->setURL('dispatch.php/course/forum/recent', ['last_visit' => $last_visit]);
} else {
$navigation->setImage(Icon::create('forum'));
+ $navigation->setURL('dispatch.php/course/forum/topics');
}
return $navigation;
}
- /**
- * This method is called, whenever an user clicked to clear the visit timestamps
- * and set everything as visited
- *
- * @param object $notification
- * @param string $user_id
- */
- public static function overviewDidClear($notification, $user_id)
- {
- $query = "REPLACE INTO `forum_visits`
- SELECT `user_id`, `Seminar_id`, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
- FROM `seminar_user`
- WHERE `user_id` = ?";
- DBManager::get()->execute($query, [$user_id]);
- }
-
- /**
- * This method is called whenever a user is removed from a course and thus
- * the forum abos will be removed.
- *
- * @param object $notification
- * @param string $course_id
- * @param string $user_id
- */
- public static function removeAbosForUserAndCourse($notification, $course_id, $user_id)
- {
- ForumAbo::removeForCourseAndUser($course_id, $user_id);
- }
-
public function getInfoTemplate($course_id)
{
- return null;
- }
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* * IMPLEMENTATION OF METHODS FROM FORUMMODULE-INTERFACE * */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- public function getLinkToThread($issue_id)
- {
- if ($topic_id = ForumIssue::getThreadIdForIssue($issue_id)) {
- return URLHelper::getLink('dispatch.php/course/forum/index/index/' . $topic_id);
- }
-
- return false;
- }
-
- public function setThreadForIssue($issue_id, $title, $content)
- {
- ForumIssue::setThreadForIssue(Context::getId(), $issue_id, $title, $content);
- }
-
- public function getNumberOfPostingsForUser($user_id, $seminar_id = null)
- {
- return ForumEntry::countUserEntries($user_id, $seminar_id);
- }
-
- public function getNumberOfPostingsForIssue($issue_id)
- {
- $topic_id = ForumIssue::getThreadIdForIssue($issue_id);
-
- return $topic_id ? ForumEntry::countEntries($topic_id) : 0;
- }
-
- public function getNumberOfPostingsForSeminar($seminar_id)
- {
- return floor(ForumEntry::countEntries($seminar_id));
- }
-
- public function getNumberOfPostings()
- {
- return ForumEntry::countAllEntries();
- }
-
- public function getEntryTableInfo()
- {
- return [
- 'table' => 'forum_entries',
- 'content' => 'content',
- 'chdate' => 'chdate',
- 'seminar_id' => 'seminar_id',
- 'user_id' => 'user_id'
- ];
+ // TODO: Implement getInfoTemplate() method.
}
- public function getTopTenSeminars()
+ public static function isAdmin($course_id): bool
{
- return ForumEntry::getTopTenSeminars();
+ return $GLOBALS['perm']->have_perm('root') || $GLOBALS['perm']->have_studip_perm('dozent', $course_id);
}
- public function migrateUser($user_from, $user_to)
+ public static function isModerator($course_id): bool
{
- ForumEntry::migrateUser($user_from, $user_to);
+ return self::isAdmin($course_id) ||
+ CourseConfig::get($course_id)->FORUM_MODERATION_PERMISSION === $GLOBALS['perm']->get_studip_perm($course_id) ||
+ CourseConfig::get($course_id)->FORUM_MODERATION_PERMISSION === 'all';
}
- public function deleteContents($seminar_id)
- {
- ForumEntry::delete($seminar_id);
- }
-
- public function getDump($seminar_id)
- {
- return ForumEntry::getDump($seminar_id);
- }
-
- public static function getDescription()
- {
- return _('Textbasierte und zeit- und ortsunabhängige '.
- 'Diskursmöglichkeit. Lehrende können parallel zu '.
- 'Veranstaltungsthemen Fragen stellen, die von den Studierenden '.
- 'per Meinungsaustausch besprochen werden.');
- }
/**
* {@inheritdoc}
@@ -201,11 +104,17 @@ class CoreForum extends CorePlugin implements ForumModule
'screenshots' => [
'path' => 'assets/images/plus/screenshots/Forum',
'pictures' => [
- 0 => ['source' => 'Uebersicht.jpg', 'title' => _('Übersicht')],
- 1 => ['source' => 'Beitrag.jpg', 'title' => _('Beitrag')],
- 2 => ['source' => 'Beitrag_verfassen.jpg', 'title' => _('Beitrag verfassen')],
+ ['source' => 'Lehrendensicht_-_Kategorien_mit_Bereichen_und_Beitraegen.jpg'],
+ ['source' => 'Studentische_Sicht_-_Kategorien_mit_Bereichen_und_Beitraegen.jpg'],
+ ['source' => 'Einen_Forumsbeitrag_erstellen.jpg'],
]
]
];
}
+
+ public static function deleteCourseContents($course_id)
+ {
+ \Forum\ForumCategory::deleteBySQL("range_id = ?", [$course_id]);
+ \Forum\ForumTopic::deleteBySQL("range_id = ?", [$course_id]);
+ }
}