From: moodler Date: Wed, 22 Oct 2003 13:14:56 +0000 (+0000) Subject: Modularised some of the processing for "extra" information such as X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8dddba42ce58b2f26130bf064c12c6ff2f8b0b30;p=moodle.git Modularised some of the processing for "extra" information such as information for popup windows on resources and labels --- diff --git a/course/lib.php b/course/lib.php index 05efc50899..af82da58a4 100644 --- a/course/lib.php +++ b/course/lib.php @@ -361,6 +361,8 @@ function get_array_of_activities($courseid) { // visible - is the instance visible or not // extra - contains extra string to include in any link + global $CFG; + $mod = array(); if (!$rawmods = get_course_mods($courseid)) { @@ -381,21 +383,15 @@ function get_array_of_activities($courseid) { $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); $mod[$seq]->visible = $rawmods[$seq]->visible; $mod[$seq]->extra = ""; - - // This part is an ugly hack that doesn't belong here// - if ($mod[$seq]->mod == "resource") { - if ($resource = get_record("resource", "id", $rawmods[$seq]->instance)) { - if (($resource->type == 3 or $resource->type == 5) and !empty($resource->alltext)) { - $mod[$seq]->extra = urlencode("target=\"resource$resource->id\" onClick=\"return ". - "openpopup('/mod/resource/view.php?inpopup=true&id=". - $mod[$seq]->cm. - "','resource$resource->id','$resource->alltext');\""); - } - } - } - if ($mod[$seq]->mod == "label") { - if ($label = get_record("label", "id", $rawmods[$seq]->instance)) { - $mod[$seq]->extra = urlencode($label->content); + + $modname = $mod[$seq]->mod; + $functionname = $modname."_get_coursemodule_info"; + + include_once("$CFG->dirroot/mod/$modname/lib.php"); + + if (function_exists($functionname)) { + if ($extra = $functionname($rawmods[$seq])) { + $mod[$seq]->extra = $extra; } } } diff --git a/mod/label/lib.php b/mod/label/lib.php index c01d7f7869..f6f9c0519e 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -79,4 +79,18 @@ function label_get_participants($labelid) { return false; } +function label_get_coursemodule_info($coursemodule) { +/// Given a course_module object, this function returns any +/// "extra" information that may be needed when printing +/// this activity in a course listing. +/// +/// See get_array_of_activities() in course/lib.php + + if ($label = get_record("label", "id", $coursemodule->instance)) { + return urlencode($label->content); + } + + return false; +} + ?> diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 4c781866ce..2cc390f0c4 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -133,4 +133,25 @@ function resource_get_participants($resourceid) { return false; } +function resource_get_coursemodule_info($coursemodule) { +/// Given a course_module object, this function returns any +/// "extra" information that may be needed when printing +/// this activity in a course listing. +/// +/// See get_array_of_activities() in course/lib.php +/// + + if ($resource = get_record("resource", "id", $coursemodule->instance)) { + if (($resource->type == UPLOADEDFILE or $resource->type == WEBLINK) and !empty($resource->alltext)) { + return urlencode("target=\"resource$resource->id\" onClick=\"return ". + "openpopup('/mod/resource/view.php?inpopup=true&id=". + $coursemodule->id. + "','resource$resource->id','$resource->alltext');\""); + } + } + + return false; +} + + ?>