diff --git a/blocks/messages/block_messages.php b/blocks/messages/block_messages.php index 93589364e91d7..c56170001dcd1 100644 --- a/blocks/messages/block_messages.php +++ b/blocks/messages/block_messages.php @@ -28,7 +28,7 @@ function get_content() { $this->content->footer = ''.get_string('messages', 'message').'...'; $users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count, - u.firstname, u.lastname, u.picture, u.lastaccess + u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess FROM {$CFG->prefix}user u, {$CFG->prefix}message m WHERE m.useridto = '$USER->id' @@ -43,7 +43,7 @@ function get_content() { foreach ($users as $user) { $timeago = format_time(time() - $user->lastaccess); $this->content->text .= '
'; - print_user_picture($template['userid'], SITEID, $user->picture); + print_user_picture($user, SITEID, $user->picture); echo ' | '; echo ''.$template['title'].' ';
diff --git a/course/lib.php b/course/lib.php
index 9f1a5353a79b3..a063c2fe56a21 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1074,6 +1074,16 @@ function &get_fast_modinfo(&$course, $userid=0) {
$modlurals = array();
+ $cmids = array();
+ $contexts = null;
+ foreach ($info as $mod) {
+ $cmids[$mod->cm] = $mod->cm;
+ }
+ if ($cmids) {
+ // preload all module contexts with one query
+ $contexts = get_context_instance(CONTEXT_MODULE, $cmids);
+ }
+
foreach ($info as $mod) {
// reconstruct minimalistic $cm
$cm = new object();
@@ -1097,11 +1107,11 @@ function &get_fast_modinfo(&$course, $userid=0) {
}
$cm->modplural = $modlurals[$cm->modname];
- if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+ if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $contexts[$cm->id], $userid)) {
$cm->uservisible = false;
} else if (!empty($CFG->enablegroupings) and !empty($cm->groupmembersonly)
- and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+ and !has_capability('moodle/site:accessallgroups', $contexts[$cm->id], $userid)) {
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id, $userid);
}
@@ -1440,6 +1450,10 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
if (function_exists($gettypesfunc)) {
$types = $gettypesfunc();
foreach($types as $type) {
+ if (!isset($type->modclass) or !isset($type->typestr)) {
+ debugging('Incorrect ativity type in '.$modname);
+ continue;
+ }
if ($type->modclass == MOD_CLASS_RESOURCE) {
$resources[$type->type] = $type->typestr;
} else {
diff --git a/lib/accesslib.php b/lib/accesslib.php
index e550f46c1b55c..2f10620d16573 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -2538,7 +2538,7 @@ function cleanup_contexts() {
*/
function get_context_instance($contextlevel, $instance=0) {
- global $context_cache, $context_cache_id;
+ global $context_cache, $context_cache_id, $CFG;
static $allowed_contexts = array(CONTEXT_SYSTEM, CONTEXT_USER, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_GROUP, CONTEXT_MODULE, CONTEXT_BLOCK);
if ($contextlevel === 'clearcache') {
@@ -2561,30 +2561,79 @@ function get_context_instance($contextlevel, $instance=0) {
error('Error: get_context_instance() called with incorrect context level "'.s($contextlevel).'"');
}
-/// Check the cache
- if (isset($context_cache[$contextlevel][$instance])) { // Already cached
- return $context_cache[$contextlevel][$instance];
+ if (!is_array($instance)) {
+ /// Check the cache
+ if (isset($context_cache[$contextlevel][$instance])) { // Already cached
+ return $context_cache[$contextlevel][$instance];
+ }
+
+ /// Get it from the database, or create it
+ if (!$context = get_record('context', 'contextlevel', $contextlevel, 'instanceid', $instance)) {
+ $context = create_context($contextlevel, $instance);
+ }
+
+ /// Only add to cache if context isn't empty.
+ if (!empty($context)) {
+ $context_cache[$contextlevel][$instance] = $context; // Cache it for later
+ $context_cache_id[$context->id] = $context; // Cache it for later
+ }
+
+ return $context;
}
-/// Get it from the database, or create it
- if (!$context = get_record('context', 'contextlevel', $contextlevel, 'instanceid', $instance)) {
- $context = create_context($contextlevel, $instance);
+
+/// ok, somebody wants to load several contexts to save some db queries ;-)
+ $instances = $instance;
+ $result = array();
+
+ foreach ($instances as $key=>$instance) {
+ /// Check the cache first
+ if (isset($context_cache[$contextlevel][$instance])) { // Already cached
+ $result[$instance] = $context_cache[$contextlevel][$instance];
+ unset($instances[$key]);
+ continue;
+ }
}
-/// Only add to cache if context isn't empty.
- if (!empty($context)) {
- $context_cache[$contextlevel][$instance] = $context; // Cache it for later
- $context_cache_id[$context->id] = $context; // Cache it for later
+ if ($instances) {
+ if (count($instances) > 1) {
+ $instanceids = implode(',', $instances);
+ $instanceids = "instanceid IN ($instanceids)";
+ } else {
+ $instance = reset($instances);
+ $instanceids = "instanceid = $instance";
+ }
+
+ if (!$contexts = get_records_sql("SELECT instanceid, id, contextlevel, path, depth
+ FROM {$CFG->prefix}context
+ WHERE contextlevel=$contextlevel AND $instanceids")) {
+ $contexts = array();
+ }
+
+ foreach ($instances as $instance) {
+ if (isset($contexts[$instance])) {
+ $context = $contexts[$instance];
+ } else {
+ $context = create_context($contextlevel, $instance);
+ }
+
+ if (!empty($context)) {
+ $context_cache[$contextlevel][$instance] = $context; // Cache it for later
+ $context_cache_id[$context->id] = $context; // Cache it for later
+ }
+
+ $result[$instance] = $context;
+ }
}
- return $context;
+ return $result;
}
/**
* Get a context instance as an object, from a given context id.
- * @param $id a context id.
- * @return object The context object.
+ * @param mixed $id a context id or array of ids.
+ * @return mixed object or array of the context object.
*/
function get_context_instance_by_id($id) {
diff --git a/lib/grouplib.php b/lib/grouplib.php
index 9c7000eec6682..fa75173ac9019 100644
--- a/lib/grouplib.php
+++ b/lib/grouplib.php
@@ -93,12 +93,12 @@ function groups_get_grouping($groupingid) {
/**
* Gets array of all groups in a specified course.
* @param int $courseid The id of the course.
- * @param int $userid optional user id, returns only groups of the user.
+ * @param mixed $userid optional user id or array of ids, returns only groups of the user.
* @param int $groupingid optional returns only groups in the specified grouping.
* @return array | false Returns an array of the group objects or false if no records
- * or an error occurred.
+ * or an error occurred. (userid field returned if array in $userid)
*/
-function groups_get_all_groups($courseid, $userid=0, $groupingid=0) {
+function groups_get_all_groups($courseid, $userid=0, $groupingid=0, $fields='g.*') {
global $CFG;
// groupings are ignored when not enabled
@@ -106,12 +106,18 @@ function groups_get_all_groups($courseid, $userid=0, $groupingid=0) {
$groupingid = 0;
}
- if (!empty($userid)) {
- $userfrom = ", {$CFG->prefix}groups_members gm";
- $userwhere = "AND g.id = gm.groupid AND gm.userid = '$userid'";
- } else {
+ if (empty($userid)) {
$userfrom = "";
$userwhere = "";
+
+ } else if (is_array($userid)) {
+ $userids = implode(',', $userid);
+ $userfrom = ", {$CFG->prefix}groups_members gm";
+ $userwhere = "AND g.id = gm.groupid AND gm.userid IN ($userids)";
+
+ } else {
+ $userfrom = ", {$CFG->prefix}groups_members gm";
+ $userwhere = "AND g.id = gm.groupid AND gm.userid = '$userid'";
}
if (!empty($groupingid)) {
@@ -122,7 +128,7 @@ function groups_get_all_groups($courseid, $userid=0, $groupingid=0) {
$groupingwhere = "";
}
- return get_records_sql("SELECT g.*
+ return get_records_sql("SELECT $fields
FROM {$CFG->prefix}groups g $userfrom $groupingfrom
WHERE g.courseid = $courseid $userwhere $groupingwhere
ORDER BY name ASC");
diff --git a/message/discussion.php b/message/discussion.php
index bfd4e20574f84..e1cbaca524352 100644
--- a/message/discussion.php
+++ b/message/discussion.php
@@ -124,7 +124,7 @@
print_header(get_string('discussion', 'message').': '.fullname($user), '', '', 'edit-message');
echo ' ';
echo ' ';
- echo print_user_picture($user->id, SITEID, $user->picture, 48, true, true, 'userwindow');
+ echo print_user_picture($user, SITEID, $user->picture, 48, true, true, 'userwindow');
echo ' '.$userfullname.'
|