Skip to content

Commit

Permalink
MDL-12945 a slightly bigger patch for performance in recent activity …
Browse files Browse the repository at this point in the history
…and various group related issues + some other fixes - see list of subtasks in tracker; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Jan 24, 2008
1 parent d20737e commit dd97c32
Show file tree
Hide file tree
Showing 63 changed files with 2,294 additions and 1,897 deletions.
46 changes: 25 additions & 21 deletions blocks/activity_modules/block_activity_modules.php
Expand Up @@ -7,21 +7,7 @@ function init() {
}

function get_content() {
global $USER, $CFG;

// TODO: FIX: HACK: (any other tags I should add? :P)
// Hacker's improvised caching scheme: avoid fetching the mod
// data from db if the course format has already fetched them
if(!isset($GLOBALS['modnamesplural']) || !isset($GLOBALS['modnamesused'])) {
require_once($CFG->dirroot.'/course/lib.php');
if (!empty($this->instance)) {
get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
}
}
else {
$modnamesplural = $GLOBALS['modnamesplural'];
$modnamesused = $GLOBALS['modnamesused'];
}
global $CFG, $COURSE;

if($this->content !== NULL) {
return $this->content;
Expand All @@ -32,12 +18,30 @@ function get_content() {
$this->content->icons = array();
$this->content->footer = '';

if (isset($modnamesused) && $modnamesused) {
foreach ($modnamesused as $modname => $modfullname) {
if ($modname != 'label') {
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->instance->pageid.'">'.$modnamesplural[$modname].'</a>';
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" class="icon" alt="" />';
}
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}

require_once($CFG->dirroot.'/course/lib.php');

$modinfo = get_fast_modinfo($course);
$modfullanmes = array();

foreach($modinfo->cms as $cm) {
if (!$cm->uservisible) {
continue;
}
$modfullnames[$cm->modname] = $cm->modplural;
}

asort($modfullnames, SORT_LOCALE_STRING);

foreach ($modfullnames as $modname => $modfullname) {
if ($modname != 'label') {
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->instance->pageid.'">'.$modfullname.'</a>';
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" class="icon" alt="" />';
}
}

Expand Down
38 changes: 21 additions & 17 deletions blocks/admin/block_admin.php
Expand Up @@ -49,7 +49,7 @@ function get_content() {

/// Course editing on/off

if (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
if (isediting($this->instance->pageid)) {
$this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
Expand All @@ -63,32 +63,36 @@ function get_content() {

/// Assign roles to the course

if (has_capability('moodle/role:assign', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/role:assign', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';

}

/// View course grades (or just your own grades, same link)
/// find all accessible reports
if ($course->id!==SITEID) {
if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
foreach ($reports as $key => $plugin) { // Remove ones we can't see
if (!has_capability('gradereport/'.$plugin.':view', $context)) {
unset($reports[$key]);
if ($course->id !== SITEID) {
$reportavailable = false;
if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
arsort($reports); // user is last, we want to test it first
foreach ($reports as $plugin) {
if (has_capability('gradereport/'.$plugin.':view', $context)) {
//stop when fisrt visible found
$reportavailable = true;
break;
}
}
}

if (!empty($reports)) {
if ($reportavailable) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$this->instance->pageid.'">'.get_string('grades').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />';
}
}

/// Course outcomes (to help give it more prominence because it's important)
if (!empty($CFG->enableoutcomes)) {
if (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
if ($course->id!==SITEID and has_capability('moodle/course:update', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="" />';
}
Expand All @@ -110,45 +114,45 @@ function get_content() {

/// Manage groups in this course

if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context) && ($course->id!==SITEID)) {
if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
$strgroups = get_string('groups');
$this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
}

/// Backup this course

if (has_capability('moodle/site:backup', $context)&& ($course->id!==SITEID)) {
if ($course->id!==SITEID and has_capability('moodle/site:backup', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
}

/// Restore to this course
if (has_capability('moodle/site:restore', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
}

/// Import data from other courses
if (has_capability('moodle/site:import', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('import').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
}

/// Reset this course
if (has_capability('moodle/course:reset', $context) && ($course->id!==SITEID)) {
if ($course->id!==SITEID and has_capability('moodle/course:reset', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$this->instance->pageid.'">'.get_string('reset').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/return.gif" class="icon" alt="" />';
}

/// View course reports
if (has_capability('moodle/site:viewreports', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$this->instance->pageid.'">'.get_string('reports').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/stats.gif" class="icon" alt="" />';
}

/// Manage questions
if ($course->id!==SITEID){
if ($course->id !== SITEID){
$questionlink = '';
$questioncaps = array(
'moodle/question:add',
Expand Down Expand Up @@ -176,7 +180,7 @@ function get_content() {


/// Manage files
if (has_capability('moodle/course:managefiles', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.get_string('files').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" class="icon" alt="" />';
}
Expand Down
15 changes: 8 additions & 7 deletions blocks/calendar_month/block_calendar_month.php
Expand Up @@ -20,8 +20,8 @@ function get_content() {
if ($this->content !== NULL) {
return $this->content;
}
// Initialize the session variables
calendar_session_vars();
// Reset the session variables
calendar_session_vars($COURSE);

$this->content = new stdClass;
$this->content->text = '';
Expand All @@ -35,11 +35,12 @@ function get_content() {
if($courseshown == SITEID) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
// the list of courses it will be grabbing events from.
$filtercourse = NULL;
}
else {
$filtercourse = NULL;
$groupeventsfrom = NULL;
} else {
// Forcibly filter events to include only those from the particular course we are in.
$filtercourse = array($courseshown => 1);
$filtercourse = array($courseshown => $COURSE);
$groupeventsfrom = array($courseshown => 1);
}

// We 'll need this later
Expand All @@ -53,7 +54,7 @@ function get_content() {

// Be VERY careful with the format for default courses arguments!
// Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
calendar_set_filters($courses, $group, $user, $filtercourse, $filtercourse);
calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
if ($courseshown == SITEID) {
// For the front page
$this->content->text .= calendar_overlib_html();
Expand Down
12 changes: 7 additions & 5 deletions blocks/calendar_upcoming/block_calendar_upcoming.php
Expand Up @@ -16,8 +16,8 @@ function get_content() {
if ($this->content !== NULL) {
return $this->content;
}
// Initialize the session variables
calendar_session_vars();
// Reset the session variables
calendar_session_vars($COURSE);
$this->content = new stdClass;
$this->content->text = '';

Expand All @@ -42,10 +42,12 @@ function get_content() {
if ($courseshown == SITEID) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
// the list of courses it will be grabbing events from.
$filtercourse = NULL;
$filtercourse = NULL;
$groupeventsfrom = NULL;
} else {
// Forcibly filter events to include only those from the particular course we are in.
$filtercourse = array($courseshown => 1);
$filtercourse = array($courseshown => $COURSE);
$groupeventsfrom = array($courseshown => 1);
}
}

Expand All @@ -55,7 +57,7 @@ function get_content() {
// Be VERY careful with the format for default courses arguments!
// Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.

calendar_set_filters($courses, $group, $user, $filtercourse, $filtercourse, false);
calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
$events = calendar_get_upcoming($courses, $group, $user,
get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS),
get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
Expand Down
6 changes: 6 additions & 0 deletions blocks/course_list/block_course_list.php
Expand Up @@ -110,6 +110,12 @@ function get_content() {

function get_remote_courses() {
global $THEME, $CFG, $USER;

if (!is_enabled_auth('mnet')) {
// no need to query anything remote related
return;
}

$icon = '<img src="'.$CFG->pixpath.'/i/mnethost.gif" class="icon" alt="'.get_string('course').'" />';

// only for logged in users!
Expand Down
5 changes: 3 additions & 2 deletions blocks/course_summary/block_course_summary.php
Expand Up @@ -24,10 +24,11 @@ function get_content() {
return '';
}

$this->content = New stdClass;
$this->content = new object();
$options = new object();
$options->noclean = true; // Don't clean Javascripts etc
$this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
if(isediting($COURSE->id)) {
if (isediting($COURSE->id)) { // ?? courseid param not there??
if($COURSE->id == SITEID) {
$editpage = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=frontpagesettings';
} else {
Expand Down
7 changes: 2 additions & 5 deletions blocks/glossary_random/block_glossary_random.php
Expand Up @@ -189,13 +189,10 @@ function get_content() {

// place link to glossary in the footer if the glossary is visible

//Create a temp valid module structure (course,id)
$tempmod->course = $this->course->id;
$tempmod->id = $glossaryid;
$cm = get_coursemodule_from_instance('glossary',$glossaryid, $this->course->id) ;

//Obtain the visible property from the instance
if (instance_is_visible('glossary', $tempmod)) {
$cm = get_coursemodule_from_instance('glossary',$glossaryid, $this->course->id) ;
if (coursemodule_visible_for_user($cm)) {
if (has_capability('mod/glossary:write', get_context_instance(CONTEXT_MODULE, $cm->id))) {
$this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/glossary/edit.php?id='.$cm->id
.'" title="'.$this->config->addentry.'">'.$this->config->addentry.'</a><br />';
Expand Down
5 changes: 5 additions & 0 deletions blocks/mnet_hosts/block_mnet_hosts.php
Expand Up @@ -26,6 +26,11 @@ function get_content() {
return false;
}

if (!is_enabled_auth('mnet')) {
// no need to query anything remote related
return '';
}

// check for outgoing roaming permission first
if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
return '';
Expand Down
4 changes: 3 additions & 1 deletion blocks/news_items/block_news_items.php
Expand Up @@ -32,9 +32,11 @@ function get_content() {
return '';
}

if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $COURSE->id)) {
$modinfo = get_fast_modinfo($COURSE);
if (empty($modinfo->instances['forum'][$forum->id])) {
return '';
}
$cm = $modinfo->instances['forum'][$forum->id];

$context = get_context_instance(CONTEXT_MODULE, $cm->id);

Expand Down
29 changes: 16 additions & 13 deletions blocks/online_users/block_online_users.php
Expand Up @@ -83,23 +83,26 @@ function get_content() {
$pcontext = get_related_contexts_string($context);

if ($pusers = get_records_sql($SQL, 0, 50)) { // We'll just take the most recent 50 maximum
foreach ($pusers as $puser) {

$hidden = false;

if (!has_capability('moodle/role:viewhiddenassigns', $context)) {
// if current user can't view hidden role assignment in this context and
// user has a hidden role assigned at this context or any parent contexts,
// ignore this user

$SQL = "SELECT id FROM {$CFG->prefix}role_assignments
WHERE userid = $puser->id
AND contextid $pcontext
AND hidden = 1";

if (!has_capability('moodle/role:viewhiddenassigns', $context) && record_exists_sql($SQL)) {
// can't see this user as the current user has no capability
// and this user has a hidden assignment at this context or higher
continue;
$userids = array_keys($pusers);
$userids = implode(',', $userids);
$sql = "SELECT userid
FROM {$CFG->prefix}role_assignments
WHERE userid IN ($userids) AND contextid $pcontext AND hidden = 1
GROUP BY userid";
$hidden = get_records_sql($sql);
}

foreach ($pusers as $puser) {
if ($hidden and isset($hidden[$puser->id])) {
continue;
}

$puser->fullname = fullname($puser);
$users[$puser->id] = $puser;
}
Expand Down

0 comments on commit dd97c32

Please sign in to comment.