MDL-44070 Conditional availability enhancements (9): wider changes

Changes to arbitrary areas of code that are necessary after the new
API (mostly to replace deprecated function calls).
This commit is contained in:
sam marshall 2014-03-21 11:34:15 +00:00
parent 00c832d7a1
commit 8270f0d0bd
10 changed files with 20 additions and 35 deletions

View File

@ -175,7 +175,7 @@ $ical->add_property('method', 'PUBLISH');
foreach($events as $event) {
if (!empty($event->modulename)) {
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
if (!groups_course_module_visible($cm)) {
if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
continue;
}
}

View File

@ -235,7 +235,7 @@ class core_calendar_external extends external_api {
$events[$eventid] = $event;
} else if (!empty($eventobj->modulename)) {
$cm = get_coursemodule_from_instance($eventobj->modulename, $eventobj->instance);
if (groups_course_module_visible($cm)) {
if (\core_availability\info_module::is_user_visible($cm, 0, false)) {
$events[$eventid] = $event;
}
} else {

View File

@ -265,7 +265,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
foreach ($events as $eventid => $event) {
if (!empty($event->modulename)) {
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
if (!groups_course_module_visible($cm)) {
if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
unset($events[$eventid]);
}
}
@ -571,7 +571,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
if (!$cm = get_coursemodule_from_instance($event->modulename, $event->instance)) {
continue;
}
if (!coursemodule_visible_for_user($cm)) {
if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
continue;
}
}

View File

@ -454,7 +454,7 @@ class core_calendar_renderer extends plugin_renderer_base {
$event = new calendar_event($event);
if (!empty($event->modulename)) {
$cm = get_coursemodule_from_instance($event->modulename, $event->instance);
if (!groups_course_module_visible($cm)) {
if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
unset($events[$eventid]);
}
}

View File

@ -863,6 +863,7 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
$assign = new testable_assign($context, $cm, $this->course);
$this->setUser($this->teachers[0]);
get_fast_modinfo($this->course, 0, true);
$this->assertCount(5, $assign->list_participants(0, true));
}

View File

@ -179,22 +179,8 @@ class assign_upgrade_manager {
}
// Upgrade availability data.
$DB->set_field('course_modules_avail_fields',
'coursemoduleid',
$newcoursemodule->id,
array('coursemoduleid'=>$oldcoursemodule->id));
$DB->set_field('course_modules_availability',
'coursemoduleid',
$newcoursemodule->id,
array('coursemoduleid'=>$oldcoursemodule->id));
$DB->set_field('course_modules_availability',
'sourcecmid',
$newcoursemodule->id,
array('sourcecmid'=>$oldcoursemodule->id));
$DB->set_field('course_sections_availability',
'sourcecmid',
$newcoursemodule->id,
array('sourcecmid'=>$oldcoursemodule->id));
\core_availability\info::update_dependency_id_across_course(
$newcoursemodule->course, 'course_modules', $oldcoursemodule->id, $newcoursemodule->id);
// Upgrade completion data.
$DB->set_field('course_modules_completion',
@ -400,9 +386,7 @@ class assign_upgrade_manager {
$newcm->completionview = $cm->completionview;
$newcm->completionexpected = $cm->completionexpected;
if (!empty($CFG->enableavailability)) {
$newcm->availablefrom = $cm->availablefrom;
$newcm->availableuntil = $cm->availableuntil;
$newcm->showavailability = $cm->showavailability;
$newcm->availability = $cm->availability;
}
$newcm->showdescription = $cm->showdescription;

View File

@ -77,11 +77,14 @@
print_error('cannotmovetosingleforum', 'forum', $return);
}
if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) {
// Get target forum cm and check it is visible to current user.
$modinfo = get_fast_modinfo($course);
$forums = $modinfo->get_instances_of('forum');
if (!array_key_exists($forumto->id, $forums)) {
print_error('cannotmovetonotfound', 'forum', $return);
}
if (!coursemodule_visible_for_user($cmto)) {
$cmto = $forums[$forumto->id];
if (!$cmto->uservisible) {
print_error('cannotmovenotvisible', 'forum', $return);
}

View File

@ -3267,7 +3267,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
}
if (!isset($cm->uservisible)) {
$cm->uservisible = coursemodule_visible_for_user($cm);
$cm->uservisible = \core_availability\info_module::is_user_visible($cm, 0, false);
}
if ($istracked && is_null($postisread)) {
@ -5475,7 +5475,7 @@ function forum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=NUL
return false;
}
} else {
if (!coursemodule_visible_for_user($cm, $user->id)) {
if (!\core_availability\info_module::is_user_visible($cm, $user->id, false)) {
return false;
}
}

View File

@ -134,9 +134,7 @@ if ($xml = glossary_read_imported_file($result)) {
// These fields were not included in export, assume zero.
$glossary->assessed = 0;
$glossary->availablefrom = 0;
$glossary->availableuntil = 0;
$glossary->showavailability = 0;
$glossary->availability = null;
// New glossary is to be inserted in section 0, it is always visible.
$glossary->section = 0;

View File

@ -318,9 +318,8 @@ function profile_delete_field($id) {
print_error('cannotdeletecustomfield');
}
// Delete any module dependencies for this field.
$DB->delete_records('course_modules_avail_fields', array('customfieldid' => $id));
$DB->delete_records('course_sections_avail_fields', array('customfieldid' => $id));
// Note: Any availability conditions that depend on this field will remain,
// but show the field as missing until manually corrected to something else.
// Need to rebuild course cache to update the info.
rebuild_course_cache();