Skip to content

Commit

Permalink
MDL-35339 avoid using get_all_sections(), get_all_mods() and field se…
Browse files Browse the repository at this point in the history
…ction.sequence directly
  • Loading branch information
marinaglancy committed Oct 15, 2012
1 parent ecfe814 commit 71a56e0
Show file tree
Hide file tree
Showing 31 changed files with 65 additions and 154 deletions.
13 changes: 6 additions & 7 deletions blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function get_content() {
require_once($CFG->dirroot.'/course/lib.php');
$context = context_course::instance($course->id);
$isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);

/// extra fast view mode
if (!$isediting) {
$modinfo = get_fast_modinfo($course);
if (!empty($modinfo->sections[0])) {
$options = array('overflowdiv'=>true);
foreach($modinfo->sections[0] as $cmid) {
Expand Down Expand Up @@ -62,7 +62,7 @@ function get_content() {
/// slow & hacky editing mode
$ismoving = ismoving($course->id);
$section = get_course_section(0, $course->id);

$modinfo = get_fast_modinfo($course);
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);

$groupbuttons = $course->groupmode;
Expand All @@ -82,14 +82,13 @@ function get_content() {
$this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
}

if (!empty($section->sequence)) {
$sectionmods = explode(',', $section->sequence);
if (!empty($modinfo->sections[0])) {
$options = array('overflowdiv'=>true);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
foreach ($modinfo->sections[0] as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if (!$mod->uservisible) {
continue;
}
$mod = $mods[$modnumber];
if (!$ismoving) {
if ($groupbuttons) {
if (! $mod->groupmodelink = $groupbuttonslink) {
Expand Down
16 changes: 6 additions & 10 deletions blocks/social_activities/block_social_activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ function get_content() {

/// slow & hacky editing mode
$ismoving = ismoving($course->id);
$sections = get_all_sections($course->id);

if(!empty($sections) && isset($sections[0])) {
$section = $sections[0];
}
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(0);

if (!empty($section)) {
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
Expand All @@ -91,14 +88,13 @@ function get_content() {
$this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
}

if (!empty($section) && !empty($section->sequence)) {
$sectionmods = explode(',', $section->sequence);
if (!empty($modinfo->sections[0])) {
$options = array('overflowdiv'=>true);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
foreach ($modinfo->sections[0] as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if (!$mod->uservisible) {
continue;
}
$mod = $mods[$modnumber];
if (!$ismoving) {
if ($groupbuttons) {
if (! $mod->groupmodelink = $groupbuttonslink) {
Expand Down
5 changes: 2 additions & 3 deletions course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ public static function get_course_contents($courseid, $options = array()) {

//retrieve sections
$modinfo = get_fast_modinfo($course);
$sections = get_all_sections($course->id);
$sections = $modinfo->get_section_info_all();

//for each sections (first displayed to last displayed)
foreach ($sections as $key => $section) {

$showsection = (has_capability('moodle/course:viewhiddensections', $context) or $section->visible or !$course->hiddensections);
if (!$showsection) {
if (!$section->uservisible) {
continue;
}

Expand Down
34 changes: 14 additions & 20 deletions course/recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@
$hiddenfilter = "AND cs.visible = 1";
}
$sections = array();
$rawsections = array_slice(get_all_sections($course->id), 0, $course->numsections+1, true);
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
foreach ($rawsections as $section) {
if ($canviewhidden || !empty($section->visible)) {
$sections[$section->section] = $section;
foreach ($modinfo->get_section_info_all() as $i => $section) {
if (!empty($section->uservisible)) {
$sections[$i] = $section;
}
}

Expand All @@ -115,20 +113,18 @@
}

} else if (is_numeric($param->modid)) {
$section = $sections[$modinfo->cms[$param->modid]->sectionnum];
$section->sequence = $param->modid;
$sections = array($section->sequence=>$section);
$sectionnum = $modinfo->cms[$param->modid]->sectionnum;
$filter_modid = $param->modid;
$sections = array($sectionnum => $sections[$sectionnum]);
}


if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$modinfo->get_groups(); // load all my groups and cache it in modinfo

$activities = array();
$index = 0;

foreach ($sections as $section) {
foreach ($sections as $sectionnum => $section) {

$activity = new stdClass();
$activity->type = 'section';
Expand All @@ -141,17 +137,11 @@
$activity->visible = $section->visible;
$activities[$index++] = $activity;

if (empty($section->sequence)) {
if (empty($modinfo->sections[$sectionnum])) {
continue;
}

$sectionmods = explode(",", $section->sequence);

foreach ($sectionmods as $cmid) {
if (!isset($mods[$cmid]) or !isset($modinfo->cms[$cmid])) {
continue;
}

foreach($modinfo->sections[$sectionnum] as $cmid) {
$cm = $modinfo->cms[$cmid];

if (!$cm->uservisible) {
Expand All @@ -162,6 +152,10 @@
continue;
}

if (!empty($filter_modid) and $cmid != $filter_modid) {
continue;
}

$libfile = "$CFG->dirroot/mod/$cm->modname/lib.php";

if (file_exists($libfile)) {
Expand Down
3 changes: 1 addition & 2 deletions course/recent_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function definition() {
$mform =& $this->_form;
$context = context_course::instance($COURSE->id);
$modinfo = get_fast_modinfo($COURSE);
$sections = get_all_sections($COURSE->id);

$mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string

Expand Down Expand Up @@ -127,7 +126,7 @@ function definition() {
}

foreach ($modinfo->sections as $section=>$cmids) {
$options["section/$section"] = "-- ".get_section_name($COURSE, $sections[$section])." --";
$options["section/$section"] = "-- ".get_section_name($COURSE, $section)." --";
foreach ($cmids as $cmid) {
$cm = $modinfo->cms[$cmid];
if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
Expand Down
5 changes: 1 addition & 4 deletions course/resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@

$modinfo = get_fast_modinfo($course);
$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}
$cms = array();
$resources = array();
foreach ($modinfo->cms as $cm) {
Expand Down Expand Up @@ -116,7 +113,7 @@
$printsection = '';
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = get_section_name($course, $sections[$cm->sectionnum]);
$printsection = get_section_name($course, $cm->sectionnum);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
Expand Down
5 changes: 1 addition & 4 deletions mod/assignment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

$timenow = time();

Expand Down Expand Up @@ -74,7 +71,7 @@
if ($usesections) {
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = get_section_name($course, $sections[$cm->sectionnum]);
$printsection = get_section_name($course, $cm->sectionnum);
}
if ($currentsection !== "") {
$table->data[] = 'hr';
Expand Down
4 changes: 1 addition & 3 deletions mod/assignment/type/online/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
// get all the assignments in the course
$assignments = get_all_instances_in_course('assignment',$course, $USER->id );

$sections = get_all_sections($course->id);

// array to hold display data
$views = array();

Expand Down Expand Up @@ -98,7 +96,7 @@
$view = new stdClass;

// start to build view object
$view->section = get_section_name($course, $sections[$assignment->section]);
$view->section = get_section_name($course, $assignment->section);

$view->name = $assignment->name;
$view->submitted = $submitted;
Expand Down
5 changes: 1 addition & 4 deletions mod/book/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
Expand All @@ -80,7 +77,7 @@
$printsection = '';
if ($book->section !== $currentsection) {
if ($book->section) {
$printsection = get_section_name($course, $sections[$book->section]);
$printsection = get_section_name($course, $book->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
Expand Down
5 changes: 1 addition & 4 deletions mod/chat/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

/// Print the list of instances (your module will probably extend this)

Expand Down Expand Up @@ -69,7 +66,7 @@
$printsection = '';
if ($chat->section !== $currentsection) {
if ($chat->section) {
$printsection = get_section_name($course, $sections[$chat->section]);
$printsection = get_section_name($course, $chat->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
Expand Down
5 changes: 1 addition & 4 deletions mod/choice/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

$sql = "SELECT cha.*
FROM {choice} ch, {choice_answers} cha
Expand Down Expand Up @@ -76,7 +73,7 @@
$printsection = "";
if ($choice->section !== $currentsection) {
if ($choice->section) {
$printsection = get_section_name($course, $sections[$choice->section]);
$printsection = get_section_name($course, $choice->section);
}
if ($currentsection !== "") {
$table->data[] = 'hr';
Expand Down
5 changes: 1 addition & 4 deletions mod/data/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

$timenow = time();
$strname = get_string('name');
Expand Down Expand Up @@ -120,7 +117,7 @@
if ($usesections) {
if ($data->section !== $currentsection) {
if ($data->section) {
$printsection = get_section_name($course, $sections[$data->section]);
$printsection = get_section_name($course, $data->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
Expand Down
5 changes: 1 addition & 4 deletions mod/feedback/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

/// Print the list of instances (your module will probably extend this)

Expand Down Expand Up @@ -105,7 +102,7 @@
$link = '<a '.$dimmedclass.' href="'.$viewurl->out().'">'.$feedback->name.'</a>';

if ($usesections) {
$tabledata = array (get_section_name($course, $sections[$feedback->section]), $link);
$tabledata = array (get_section_name($course, $feedback->section), $link);
} else {
$tabledata = array ($link);
}
Expand Down
5 changes: 1 addition & 4 deletions mod/folder/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
}

$usesections = course_format_uses_sections($course->format);
if ($usesections) {
$sections = get_all_sections($course->id);
}

$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
Expand All @@ -77,7 +74,7 @@
$printsection = '';
if ($folder->section !== $currentsection) {
if ($folder->section) {
$printsection = get_section_name($course, $sections[$folder->section]);
$printsection = get_section_name($course, $folder->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
Expand Down
3 changes: 1 addition & 2 deletions mod/forum/discuss.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@
$modinfo = get_fast_modinfo($course);
if (isset($modinfo->instances['forum'])) {
$forummenu = array();
$sections = get_all_sections($course->id);
// Check forum types and eliminate simple discussions.
$forumcheck = $DB->get_records('forum', array('course' => $course->id),'', 'id, type');
foreach ($modinfo->instances['forum'] as $forumcm) {
Expand All @@ -228,7 +227,7 @@
continue;
}
$section = $forumcm->sectionnum;
$sectionname = get_section_name($course, $sections[$section]);
$sectionname = get_section_name($course, $section);
if (empty($forummenu[$section])) {
$forummenu[$section] = array($sectionname => array());
}
Expand Down
3 changes: 1 addition & 2 deletions mod/forum/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
}

$usesections = course_format_uses_sections($course->format);
$sections = get_all_sections($course->id);

$table = new html_table();

Expand Down Expand Up @@ -358,7 +357,7 @@
$forum->intro = shorten_text(format_module_intro('forum', $forum, $cm->id), $CFG->forum_shortpost);

if ($cm->sectionnum != $currentsection) {
$printsection = get_section_name($course, $sections[$cm->sectionnum]);
$printsection = get_section_name($course, $cm->sectionnum);
if ($currentsection) {
$learningtable->data[] = 'hr';
}
Expand Down
Loading

0 comments on commit 71a56e0

Please sign in to comment.