Permalink
Browse files

MDL-27001 'Show description' feature part 3: Implementation for all m…

…odules

For modules that still used the 'old' generic object return from _get_coursemodule_info instead of returning a cached_cm_info object, I changed them to use the new format as part of this. This made a few areas of code regarding onclick links slightly nicer.
  • Loading branch information...
1 parent b3a8923 commit 3e4c24350090292a3316ed217756cc3731dcfd31 @sammarshallou sammarshallou committed Jul 21, 2011
@@ -2070,11 +2070,10 @@ function custom_feedbackform($submission, $return=false) {
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param $coursemodule object The coursemodule object (record).
- * @return object An object on information that the courses will know about (most noticeably, an icon).
- *
+ * @return cached_cm_info Object used to customise appearance on course page
*/
function get_coursemodule_info($coursemodule) {
- return false;
+ return null;
}
/**
@@ -3341,13 +3340,13 @@ function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param $coursemodule object The coursemodule object (record).
- * @return object An object on information that the courses will know about (most noticeably, an icon).
- *
+ * @return cached_cm_info An object on information that the courses will know about (most noticeably, an icon).
*/
function assignment_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
- if (! $assignment = $DB->get_record('assignment', array('id'=>$coursemodule->instance), 'id, assignmenttype, name')) {
+ if (! $assignment = $DB->get_record('assignment', array('id'=>$coursemodule->instance),
+ 'id, assignmenttype, name, intro, introformat')) {
return false;
}
@@ -3357,14 +3356,15 @@ function assignment_get_coursemodule_info($coursemodule) {
require_once($libfile);
$assignmentclass = "assignment_$assignment->assignmenttype";
$ass = new $assignmentclass('staticonly');
- if ($result = $ass->get_coursemodule_info($coursemodule)) {
- return $result;
- } else {
- $info = new stdClass();
- $info->name = $assignment->name;
- return $info;
+ if (!($result = $ass->get_coursemodule_info($coursemodule))) {
+ $result = new cached_cm_info();
+ $result->name = $assignment->name;
}
-
+ if ($coursemodule->showdescription) {
+ // Convert intro to html. Do not filter cached version, filters run at display time.
+ $info->content = format_module_intro('assignment', $assignment, $coursemodule->id, false);
+ }
+ return $result;
} else {
debugging('Incorrect assignment type: '.$assignment->assignmenttype);
return false;
@@ -3669,6 +3669,7 @@ function assignment_supports($feature) {
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -1238,6 +1238,7 @@ function chat_supports($feature) {
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -795,6 +795,7 @@ function choice_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -2683,6 +2683,7 @@ function data_supports($feature) {
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_RATE: return true;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
@@ -61,6 +61,7 @@ function feedback_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -42,6 +42,7 @@ function folder_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -292,6 +292,7 @@ function forum_supports($feature) {
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_RATE: return true;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
@@ -2691,6 +2691,7 @@ function glossary_supports($feature) {
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_RATE: return true;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -42,6 +42,7 @@ function imscp_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -40,6 +40,7 @@ function page_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
@@ -247,20 +248,26 @@ function page_get_participants($pageid) {
*
* See {@link get_array_of_activities()} in course/lib.php
*
- * @param object $coursemodule
- * @return object info
+ * @param cm_info $coursemodule
+ * @return cached_cm_info Info to customise main page display
*/
function page_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
- if (!$page = $DB->get_record('page', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions')) {
+ if (!$page = $DB->get_record('page', array('id'=>$coursemodule->instance),
+ 'id, name, display, displayoptions, intro, introformat')) {
return NULL;
}
- $info = new stdClass();
+ $info = new cached_cm_info();
$info->name = $page->name;
+ if ($coursemodule->showdescription) {
+ // Convert intro to html. Do not filter cached version, filters run at display time.
+ $info->content = format_module_intro('page', $page, $coursemodule->id, false);
+ }
+
if ($page->display != RESOURCELIB_DISPLAY_POPUP) {
return $info;
}
@@ -270,7 +277,7 @@ function page_get_coursemodule_info($coursemodule) {
$width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
$height = empty($options['popupheight']) ? 450 : $options['popupheight'];
$wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
- $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";
+ $info->onclick = "window.open('$fullurl', '', '$wh'); return false;";
return $info;
}
View
@@ -1494,6 +1494,7 @@ function quiz_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -40,6 +40,7 @@ function resource_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
@@ -226,8 +227,8 @@ function resource_get_participants($resourceid) {
*
* See {@link get_array_of_activities()} in course/lib.php
*
- * @param object $coursemodule
- * @return object info
+ * @param cm_info $coursemodule
+ * @return cached_cm_info info
*/
function resource_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
@@ -237,12 +238,17 @@ function resource_get_coursemodule_info($coursemodule) {
$context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);
- if (!$resource = $DB->get_record('resource', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions, tobemigrated, revision')) {
+ if (!$resource = $DB->get_record('resource', array('id'=>$coursemodule->instance),
+ 'id, name, display, displayoptions, tobemigrated, revision, intro, introformat')) {
return NULL;
}
- $info = new stdClass();
+ $info = new cached_cm_info();
$info->name = $resource->name;
+ if ($coursemodule->showdescription) {
+ // Convert intro to html. Do not filter cached version, filters run at display time.
+ $info->content = format_module_intro('resource', $resource, $coursemodule->id, false);
+ }
if ($resource->tobemigrated) {
$info->icon ='i/cross_red_big';
@@ -264,15 +270,15 @@ function resource_get_coursemodule_info($coursemodule) {
$width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
$height = empty($options['popupheight']) ? 450 : $options['popupheight'];
$wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
- $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";
+ $info->onclick = "window.open('$fullurl', '', '$wh'); return false;";
} else if ($display == RESOURCELIB_DISPLAY_NEW) {
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
- $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
+ $info->onclick = "window.open('$fullurl'); return false;";
} else if ($display == RESOURCELIB_DISPLAY_OPEN) {
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
- $info->extra = "onclick=\"window.location.href ='$fullurl';return false;\"";
+ $info->onclick = "window.location.href ='$fullurl';return false;";
} else if ($display == RESOURCELIB_DISPLAY_DOWNLOAD) {
if (empty($mainfile)) {
@@ -293,7 +299,7 @@ function resource_get_coursemodule_info($coursemodule) {
if ($completion->is_enabled($coursemodule) == COMPLETION_TRACKING_AUTOMATIC) {
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
}
- $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
+ $info->onclick = "window.open('$fullurl'); return false;";
}
return $info;
View
@@ -940,6 +940,7 @@ function scorm_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
@@ -1123,4 +1124,4 @@ function scorm_version_check($scormversion, $version='') {
}
}
return false;
-}
+}
View
@@ -806,6 +806,7 @@ function survey_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
View
@@ -42,6 +42,7 @@ function url_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
@@ -260,11 +261,12 @@ function url_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
require_once("$CFG->dirroot/mod/url/locallib.php");
- if (!$url = $DB->get_record('url', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions, externalurl, parameters')) {
+ if (!$url = $DB->get_record('url', array('id'=>$coursemodule->instance),
+ 'id, name, display, displayoptions, externalurl, parameters, intro, introformat')) {
return NULL;
}
- $info = new stdClass();
+ $info = new cached_cm_info();
$info->name = $url->name;
//note: there should be a way to differentiate links from normal resources
@@ -278,15 +280,20 @@ function url_get_coursemodule_info($coursemodule) {
$width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
$height = empty($options['popupheight']) ? 450 : $options['popupheight'];
$wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
- $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";
+ $info->onclick = "window.open('$fullurl', '', '$wh'); return false;";
} else if ($display == RESOURCELIB_DISPLAY_NEW) {
$fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
- $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
+ $info->onclick = "window.open('$fullurl'); return false;";
} else if ($display == RESOURCELIB_DISPLAY_OPEN) {
$fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
- $info->extra = "onclick=\"window.location.href ='$fullurl';return false;\"";
+ $info->onclick = "window.location.href ='$fullurl';return false;";
+ }
+
+ if ($coursemodule->showdescription) {
+ // Convert intro to html. Do not filter cached version, filters run at display time.
+ $info->content = format_module_intro('url', $url, $coursemodule->id, false);
}
return $info;
View
@@ -254,6 +254,8 @@ function wiki_supports($feature) {
return false;
case FEATURE_BACKUP_MOODLE2:
return true;
+ case FEATURE_SHOW_DESCRIPTION:
+ return true;
default:
return null;
@@ -50,6 +50,7 @@ function workshop_supports($feature) {
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS:
return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
}

0 comments on commit 3e4c243

Please sign in to comment.