Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'w07_MDL-23939_20_completeuser' of git://github.com/skod…

…ak/moodle
  • Loading branch information...
commit 0dd8cb88e9993bf3e024327c272a9a257b4f4cd7 2 parents 76b7e2d + 4f97de7
@stronk7 stronk7 authored
View
6 course/format/topics/format.php
@@ -35,11 +35,7 @@
if ($topic != -1) {
$displaysection = course_set_display($course->id, $topic);
} else {
- if (isset($USER->display[$course->id])) {
- $displaysection = $USER->display[$course->id];
- } else {
- $displaysection = course_set_display($course->id, 0);
- }
+ $displaysection = course_get_display($course->id);
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
View
6 course/format/weeks/format.php
@@ -34,11 +34,7 @@
if ($week != -1) {
$displaysection = course_set_display($course->id, $week);
} else {
- if (isset($USER->display[$course->id])) {
- $displaysection = $USER->display[$course->id];
- } else {
- $displaysection = course_set_display($course->id, 0);
- }
+ $displaysection = course_get_display($course->id);
}
$streditsummary = get_string('editsummary');
View
69 course/lib.php
@@ -1239,26 +1239,71 @@ function get_all_sections($courseid) {
return $coursesections[$courseid];
}
-function course_set_display($courseid, $display=0) {
+/**
+ * Returns the course section to display or 0 meaning show all sections. Returns 0 for guests.
+ * It also sets the $USER->display cache to array($courseid=>return value)
+ *
+ * @param int $courseid The course id
+ * @return int Course section to display, 0 means all
+ */
+function course_get_display($courseid) {
+ global $USER, $DB;
+
+ if (!isloggedin() or isguestuser()) {
+ //do not get settings in db for guests
+ return 0; //return the implicit setting
+ }
+
+ if (!isset($USER->display[$courseid])) {
+ if (!$display = $DB->get_field('course_display', 'display', array('userid' => $USER->id, 'course'=>$courseid))) {
+ $display = 0; // all sections option is not stored in DB, this makes the table much smaller
+ }
+ //use display cache for one course only - we need to keep session small
+ $USER->display = array($courseid => $display);
+ }
+
+ return $USER->display[$courseid];
+}
+
+/**
+ * Show one section only or all sections.
+ *
+ * @param int $courseid The course id
+ * @param mixed $display show only this section, 0 or 'all' means show all sections
+ * @return int Course section to display, 0 means all
+ */
+function course_set_display($courseid, $display) {
global $USER, $DB;
- if ($display == "all" or empty($display)) {
+ if ($display === 'all' or empty($display)) {
$display = 0;
}
if (!isloggedin() or isguestuser()) {
//do not store settings in db for guests
- } else if ($DB->record_exists("course_display", array("userid" => $USER->id, "course"=>$courseid))) {
- $DB->set_field("course_display", "display", $display, array("userid"=>$USER->id, "course"=>$courseid));
+ return 0;
+ }
+
+ if ($display == 0) {
+ //show all, do not store anything in database
+ $DB->delete_records('course_display', array('userid' => $USER->id, 'course' => $courseid));
+
} else {
- $record = new stdClass();
- $record->userid = $USER->id;
- $record->course = $courseid;
- $record->display = $display;
- $DB->insert_record("course_display", $record);
+ if ($DB->record_exists('course_display', array('userid' => $USER->id, 'course' => $courseid))) {
+ $DB->set_field('course_display', 'display', $display, array('userid' => $USER->id, 'course' => $courseid));
+ } else {
+ $record = new stdClass();
+ $record->userid = $USER->id;
+ $record->course = $courseid;
+ $record->display = $display;
+ $DB->insert_record('course_display', $record);
+ }
}
- return $USER->display[$courseid] = $display; // Note: = not ==
+ //use display cache for one course only - we need to keep session small
+ $USER->display = array($courseid => $display);
+
+ return $display;
}
/**
@@ -2837,7 +2882,7 @@ function move_section($course, $section, $move) {
$DB->set_field("course_sections", "section", $section, array("id"=>$sectiondestrecord->id));
// if the focus is on the section that is being moved, then move the focus along
- if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) {
+ if (course_get_display($course->id) == $section) {
course_set_display($course->id, $sectiondest);
}
@@ -2890,7 +2935,7 @@ function move_section_to($course, $section, $destination) {
}
// if the focus is on the section that is being moved, then move the focus along
- if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) {
+ if (course_get_display($course->id) == $section) {
course_set_display($course->id, $destination);
}
return true;
View
5 lib/db/upgrade.php
@@ -6023,6 +6023,11 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011020200.01);
}
+ if ($oldversion < 2011020900.07) {
+ $DB->delete_records('course_display', array('display' => 0));
+ upgrade_main_savepoint(true, 2011020900.07);
+ }
+
return true;
}
View
25 lib/moodlelib.php
@@ -3784,12 +3784,6 @@ function get_complete_user_data($field, $value, $mnethostid = null) {
/// Get various settings and preferences
- if ($displays = $DB->get_records('course_display', array('userid'=>$user->id))) {
- foreach ($displays as $display) {
- $user->display[$display->course] = $display->display;
- }
- }
-
// preload preference cache
check_user_preferences_loaded($user);
@@ -3808,18 +3802,23 @@ function get_complete_user_data($field, $value, $mnethostid = null) {
// this is a special hack to speedup calendar display
$user->groupmember = array();
- if ($groups = $DB->get_records_sql($sql, array($user->id))) {
- foreach ($groups as $group) {
- if (!array_key_exists($group->courseid, $user->groupmember)) {
- $user->groupmember[$group->courseid] = array();
+ if (!isguestuser($user)) {
+ if ($groups = $DB->get_records_sql($sql, array($user->id))) {
+ foreach ($groups as $group) {
+ if (!array_key_exists($group->courseid, $user->groupmember)) {
+ $user->groupmember[$group->courseid] = array();
+ }
+ $user->groupmember[$group->courseid][$group->id] = $group->id;
}
- $user->groupmember[$group->courseid][$group->id] = $group->id;
}
}
/// Add the custom profile fields to the user record
- require_once($CFG->dirroot.'/user/profile/lib.php');
- profile_load_custom_fields($user);
+ $user->profile = array();
+ if (!isguestuser($user)) {
+ require_once($CFG->dirroot.'/user/profile/lib.php');
+ profile_load_custom_fields($user);
+ }
/// Rewrite some variables if necessary
if (!empty($user->description)) {
View
8 lib/navigationlib.php
@@ -1384,11 +1384,7 @@ public function load_generic_course_sections(stdClass $course, navigation_node $
$viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context);
- if (isloggedin() && !isguestuser()) {
- $activesection = $DB->get_field("course_display", "display", array("userid"=>$USER->id, "course"=>$course->id));
- } else {
- $activesection = null;
- }
+ $activesection = course_get_display($course->id);
$namingfunction = 'callback_'.$courseformat.'_get_section_name';
$namingfunctionexists = (function_exists($namingfunction));
@@ -1418,7 +1414,7 @@ public function load_generic_course_sections(stdClass $course, navigation_node $
$sectionnode = $coursenode->add($sectionname, $url, navigation_node::TYPE_SECTION, null, $section->id);
$sectionnode->nodetype = navigation_node::NODETYPE_BRANCH;
$sectionnode->hidden = (!$section->visible);
- if ($this->page->context->contextlevel != CONTEXT_MODULE && ($sectionnode->isactive || ($activesection != null && $section->section == $activesection))) {
+ if ($this->page->context->contextlevel != CONTEXT_MODULE && ($sectionnode->isactive || ($activesection && $section->section == $activesection))) {
$sectionnode->force_open();
$this->load_section_activities($sectionnode, $section->section, $modinfo);
}
View
2  version.php
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2011020900; // YYYYMMDD = date of the last version bump
+$version = 2011020900.07; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0.1+ (Build: 20110209)'; // Human-friendly version name
Please sign in to comment.
Something went wrong with that request. Please try again.