mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-57487 mod_forum: final deprecation xxx_print_overview
Apart from deprecating forum_print_overview, the following method has been also deprecated because it's not used anymore: - forum_filter_user_groups_discussions
This commit is contained in:
parent
99a80e133a
commit
b18015c687
2 changed files with 6 additions and 452 deletions
|
@ -540,44 +540,10 @@ function forum_user_complete($course, $user, $mod, $forum) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Filters the forum discussions according to groups membership and config.
|
||||
*
|
||||
* @deprecated since 3.3
|
||||
* @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57487.
|
||||
* @since Moodle 2.8, 2.7.1, 2.6.4
|
||||
* @param array $discussions Discussions with new posts array
|
||||
* @return array Forums with the number of new posts
|
||||
* @deprecated since Moodle 3.3, when the block_course_overview block was removed.
|
||||
*/
|
||||
function forum_filter_user_groups_discussions($discussions) {
|
||||
|
||||
debugging('The function forum_filter_user_groups_discussions() is now deprecated.', DEBUG_DEVELOPER);
|
||||
|
||||
// Group the remaining discussions posts by their forumid.
|
||||
$filteredforums = array();
|
||||
|
||||
// Discard not visible groups.
|
||||
foreach ($discussions as $discussion) {
|
||||
|
||||
// Course data is already cached.
|
||||
$instances = get_fast_modinfo($discussion->course)->get_instances();
|
||||
$forum = $instances['forum'][$discussion->forum];
|
||||
|
||||
// Continue if the user should not see this discussion.
|
||||
if (!forum_is_user_group_discussion($forum, $discussion->groupid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grouping results by forum.
|
||||
if (empty($filteredforums[$forum->instance])) {
|
||||
$filteredforums[$forum->instance] = new stdClass();
|
||||
$filteredforums[$forum->instance]->id = $forum->id;
|
||||
$filteredforums[$forum->instance]->count = 0;
|
||||
}
|
||||
$filteredforums[$forum->instance]->count += $discussion->count;
|
||||
|
||||
}
|
||||
|
||||
return $filteredforums;
|
||||
function forum_filter_user_groups_discussions() {
|
||||
throw new coding_exception('forum_filter_user_groups_discussions() can not be used any more and is obsolete.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -607,155 +573,10 @@ function forum_is_user_group_discussion(cm_info $cm, $discussiongroupid) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 3.3
|
||||
* @todo The final deprecation of this function will take place in Moodle 3.7 - see MDL-57487.
|
||||
* @global object
|
||||
* @global object
|
||||
* @global object
|
||||
* @param array $courses
|
||||
* @param array $htmlarray
|
||||
* @deprecated since Moodle 3.3, when the block_course_overview block was removed.
|
||||
*/
|
||||
function forum_print_overview($courses,&$htmlarray) {
|
||||
global $USER, $CFG, $DB, $SESSION;
|
||||
|
||||
debugging('The function forum_print_overview() is now deprecated.', DEBUG_DEVELOPER);
|
||||
|
||||
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!$forums = get_all_instances_in_courses('forum',$courses)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Courses to search for new posts
|
||||
$coursessqls = array();
|
||||
$params = array();
|
||||
foreach ($courses as $course) {
|
||||
|
||||
// If the user has never entered into the course all posts are pending
|
||||
if ($course->lastaccess == 0) {
|
||||
$coursessqls[] = '(d.course = ?)';
|
||||
$params[] = $course->id;
|
||||
|
||||
// Only posts created after the course last access
|
||||
} else {
|
||||
$coursessqls[] = '(d.course = ? AND p.created > ?)';
|
||||
$params[] = $course->id;
|
||||
$params[] = $course->lastaccess;
|
||||
}
|
||||
}
|
||||
$params[] = $USER->id;
|
||||
$coursessql = implode(' OR ', $coursessqls);
|
||||
|
||||
$sql = "SELECT d.id, d.forum, d.course, d.groupid, COUNT(*) as count "
|
||||
.'FROM {forum_discussions} d '
|
||||
.'JOIN {forum_posts} p ON p.discussion = d.id '
|
||||
."WHERE ($coursessql) "
|
||||
.'AND p.deleted <> 1 '
|
||||
.'AND p.userid != ? '
|
||||
.'AND (d.timestart <= ? AND (d.timeend = 0 OR d.timeend > ?)) '
|
||||
.'GROUP BY d.id, d.forum, d.course, d.groupid '
|
||||
.'ORDER BY d.course, d.forum';
|
||||
$params[] = time();
|
||||
$params[] = time();
|
||||
|
||||
// Avoid warnings.
|
||||
if (!$discussions = $DB->get_records_sql($sql, $params)) {
|
||||
$discussions = array();
|
||||
}
|
||||
|
||||
$forumsnewposts = forum_filter_user_groups_discussions($discussions);
|
||||
|
||||
// also get all forum tracking stuff ONCE.
|
||||
$trackingforums = array();
|
||||
foreach ($forums as $forum) {
|
||||
if (forum_tp_can_track_forums($forum)) {
|
||||
$trackingforums[$forum->id] = $forum;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($trackingforums) > 0) {
|
||||
$cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0;
|
||||
$sql = 'SELECT d.forum,d.course,COUNT(p.id) AS count '.
|
||||
' FROM {forum_posts} p '.
|
||||
' JOIN {forum_discussions} d ON p.discussion = d.id '.
|
||||
' LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = ? WHERE p.deleted <> 1 AND (';
|
||||
$params = array($USER->id);
|
||||
|
||||
foreach ($trackingforums as $track) {
|
||||
$sql .= '(d.forum = ? AND (d.groupid = -1 OR d.groupid = 0 OR d.groupid = ?)) OR ';
|
||||
$params[] = $track->id;
|
||||
if (isset($SESSION->currentgroup[$track->course])) {
|
||||
$groupid = $SESSION->currentgroup[$track->course];
|
||||
} else {
|
||||
// get first groupid
|
||||
$groupids = groups_get_all_groups($track->course, $USER->id);
|
||||
if ($groupids) {
|
||||
reset($groupids);
|
||||
$groupid = key($groupids);
|
||||
$SESSION->currentgroup[$track->course] = $groupid;
|
||||
} else {
|
||||
$groupid = 0;
|
||||
}
|
||||
unset($groupids);
|
||||
}
|
||||
$params[] = $groupid;
|
||||
}
|
||||
$sql = substr($sql,0,-3); // take off the last OR
|
||||
$sql .= ') AND p.modified >= ? AND r.id is NULL ';
|
||||
$sql .= 'AND (d.timestart < ? AND (d.timeend = 0 OR d.timeend > ?)) ';
|
||||
$sql .= 'GROUP BY d.forum,d.course';
|
||||
$params[] = $cutoffdate;
|
||||
$params[] = time();
|
||||
$params[] = time();
|
||||
|
||||
if (!$unread = $DB->get_records_sql($sql, $params)) {
|
||||
$unread = array();
|
||||
}
|
||||
} else {
|
||||
$unread = array();
|
||||
}
|
||||
|
||||
if (empty($unread) and empty($forumsnewposts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$strforum = get_string('modulename','forum');
|
||||
|
||||
foreach ($forums as $forum) {
|
||||
$str = '';
|
||||
$count = 0;
|
||||
$thisunread = 0;
|
||||
$showunread = false;
|
||||
// either we have something from logs, or trackposts, or nothing.
|
||||
if (array_key_exists($forum->id, $forumsnewposts) && !empty($forumsnewposts[$forum->id])) {
|
||||
$count = $forumsnewposts[$forum->id]->count;
|
||||
}
|
||||
if (array_key_exists($forum->id,$unread)) {
|
||||
$thisunread = $unread[$forum->id]->count;
|
||||
$showunread = true;
|
||||
}
|
||||
if ($count > 0 || $thisunread > 0) {
|
||||
$str .= '<div class="overview forum"><div class="name">'.$strforum.': <a title="'.$strforum.'" href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
|
||||
$forum->name.'</a></div>';
|
||||
$str .= '<div class="info"><span class="postsincelogin">';
|
||||
$str .= get_string('overviewnumpostssince', 'forum', $count)."</span>";
|
||||
if (!empty($showunread)) {
|
||||
$str .= '<div class="unreadposts">'.get_string('overviewnumunread', 'forum', $thisunread).'</div>';
|
||||
}
|
||||
$str .= '</div></div>';
|
||||
}
|
||||
if (!empty($str)) {
|
||||
if (!array_key_exists($forum->course,$htmlarray)) {
|
||||
$htmlarray[$forum->course] = array();
|
||||
}
|
||||
if (!array_key_exists('forum',$htmlarray[$forum->course])) {
|
||||
$htmlarray[$forum->course]['forum'] = ''; // initialize, avoid warnings
|
||||
}
|
||||
$htmlarray[$forum->course]['forum'] .= $str;
|
||||
}
|
||||
}
|
||||
function forum_print_overview() {
|
||||
throw new coding_exception('forum_print_overview() can not be used any more and is obsolete.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2524,273 +2524,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
|||
$this->assertArrayHasKey('forumdiscussions', $nodes->getValue($tree));
|
||||
}
|
||||
|
||||
public function test_print_overview() {
|
||||
$this->resetAfterTest();
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$course2 = self::getDataGenerator()->create_course();
|
||||
|
||||
// Create an author user.
|
||||
$author = self::getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
|
||||
$this->getDataGenerator()->enrol_user($author->id, $course2->id);
|
||||
|
||||
// Create a viewer user.
|
||||
$viewer = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
|
||||
$this->getDataGenerator()->enrol_user($viewer->id, $course1->id);
|
||||
$this->getDataGenerator()->enrol_user($viewer->id, $course2->id);
|
||||
|
||||
// Create two forums - one in each course.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', (object) array('course' => $course1->id));
|
||||
$forum2 = self::getDataGenerator()->create_module('forum', (object) array('course' => $course2->id));
|
||||
|
||||
// A standard post in the forum.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $author->id;
|
||||
$record->forum = $forum1->id;
|
||||
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
$this->setUser($viewer->id);
|
||||
$courses = array(
|
||||
$course1->id => clone $course1,
|
||||
$course2->id => clone $course2,
|
||||
);
|
||||
|
||||
foreach ($courses as $courseid => $course) {
|
||||
$courses[$courseid]->lastaccess = 0;
|
||||
}
|
||||
$results = array();
|
||||
forum_print_overview($courses, $results);
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
|
||||
// There should be one entry for course1, and no others.
|
||||
$this->assertCount(1, $results);
|
||||
|
||||
// There should be one entry for a forum in course1.
|
||||
$this->assertCount(1, $results[$course1->id]);
|
||||
$this->assertArrayHasKey('forum', $results[$course1->id]);
|
||||
}
|
||||
|
||||
public function test_print_overview_groups() {
|
||||
$this->resetAfterTest();
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
|
||||
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
|
||||
|
||||
// Create an author user.
|
||||
$author = self::getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
|
||||
|
||||
// Create two viewer users - one in each group.
|
||||
$viewer1 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
|
||||
$this->getDataGenerator()->enrol_user($viewer1->id, $course1->id);
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $viewer1->id, 'groupid' => $group1->id));
|
||||
|
||||
$viewer2 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
|
||||
$this->getDataGenerator()->enrol_user($viewer2->id, $course1->id);
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $viewer2->id, 'groupid' => $group2->id));
|
||||
|
||||
// Create a forum.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', (object) array(
|
||||
'course' => $course1->id,
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
));
|
||||
|
||||
// A post in the forum for group1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $author->id;
|
||||
$record->forum = $forum1->id;
|
||||
$record->groupid = $group1->id;
|
||||
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
$course1->lastaccess = 0;
|
||||
$courses = array($course1->id => $course1);
|
||||
|
||||
// As viewer1 (same group as post).
|
||||
$this->setUser($viewer1->id);
|
||||
$results = array();
|
||||
forum_print_overview($courses, $results);
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
|
||||
// There should be one entry for course1.
|
||||
$this->assertCount(1, $results);
|
||||
|
||||
// There should be one entry for a forum in course1.
|
||||
$this->assertCount(1, $results[$course1->id]);
|
||||
$this->assertArrayHasKey('forum', $results[$course1->id]);
|
||||
|
||||
$this->setUser($viewer2->id);
|
||||
$results = array();
|
||||
forum_print_overview($courses, $results);
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
|
||||
// There should be one entry for course1.
|
||||
$this->assertCount(0, $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider print_overview_timed_provider
|
||||
*/
|
||||
public function test_print_overview_timed($config, $hasresult) {
|
||||
$this->resetAfterTest();
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
|
||||
// Create an author user.
|
||||
$author = self::getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
|
||||
|
||||
// Create a viewer user.
|
||||
$viewer = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
|
||||
$this->getDataGenerator()->enrol_user($viewer->id, $course1->id);
|
||||
|
||||
// Create a forum.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', (object) array('course' => $course1->id));
|
||||
|
||||
// A timed post with a timestart in the past (24 hours ago).
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $author->id;
|
||||
$record->forum = $forum1->id;
|
||||
if (isset($config['timestartmodifier'])) {
|
||||
$record->timestart = time() + $config['timestartmodifier'];
|
||||
}
|
||||
if (isset($config['timeendmodifier'])) {
|
||||
$record->timeend = time() + $config['timeendmodifier'];
|
||||
}
|
||||
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
$course1->lastaccess = 0;
|
||||
$courses = array($course1->id => $course1);
|
||||
|
||||
// As viewer, check the forum_print_overview result.
|
||||
$this->setUser($viewer->id);
|
||||
$results = array();
|
||||
forum_print_overview($courses, $results);
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
|
||||
if ($hasresult) {
|
||||
// There should be one entry for course1.
|
||||
$this->assertCount(1, $results);
|
||||
|
||||
// There should be one entry for a forum in course1.
|
||||
$this->assertCount(1, $results[$course1->id]);
|
||||
$this->assertArrayHasKey('forum', $results[$course1->id]);
|
||||
} else {
|
||||
// There should be no entries for any course.
|
||||
$this->assertCount(0, $results);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider print_overview_timed_provider
|
||||
*/
|
||||
public function test_print_overview_timed_groups($config, $hasresult) {
|
||||
$this->resetAfterTest();
|
||||
$course1 = self::getDataGenerator()->create_course();
|
||||
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
|
||||
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
|
||||
|
||||
// Create an author user.
|
||||
$author = self::getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
|
||||
|
||||
// Create two viewer users - one in each group.
|
||||
$viewer1 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
|
||||
$this->getDataGenerator()->enrol_user($viewer1->id, $course1->id);
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $viewer1->id, 'groupid' => $group1->id));
|
||||
|
||||
$viewer2 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
|
||||
$this->getDataGenerator()->enrol_user($viewer2->id, $course1->id);
|
||||
$this->getDataGenerator()->create_group_member(array('userid' => $viewer2->id, 'groupid' => $group2->id));
|
||||
|
||||
// Create a forum.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', (object) array(
|
||||
'course' => $course1->id,
|
||||
'groupmode' => SEPARATEGROUPS,
|
||||
));
|
||||
|
||||
// A post in the forum for group1.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $author->id;
|
||||
$record->forum = $forum1->id;
|
||||
$record->groupid = $group1->id;
|
||||
if (isset($config['timestartmodifier'])) {
|
||||
$record->timestart = time() + $config['timestartmodifier'];
|
||||
}
|
||||
if (isset($config['timeendmodifier'])) {
|
||||
$record->timeend = time() + $config['timeendmodifier'];
|
||||
}
|
||||
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
$course1->lastaccess = 0;
|
||||
$courses = array($course1->id => $course1);
|
||||
|
||||
// As viewer1 (same group as post).
|
||||
$this->setUser($viewer1->id);
|
||||
$results = array();
|
||||
forum_print_overview($courses, $results);
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
|
||||
if ($hasresult) {
|
||||
// There should be one entry for course1.
|
||||
$this->assertCount(1, $results);
|
||||
|
||||
// There should be one entry for a forum in course1.
|
||||
$this->assertCount(1, $results[$course1->id]);
|
||||
$this->assertArrayHasKey('forum', $results[$course1->id]);
|
||||
} else {
|
||||
// There should be no entries for any course.
|
||||
$this->assertCount(0, $results);
|
||||
}
|
||||
|
||||
$this->setUser($viewer2->id);
|
||||
$results = array();
|
||||
forum_print_overview($courses, $results);
|
||||
$this->assertDebuggingCalledCount(2);
|
||||
|
||||
// There should be one entry for course1.
|
||||
$this->assertCount(0, $results);
|
||||
}
|
||||
|
||||
public function print_overview_timed_provider() {
|
||||
return array(
|
||||
'timestart_past' => array(
|
||||
'discussionconfig' => array(
|
||||
'timestartmodifier' => -86000,
|
||||
),
|
||||
'hasresult' => true,
|
||||
),
|
||||
'timestart_future' => array(
|
||||
'discussionconfig' => array(
|
||||
'timestartmodifier' => 86000,
|
||||
),
|
||||
'hasresult' => false,
|
||||
),
|
||||
'timeend_past' => array(
|
||||
'discussionconfig' => array(
|
||||
'timeendmodifier' => -86000,
|
||||
),
|
||||
'hasresult' => false,
|
||||
),
|
||||
'timeend_future' => array(
|
||||
'discussionconfig' => array(
|
||||
'timeendmodifier' => 86000,
|
||||
),
|
||||
'hasresult' => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test test_pinned_discussion_with_group.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue