Skip to content

Commit

Permalink
MDL-44070 Conditional availability enhancements (9): wider changes
Browse files Browse the repository at this point in the history
Changes to arbitrary areas of code that are necessary after the new
API (mostly to replace deprecated function calls).
  • Loading branch information
sammarshallou committed Apr 7, 2014
1 parent 00c832d commit 8270f0d
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion calendar/export_execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion calendar/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static function get_calendar_events($events = array(), $options = array()
$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 {
Expand Down
4 changes: 2 additions & 2 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion calendar/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public function show_month_detailed(calendar_information $calendar, moodle_url $
$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]);
}
}
Expand Down
1 change: 1 addition & 0 deletions mod/assign/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ public function test_group_members_only() {
$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));

}
Expand Down
22 changes: 3 additions & 19 deletions mod/assign/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,8 @@ public function upgrade_assignment($oldassignmentid, & $log) {
}

// 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',
Expand Down Expand Up @@ -400,9 +386,7 @@ private function duplicate_course_module(stdClass $cm, $moduleid, $newinstanceid
$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;

Expand Down
9 changes: 6 additions & 3 deletions mod/forum/discuss.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 1 addition & 3 deletions mod/glossary/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@

// 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;
Expand Down
5 changes: 2 additions & 3 deletions user/profile/definelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8270f0d

Please sign in to comment.