Beispiel #1
0
/**
 * Returns the display name of the given section that the course prefers.
 *
 * This function utilizes a callback that can be implemented within the course
 * formats lib.php file to customize the display name that is used to reference
 * the section.
 *
 * By default (if callback is not defined) the method
 * {@see get_numeric_section_name} is called instead.
 *
 * @param stdClass $course The course to get the section name for
 * @param stdClass $section Section object from database
 * @return Display name that the course format prefers, e.g. "Week 2"
 *
 * @see get_generic_section_name
 */
function get_section_name(stdClass $course, stdClass $section)
{
    global $CFG;
    /// Inelegant hack for bug 3408
    if ($course->format == 'site') {
        return get_string('site');
    }
    // Use course formatter callback if it exists
    $namingfile = $CFG->dirroot . '/course/format/' . $course->format . '/lib.php';
    $namingfunction = 'callback_' . $course->format . '_get_section_name';
    if (!function_exists($namingfunction) && file_exists($namingfile)) {
        require_once $namingfile;
    }
    if (function_exists($namingfunction)) {
        return $namingfunction($course, $section);
    }
    // else, default behavior:
    return get_generic_section_name($course->format, $section);
}
function RWSASList()
{
    global $CFG;
    RWSCMAuth();
    RWSCRAuth();
    RWSCMUSvc();
    RWSCMMaint();
    $r_rv = RWSGSOpt("version", PARAM_ALPHANUMEXT);
    if ($r_rv === false || strlen($r_rv) == 0) {
        $r_bv = 2009093000;
    } else {
        $r_bv = intval($r_rv);
    }
    $r_pm = RWSGSOpt("courseid", PARAM_ALPHANUM);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2057");
    }
    $r_cid = intval($r_pm);
    $r_crs = RWSCMUCourse($r_cid);
    $r_secs = RWSGUVSList($r_cid);
    RWSRHXml();
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
    if (count($r_secs) == 0) {
        echo "<sectionlist />\r\n";
        exit;
    }
    echo "<sectionlist>\r\n";
    if ($r_bv < 2011020100) {
        if (respondusws_floatcompare($CFG->version, 2012120300, 2) >= 0) {
            $r_fnm = get_section_name($r_crs, $r_secs[0]);
        } else {
            $r_fnm = get_generic_section_name($r_crs->format, $r_secs[0]);
        }
        $r_p = strrpos($r_fnm, " ");
        if ($r_p !== false) {
            $r_fnm = substr($r_fnm, 0, $r_p);
        }
        echo "\t<format_name>";
        echo utf8_encode(htmlspecialchars(trim($r_fnm)));
        echo "</format_name>\r\n";
    }
    foreach ($r_secs as $r_s) {
        echo "\t<section>\r\n";
        if ($r_bv >= 2011020100) {
            $r_nm = get_section_name($r_crs, $r_s);
            echo "\t\t<name>";
            echo utf8_encode(htmlspecialchars($r_nm));
            echo "</name>\r\n";
        }
        $r_sum = trim($r_s->summary);
        if (strlen($r_sum) > 0) {
            echo "\t\t<summary>";
            echo utf8_encode(htmlspecialchars($r_sum));
            echo "</summary>\r\n";
        } else {
            echo "\t\t<summary />\r\n";
        }
        echo "\t\t<id>";
        echo utf8_encode(htmlspecialchars(trim($r_s->id)));
        echo "</id>\r\n";
        echo "\t\t<relative_index>";
        echo utf8_encode(htmlspecialchars(trim($r_s->section)));
        echo "</relative_index>\r\n";
        echo "\t</section>\r\n";
    }
    echo "</sectionlist>\r\n";
    exit;
}