}
}
-function rebuild_course_cache($courseid=0) {
+/**
+ * Rebuilds the cached list of course activities stored in the database
+ * @param int $courseid - id of course to rebuil, empty means all
+ * @param boolean $clearonly - only clear the modinfo fields, gets rebuild automatically on the fly
+ */
+function rebuild_course_cache($courseid=0, $clearonly=false) {
global $COURSE;
-// Rebuilds the cached list of course activities stored in the database
-// If a courseid is not specified, then all are rebuilt
+
+ if ($clearonly) {
+ $courseselect = empty($courseid) ? "" : "id = $courseid";
+ set_field_select('course', 'modinfo', null, $courseselect);
+ // update cached global COURSE too ;-)
+ if ($courseid == $COURSE->id) {
+ $COURSE->modinfo = null;
+ }
+ // reset the fast modinfo cache
+ $reset = 'reset';
+ get_fast_modinfo($reset);
+ return;
+ }
if ($courseid) {
$select = "id = '$courseid'";
@set_time_limit(0); // this could take a while! MDL-10954
}
- if ($courses = get_records_select("course", $select,'','id,fullname')) {
- foreach ($courses as $course) {
+ if ($rs = get_recordset_select("course", $select,'','id,fullname')) {
+ while($course = rs_fetch_next_record($rs)) {
$modinfo = serialize(get_array_of_activities($course->id));
if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
$COURSE->modinfo = $modinfo;
}
}
+ rs_close($rs);
}
// reset the fast modinfo cache
$reset = 'reset';
* @return string Requested piece of information from array
*/
function mimeinfo($element, $filename) {
- static $mimeinfo;
- $mimeinfo=get_mimetypes_array();
+ static $mimeinfo = null;
+ if (is_null($mimeinfo)) {
+ $mimeinfo = get_mimetypes_array();
+ }
if (eregi('\.([a-z0-9]+)$', $filename, $match)) {
if (isset($mimeinfo[strtolower($match[1])][$element])) {
var $strsubmissions;
var $strlastmodified;
var $pagetitle;
- var $currentgroup;
var $usehtmleditor;
var $defaultformat;
var $context;
$this->strlastmodified = get_string('lastmodified');
$this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));
- // visibility
- $context = get_context_instance(CONTEXT_MODULE, $cmid);
- if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
- $pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment);
- $navigation = build_navigation('', $this->cm);
-
- print_header($pagetitle, $this->course->fullname, $navigation,
- "", "", true, '', navmenu($this->course, $this->cm));
- notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
- }
- $this->currentgroup = groups_get_activity_group($this->cm);
+ // visibility handled by require_login() with $cm parameter
+ // get current group only when really needed
/// Set up things for a HTML editor if it's needed
if ($this->usehtmleditor = can_use_html_editor()) {
true, update_module_button($this->cm->id, $this->course->id, $this->strassignment),
navmenu($this->course, $this->cm));
- $groupmode = groups_get_activity_groupmode($this->cm);
groups_print_activity_menu($this->cm, 'view.php?id=' . $this->cm->id);
- $this->currentgroup = groups_get_activity_group($this->cm); // must be done after the printing!
echo '<div class="reportlink">'.$this->submittedlink().'</div>';
echo '<div class="clearer"></div>';
if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
$group = 0;
} else {
- $group = $this->currentgroup;
+ $group = groups_get_activity_group($this->cm);
}
if ($count = $this->count_real_submissions($group)) {
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
function assignment_get_coursemodule_info($coursemodule) {
global $CFG;
- if (! $assignment = get_record('assignment', 'id', $coursemodule->instance)) {
+ if (! $type = get_field('assignment', 'assignmenttype', 'id', $coursemodule->instance)) {
return false;
}
- require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
- $assignmentclass = "assignment_$assignment->assignmenttype";
- $ass = new $assignmentclass($coursemodule->id, $assignment);
+ $libfile = "$CFG->dirroot/mod/assignment/type/$type/assignment.class.php";
- return $ass->get_coursemodule_info($coursemodule);
+ if (file_exists($libfile)) {
+ require_once($libfile);
+ $assignmentclass = "assignment_$type";
+ $ass = new $assignmentclass('staticonly');
+ return $ass->get_coursemodule_info($coursemodule);
+
+ } else {
+ debugging('Incorrect assignment type: '.$type);
+ return false;
+ }
}
return false;
}
+/**
+ * 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
+ */
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)) {
+ if ($content = get_field('label', 'content', 'id', $coursemodule->instance)) {
$info = new object();
- $info->extra = urlencode($label->content);
+ $info->extra = urlencode($content);
return $info;
} else {
return null;
$info = NULL;
- if ($resource = get_record("resource", "id", $coursemodule->instance)) {
+ if ($resource = get_record("resource", "id", $coursemodule->instance, '', '', '', '', 'id, popup, reference, type')) {
$info = new object();
if (!empty($resource->popup)) {
$info->extra = urlencode("onclick=\"this.target='resource$resource->id'; return ".