Beispiel #1
0
function local_my_print_courses($title = 'mycourses', $courses, $options = array())
{
    global $OUTPUT, $DB, $PAGE;
    $config = get_config('local_my');
    $renderer = $PAGE->get_renderer('local_my');
    $str = '';
    // Be sure we have something in lastaccess.
    foreach ($courses as $cid => $c) {
        $courses[$cid]->lastaccess = 0 + @$courses[$cid]->lastaccess;
    }
    if (empty($courses)) {
        if (!empty($options['printifempty']) && empty($options['noheading'])) {
            $str .= '<div class="header">';
            $str .= '<div class="title">';
            $str .= '<h2>' . get_string($title, 'local_my') . '</h2>';
            $str .= '</div>';
            $str .= '</div>';
            $str .= $OUTPUT->box(get_string('nocourses', 'local_my'), 'content');
        }
    } else {
        if (empty($options['noheading'])) {
            $str .= '<div class="header">';
            $str .= '<div class="title">';
            $str .= '<h2>' . get_string($title, 'local_my') . '</h2>';
            $str .= '</div>';
            $str .= '</div>';
            $str .= '<div class="content">';
        }
        $str .= '<table class="courselist" width="100%">';
        if (!empty($options['withoverview'])) {
            $str .= local_print_course_overview($courses, $options);
        } else {
            if (!empty($options['withcats'])) {
                $str .= local_print_courses_by_cats($courses, $options, $config->printcategories);
            } else {
                foreach ($courses as $c) {
                    $str .= $renderer->course_table_row($c, $options);
                }
            }
        }
        $str .= '</table>';
        if (empty($options['noheading'])) {
            $str .= '</div>';
            $str .= '</div>';
        }
    }
    return $str;
}
Beispiel #2
0
/**
 * 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;
}