This commit is contained in:
Andrew Nicols 2024-08-28 22:46:56 +08:00
commit e6146bca1b
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
8 changed files with 125 additions and 37 deletions

View File

@ -778,6 +778,27 @@ class manager {
} else {
$model['enabled'] = clean_param($model['enabled'], PARAM_BOOL);
}
// For the core models only, automatically remove references to modules that do not
// exist. This allows you to install without error if there are missing plugins.
if ($componentname === 'moodle') {
$updatedindicators = [];
$allmodules = [];
foreach ($model['indicators'] as $indicator) {
if (preg_match('~^\\\\mod_([^\\\\]+)\\\\~', $indicator, $matches)) {
if (!$allmodules) {
// The first time, get all modules.
$allmodules = \core\plugin_manager::instance()->get_plugins_of_type('mod');
}
if (!array_key_exists($matches[1], $allmodules)) {
// Module does not exist, so skip indicator.
continue;
}
}
$updatedindicators[] = $indicator;
}
$model['indicators'] = $updatedindicators;
}
}
static::validate_models_declaration($models);

View File

@ -2002,6 +2002,9 @@ $string['senddetails'] = 'Send my details via email';
$string['sent'] = 'Sent';
$string['separate'] = 'Separate';
$string['separateandconnected'] = 'Separate and Connected ways of knowing';
$string['separateandconnected1'] = 'Mostly separate knowing';
$string['separateandconnected2'] = 'Separate and connected';
$string['separateandconnected3'] = 'Mostly connected knowing';
$string['separateandconnectedinfo'] = 'The scale based on the theory of separate and connected knowing. This theory describes two different ways that we can evaluate and learn about the things we see and hear.<ul><li><strong>Separate knowers</strong> remain as objective as possible without including feelings and emotions. In a discussion with other people, they like to defend their own ideas, using logic to find holes in opponent\'s ideas.</li><li><strong>Connected knowers</strong> are more sensitive to other people. They are skilled at empathy and tend to listen and ask questions until they feel they can connect and "understand things from their point of view". They learn by trying to share the experiences that led to the knowledge they find in other people.</li></ul>';
$string['servererror'] = 'An error occurred whilst communicating with the server';
$string['serverlocaltime'] = 'Server\'s local time';

View File

@ -945,6 +945,30 @@ class block_manager {
}
}
/**
* Given an array of blocks in the format used by {@see add_blocks}, removes any blocks from
* the list if they are not installed in the system.
*
* @param array $blocks Array keyed by region
* @return array Updated array
*/
public function filter_nonexistent_blocks(array $blocks): array {
$installed = array_fill_keys(
array_map(fn($block) => $block->name, $this->get_installed_blocks()),
true,
);
$result = [];
foreach ($blocks as $region => $regionblocks) {
$result[$region] = [];
foreach ($regionblocks as $blockname) {
if (array_key_exists($blockname, $installed)) {
$result[$region][] = $blockname;
}
}
}
return $result;
}
/**
* Move a block to a new position on this page.
*
@ -2680,6 +2704,9 @@ function blocks_get_default_site_course_blocks() {
/**
* Add the default blocks to a course.
*
* Because this function is used on install, we skip over any default blocks that do not exist
* so that install can complete successfully even if blocks are removed.
*
* @param object $course a course object.
*/
function blocks_add_default_course_blocks($course) {
@ -2707,11 +2734,17 @@ function blocks_add_default_course_blocks($course) {
}
$page = new moodle_page();
$page->set_course($course);
$page->blocks->add_blocks($blocknames, $pagetypepattern);
$page->blocks->add_blocks(
$page->blocks->filter_nonexistent_blocks($blocknames),
$pagetypepattern,
);
}
/**
* Add the default system-context blocks. E.g. the admin tree.
*
* Because this function is used on install, we skip over any default blocks that do not exist
* so that install can complete successfully even if blocks are removed.
*/
function blocks_add_default_system_blocks() {
global $DB;
@ -2719,7 +2752,17 @@ function blocks_add_default_system_blocks() {
$page = new moodle_page();
$page->set_context(context_system::instance());
// We don't add blocks required by the theme, they will be auto-created.
$page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2);
$page->blocks->add_blocks(
$page->blocks->filter_nonexistent_blocks([
BLOCK_POS_LEFT => [
'admin_bookmarks',
],
]),
'admin-*',
null,
false,
2,
);
if ($defaultmypage = $DB->get_record('my_pages', array('userid' => null, 'name' => '__default', 'private' => 1))) {
$subpagepattern = $defaultmypage->id;
@ -2733,22 +2776,22 @@ function blocks_add_default_system_blocks() {
$mycoursesubpagepattern = null;
}
$page->blocks->add_blocks([
$page->blocks->add_blocks($page->blocks->filter_nonexistent_blocks([
BLOCK_POS_RIGHT => [
'recentlyaccesseditems',
],
'content' => [
'timeline',
'calendar_month',
]],
]]),
'my-index',
$subpagepattern
);
$page->blocks->add_blocks([
$page->blocks->add_blocks($page->blocks->filter_nonexistent_blocks([
'content' => [
'myoverview'
]],
]]),
'my-index',
$mycoursesubpagepattern
);

View File

@ -270,10 +270,7 @@ function upgrade_calculated_grade_items($courseid = null) {
/**
* This function creates a default separated/connected scale
* so there's something in the database. The locations of
* strings and files is a bit odd, but this is because we
* need to maintain backward compatibility with many different
* existing language translations and older sites.
* so there's something in the database.
*
* @global object
* @return void
@ -286,9 +283,9 @@ function make_default_scale() {
$defaultscale->userid = 0;
$defaultscale->name = get_string('separateandconnected');
$defaultscale->description = get_string('separateandconnectedinfo');
$defaultscale->scale = get_string('postrating1', 'forum').','.
get_string('postrating2', 'forum').','.
get_string('postrating3', 'forum');
$defaultscale->scale = get_string('separateandconnected1') . ',' .
get_string('separateandconnected2') . ',' .
get_string('separateandconnected3');
$defaultscale->timemodified = time();
$defaultscale->id = $DB->insert_record('scale', $defaultscale);

View File

@ -2589,16 +2589,6 @@ class global_navigation extends navigation_node {
}
}
if (!empty($CFG->navadduserpostslinks)) {
// Add nodes for forum posts and discussions if the user can view either or both
// There are no capability checks here as the content of the page is based
// purely on the forums the current user has access too.
$forumtab = $usernode->add(get_string('forumposts', 'forum'));
$forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs));
$forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php',
array_merge($baseargs, array('mode' => 'discussions'))));
}
// Add blog nodes.
if (!empty($CFG->enableblogs)) {
if (!$this->cache->cached('userblogoptions'.$user->id)) {
@ -5201,16 +5191,6 @@ class settings_navigation extends navigation_node {
$profilenode = $mainpage->add(get_string('profile'), new moodle_url('/user/profile.php',
array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
if (!empty($CFG->navadduserpostslinks)) {
// Add nodes for forum posts and discussions if the user can view either or both
// There are no capability checks here as the content of the page is based
// purely on the forums the current user has access too.
$forumtab = $profilenode->add(get_string('forumposts', 'forum'));
$forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs), null, 'myposts');
$forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php',
array_merge($baseargs, array('mode' => 'discussions'))), null, 'mydiscussions');
}
// Add blog nodes.
if (!empty($CFG->enableblogs)) {
if (!$this->cache->cached('userblogoptions'.$user->id)) {

View File

@ -530,9 +530,6 @@ $string['postmailinfo'] = 'This is a copy of a message posted in {$a}.';
$string['postmailnow'] = '<p>This post will be mailed out immediately to all forum subscribers.</p>';
$string['postmailreply'] = 'To reply click on this link: {$a}';
$string['postmailsubject'] = '{$a->courseshortname}: {$a->subject}';
$string['postrating1'] = 'Mostly separate knowing';
$string['postrating2'] = 'Separate and connected';
$string['postrating3'] = 'Mostly connected knowing';
$string['posts'] = 'Posts';
$string['postsfrom'] = 'Posts from';
$string['postsmadebyuser'] = 'Posts made by {$a}';

View File

@ -6912,3 +6912,50 @@ function forum_refresh_events(int $courseid, stdClass $instance, stdClass $cm):
forum_update_calendar($instance, $cm->id);
}
/**
* Callback adds navigation to view user posts if the navadduserpostslinks config is on.
*
* @param navigation_node $usernode User node within navigation
* @param stdClass $user User object
* @param \core\context\user $usercontext User context
* @param stdClass $course Current course
* @param \core\context $coursecontext Course context
*/
function mod_forum_extend_navigation_user(
navigation_node $usernode,
stdClass $user,
\core\context\user $usercontext,
stdClass $course,
\core\context $coursecontext,
): void {
global $CFG;
if (!empty($CFG->navadduserpostslinks) && $coursecontext instanceof \core\context\system) {
$baseargs = ['id' => $user->id];
// Add nodes for forum posts and discussions if the user can view either or both
// There are no capability checks here as the content of the page is based
// purely on the forums the current user has access too.
$forumtab = \navigation_node::create(get_string('forumposts', 'forum'));
$forumtab->add(
get_string('posts', 'forum'),
new moodle_url('/mod/forum/user.php', $baseargs),
);
$forumtab->add(
get_string('discussions', 'forum'),
new moodle_url('/mod/forum/user.php',
array_merge($baseargs, ['mode' => 'discussions']),
),
);
// We add the forum link either immediately after the 'viewuserdetails' link, or as the first item in the list.
foreach ($usernode->children as $child) {
if ($child->key === 'viewuserdetails') {
continue;
}
$addbefore = $child;
break;
}
$usernode->add_node($forumtab, $addbefore->key);
}
}

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2024082100; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)