Skip to content

Commit

Permalink
MDL-12945 changing get_fast_modinfo() section property to sectionnum …
Browse files Browse the repository at this point in the history
…to prevent conflicts with real cm->section; full recent activity speedup when printing user pictures in forum; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Feb 1, 2008
1 parent 2fc1fd5 commit 76cbde4
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 57 deletions.
9 changes: 5 additions & 4 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ function &get_fast_modinfo(&$course, $userid=0) {
$cm->modname = $mod->mod;
$cm->name = urldecode($mod->name);
$cm->visible = $mod->visible;
$cm->section = $mod->section;
$cm->sectionnum = $mod->section;
$cm->groupmode = $mod->groupmode;
$cm->groupingid = $mod->groupingid;
$cm->groupmembersonly = $mod->groupmembersonly;
Expand Down Expand Up @@ -1117,14 +1117,15 @@ function &get_fast_modinfo(&$course, $userid=0) {
$modinfo->cms[$cm->id] =& $cm;

// reconstruct sections
if (!isset($modinfo->sections[$cm->section])) {
$modinfo->sections[$cm->section] = array();
if (!isset($modinfo->sections[$cm->sectionnum])) {
$modinfo->sections[$cm->sectionnum] = array();
}
$modinfo->sections[$cm->section][] = $cm->id;
$modinfo->sections[$cm->sectionnum][] = $cm->id;

unset($cm);
}

unset($cache[$course->id]); // prevent potential reference problems when switching users
$cache[$course->id] = $modinfo;

return $cache[$course->id];
Expand Down
10 changes: 8 additions & 2 deletions course/recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
}

} else if (is_numeric($param->modid)) {
$section = $sections[$modinfo->cms[$param->modid]->section];
$section = $sections[$modinfo->cms[$param->modid]->sectionnum];
$section->sequence = $param->modid;
$sections = array($section->sequence=>$section);
}
Expand Down Expand Up @@ -186,6 +186,7 @@
$section = 0;

$activity_count = count($activities);
$viewfullnames = array();

foreach ($activities as $key => $activity) {

Expand Down Expand Up @@ -228,6 +229,11 @@

} else {

if (!isset($viewfullnames[$activity->cmid])) {
$cm_context = get_context_instance(CONTEXT_MODULE, $activity->cmid);
$viewfullnames[$activity->cmid] = has_capability('moodle/site:viewfullnames', $cm_context);
}

if (!$inbox) {
print_simple_box_start('center', '90%');
$inbox = true;
Expand All @@ -236,7 +242,7 @@
$print_recent_mod_activity = $activity->type.'_print_recent_mod_activity';

if (function_exists($print_recent_mod_activity)) {
$print_recent_mod_activity($activity, $course->id, $detail, $modnames);
$print_recent_mod_activity($activity, $course->id, $detail, $modnames, $viewfullnames[$activity->cmid]);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5276,30 +5276,30 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
continue;
}

if ($mod->section > $course->numsections) { /// Don't show excess hidden sections
if ($mod->sectionnum > $course->numsections) { /// Don't show excess hidden sections
break;
}

if (!$mod->uservisible) { // do not icnlude empty sections at all
continue;
}

if ($mod->section > 0 and $section != $mod->section) {
$thissection = $sections[$mod->section];
if ($mod->sectionnum > 0 and $section != $mod->sectionnum) {
$thissection = $sections[$mod->sectionnum];

if ($thissection->visible or !$course->hiddensections or
has_capability('moodle/course:viewhiddensections', $context)) {
$thissection->summary = strip_tags(format_string($thissection->summary,true));
if ($course->format == 'weeks' or empty($thissection->summary)) {
$menu[] = '--'.$strsection ." ". $mod->section;
$menu[] = '--'.$strsection ." ". $mod->sectionnum;
} else {
if (strlen($thissection->summary) < ($width-3)) {
$menu[] = '--'.$thissection->summary;
} else {
$menu[] = '--'.substr($thissection->summary, 0, $width).'...';
}
}
$section = $mod->section;
$section = $mod->sectionnum;
} else {
// no activities from this hidden section shown
continue;
Expand Down Expand Up @@ -5396,16 +5396,16 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
continue;
}

if ($mod->section > $course->numsections) { /// Don't show excess hidden sections
if ($mod->sectionnum > $course->numsections) { /// Don't show excess hidden sections
break;
}

if (!$mod->uservisible) { // do not icnlude empty sections at all
continue;
}

if ($mod->section >= 0 and $section != $mod->section) {
$thissection = $sections[$mod->section];
if ($mod->sectionnum >= 0 and $section != $mod->sectionnum) {
$thissection = $sections[$mod->sectionnum];

if ($thissection->visible or !$course->hiddensections or
has_capability('moodle/course:viewhiddensections', $coursecontext)) {
Expand All @@ -5414,7 +5414,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
$menu[] = '</ul></li>';
}
if ($course->format == 'weeks' or empty($thissection->summary)) {
$item = $strsection ." ". $mod->section;
$item = $strsection ." ". $mod->sectionnum;
} else {
if (strlen($thissection->summary) < ($width-3)) {
$item = $thissection->summary;
Expand All @@ -5426,7 +5426,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
$menu[] = '<ul>';
$doneheading = true;

$section = $mod->section;
$section = $mod->sectionnum;
} else {
// no activities from this hidden section shown
continue;
Expand Down
8 changes: 4 additions & 4 deletions mod/assignment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";

$printsection = "";
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}

if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php')) {
Expand Down
2 changes: 1 addition & 1 deletion mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ function assignment_get_recent_mod_activity(&$activities, &$index, $timestart, $
$tmpactivity->type = 'assignment';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->section = $cm->section;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $submission->timemodified;

if ($grader) {
Expand Down
8 changes: 4 additions & 4 deletions mod/chat/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";

$printsection = '';
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array ($printsection, $link);
Expand Down
8 changes: 4 additions & 4 deletions mod/choice/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
}

$printsection = "";
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}

$class = $cm->visible ? '' : 'class="dimmed"';
Expand Down
8 changes: 4 additions & 4 deletions mod/data/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@
}

if ($course->format == 'weeks' or $course->format == 'topics') {
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}
$row = array ($printsection, $link, $cm->intro, $numrecords, $numunapprovedrecords);

Expand Down
25 changes: 15 additions & 10 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4173,7 +4173,7 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours

if (!$posts = get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
d.timestart, d.timeend, d.userid AS duserid,
u.firstname, u.lastname, u.email, u.picture
u.firstname, u.lastname, u.email, u.picture, u.imagealt
FROM {$CFG->prefix}forum_posts p
JOIN {$CFG->prefix}forum_discussions d ON d.id = p.discussion
JOIN {$CFG->prefix}forum f ON f.id = d.forum
Expand All @@ -4189,7 +4189,6 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$viewhiddentimed = has_capability('mod/forum:viewhiddentimedposts', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);

if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
Expand Down Expand Up @@ -4236,17 +4235,22 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
$tmpactivity->type = 'forum';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->section = $cm->section;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $post->modified;

$tmpactivity->content = new object();
$tmpactivity->content->id = $post->id;
$tmpactivity->content->discussion = $post->discussion;
$tmpactivity->content->subject = format_string($post->subject);
$tmpactivity->content->parent = $post->parent;

$tmpactivity->user->userid = $post->userid;
$tmpactivity->user->fullname = fullname($post, $viewfullnames);
$tmpactivity->user->picture = $post->picture;
$tmpactivity->user = new object();
$tmpactivity->user->id = $post->userid;
$tmpactivity->user->firstname = $post->firstname;
$tmpactivity->user->lastname = $post->lastname;
$tmpactivity->user->picture = $post->picture;
$tmpactivity->user->imagealt = $post->imagealt;
$tmpactivity->user->email = $post->email;

$activities[$index++] = $tmpactivity;
}
Expand All @@ -4257,7 +4261,7 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
/**
*
*/
function forum_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
function forum_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) {
global $CFG;

if ($activity->content->parent) {
Expand All @@ -4269,7 +4273,7 @@ function forum_print_recent_mod_activity($activity, $courseid, $detail, $modname
echo '<table border="0" cellpadding="3" cellspacing="0" class="forum-recent">';

echo "<tr><td class=\"userpicture\" valign=\"top\">";
print_user_picture($activity->user->userid, $courseid, $activity->user->picture);
print_user_picture($activity->user, $courseid);
echo "</td><td class=\"$class\">";

echo '<div class="title">';
Expand All @@ -4283,8 +4287,9 @@ function forum_print_recent_mod_activity($activity, $courseid, $detail, $modname
echo '</div>';

echo '<div class="user">';
echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->userid}&amp;course=$courseid\">"
."{$activity->user->fullname}</a> - ".userdate($activity->timestamp);
$fullname = fullname($activity->user, $viewfullnames);
echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->id}&amp;course=$courseid\">"
."{$fullname}</a> - ".userdate($activity->timestamp);
echo '</div>';
echo "</td></tr></table>";

Expand Down
8 changes: 4 additions & 4 deletions mod/glossary/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";

$printsection = "";
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}

// TODO: count only approved if not allowed to see them
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $course
$tmpactivity->type = 'quiz';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->section = $cm->section;
$tmpactivity->sectionnum= $cm->sectionnum;
$tmpactivity->timestamp = $attempt->timefinish;

$tmpactivity->content->attemptid = $attempt->id;
Expand Down
8 changes: 4 additions & 4 deletions mod/resource/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@

if ($course->format == "weeks" or $course->format == "topics") {
$printsection = "";
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($cm->timemodified)."</span>";
Expand Down
8 changes: 4 additions & 4 deletions mod/survey/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
$ss = $strnotdone;
}
$printsection = "";
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
if ($cm->sectionnum !== $currentsection) {
if ($cm->sectionnum) {
$printsection = $cm->sectionnum;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $cm->section;
$currentsection = $cm->sectionnum;
}
//Calculate the href
$class = $cm->visible ? '' : 'class="dimmed"';
Expand Down
2 changes: 1 addition & 1 deletion mod/wiki/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
$wtype = '<span class="smallinfo">'.$wtype.'</span>';

if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($cm->section, $link, $summary, $wtype, $timmod);
$table->data[] = array ($cm->sectionnum, $link, $summary, $wtype, $timmod);
} else {
$table->data[] = array ($link, $summary, $wtype, $timmod);
}
Expand Down

0 comments on commit 76cbde4

Please sign in to comment.