/** * Prefetch courses that will be printed by course areas */ function local_prefetch_course_areas(&$excludedcourses) { global $DB; $allcourses = enrol_get_my_courses('id, shortname'); $config = get_config('local_my'); if (!empty($excludedcourses)) { foreach ($excludedcourses as $id => $c) { unset($allcourses[$id]); } } if (empty($config->courseareas)) { // Performance quick trap. return array(); } $prefetchareacourses = array(); for ($i = 0; $i < $config->courseareas; $i++) { $coursearea = 'coursearea' . $i; if (!empty($config->{$coursearea})) { $mastercategory = $DB->get_record('course_categories', array('id' => $config->{$coursearea})); // Filter courses of this area. $retainedcategories = local_get_cat_branch_ids_rec($mastercategory->id); foreach ($allcourses as $c) { if (in_array($c->category, $retainedcategories)) { $c->summary = $DB->get_field('course', 'summary', array('id' => $c->id)); $prefetchareacourses[$c->id] = $c; } } } } return $prefetchareacourses; }
/** * Prints the specific courses area as a 3 column link list */ function local_my_print_course_areas_and_availables(&$excludedcourses, &$courseareacourses) { global $USER, $CFG, $OUTPUT, $DB; $debug = 0; $mycourses = enrol_get_my_courses('id,shortname,fullname'); $availablecourses = local_get_enrollable_courses(); $config = get_config('local_my'); if (!$config->courseareas) { // Performance quick trap. return; } if (empty($mycourses)) { $mycourses = array(); // Be sure of that ! } if (empty($availablecourses)) { $availablecourses = array(); } if (empty($courseareacourses)) { $courseareacourses = array(); } if (!empty($excludedcourses)) { foreach ($excludedcourses as $id => $c) { if (in_array($id, array_keys($courseareacourses))) { continue; } if ($debug) { echo "reject enrolled as excluded {$id} <br/>"; } if (array_key_exists($id, $mycourses)) { unset($mycourses[$id]); } if (array_key_exists($id, $availablecourses)) { if ($debug) { echo "reject available as excluded {$id} <br/>"; } unset($availablecourses[$id]); } } } foreach ($mycourses as $id => $c) { $mycourses[$id]->lastaccess = $DB->get_field('log', 'max(time)', array('course' => $id)); } $str = ''; $str .= '<table id="mycourseareas" width="100%">'; $str .= '<tr valign="top">'; $options['noheading'] = 1; $options['nooverview'] = 1; $options['withdescription'] = 0; $options['withcats'] = $config->printcategories; $options['withcats'] = 0; // Which one ??? $options['gaugewidth'] = 60; $options['gaugeheight'] = 15; $reali = 1; for ($i = 0; $i < $config->courseareas; $i++) { $coursearea = 'coursearea' . $i; $mastercategory = $DB->get_record('course_categories', array('id' => $config->{$coursearea})); $key = 'coursearea' . $i; $categoryid = $config->{$key}; if ($debug) { echo " > coursearea {$i} <br/>"; } // Filter courses of this area. $retainedcategories = local_get_cat_branch_ids_rec($categoryid); $myareacourses = array(); foreach ($mycourses as $c) { if ($debug) { echo " checking enrolled {$c->id} ... "; } if (in_array($c->category, $retainedcategories)) { if ($debug) { echo " accept enrolled {$c->id} <br/>"; } $myareacourses[$c->id] = $c; $excludedcourses[$c->id] = 1; } else { if ($debug) { echo " reject enrolled {$c->id} not in cat <br/>"; } } } $availableareacourses = array(); foreach ($availablecourses as $c) { if ($debug) { echo " checking available {$c->id} ... "; } if (!isset($c->summary)) { $c->summary = $DB->get_field('course', 'summary', array('id' => $id)); } if (in_array($c->category, $retainedcategories)) { if ($debug) { echo " accept available {$c->id} ... "; } $availableareacourses[$c->id] = $c; $excludedcourses[$c->id] = 1; } else { if ($debug) { echo " reject enrollable {$c->id} not in cat <br/>"; } } } if (!empty($myareacourses) || !empty($availableareacourses)) { if ($reali % 3 == 0) { $str .= '</tr><tr valign="top">'; } $str .= '<td width="33%">'; $str .= '<div class="block block_coursearea_courses">'; $str .= '<div class="header">'; $str .= '<div class="title">'; $str .= $OUTPUT->heading(format_string($mastercategory->name), 2, 'headingblock header'); $str .= '</div>'; $str .= '</div>'; $str .= '<div class="content">'; $str .= '<table id="courselistarea' . $reali . '" width="100%" class="courselist">'; $str .= '<tr valign="top">'; $str .= '<td>'; if (empty($options['nooverview'])) { if (count($myareacourses) < $config->maxoverviewedlistsize) { $str .= local_print_course_overview($myareacourses, $options); } else { // Solve a performance issue for people having wide access to courses. $str .= local_print_courses_by_cats($myareacourses, $options); } } else { // Aggregate my courses with the available and print in one unique list. $availableareacourses = $myareacourses + $availableareacourses; } if (!empty($availableareacourses)) { $str .= local_my_print_courses('available', $availableareacourses, $options); } $str .= '</td>'; $str .= '</tr>'; $str .= '</table>'; $str .= '</div>'; $str .= '</div>'; $str .= '</td>'; $reali++; } } $str .= '</tr>'; $str .= '</table>'; return $str; }