}
$mnethostlogssql = "
SELECT
- mhostlogs.remoteid, mhostlogs.time, mhostlogs.userid, mhostlogs.ip,
- mhostlogs.course, mhostlogs.module, mhostlogs.cmid, mhostlogs.action,
- mhostlogs.url, mhostlogs.info, mhostlogs.username, c.fullname as coursename,
- c.modinfo
+ l.id as remoteid, l.time, l.userid, l.ip, l.course, l.module, l.cmid,
+ l.action, l.url, l.info, u.username
FROM
- (
- SELECT
- l.id as remoteid, l.time, l.userid, l.ip, l.course, l.module, l.cmid,
- l.action, l.url, l.info, u.username
- FROM
- {user} u
- INNER JOIN {log} l on l.userid = u.id
- WHERE
- u.mnethostid = ?
- AND l.id > ?
- ORDER BY remoteid ASC
- LIMIT 500
- ) mhostlogs
- INNER JOIN {course} c on c.id = mhostlogs.course
- ORDER by mhostlogs.remoteid ASC";
+ {user} u
+ INNER JOIN {log} l on l.userid = u.id
+ WHERE
+ u.mnethostid = ?
+ AND l.id > ?
+ AND l.course IS NOT NULL
+ ORDER by l.id ASC
+ LIMIT 500";
$mnethostlogs = $DB->get_records_sql($mnethostlogssql, array($mnethostid, $mnet_request->response['last log id']));
$processedlogs = array();
foreach($mnethostlogs as $hostlog) {
- // Extract the name of the relevant module instance from the
- // course modinfo if possible.
- if (!empty($hostlog->modinfo) && !empty($hostlog->cmid)) {
- $modinfo = unserialize($hostlog->modinfo);
- unset($hostlog->modinfo);
- $modulearray = array();
- foreach($modinfo as $module) {
- $modulearray[$module->cm] = $module->name;
+ try {
+ // Get impersonalised course information. If it is cached there will be no DB queries.
+ $modinfo = get_fast_modinfo($hostlog->course, -1);
+ $hostlog->coursename = $modinfo->get_course()->fullname;
+ if (!empty($hostlog->cmid) && isset($modinfo->cms[$hostlog->cmid])) {
+ $hostlog->resource_name = $modinfo->cms[$hostlog->cmid]->name;
+ } else {
+ $hostlog->resource_name = '';
}
- $hostlog->resource_name = $modulearray[$hostlog->cmid];
- } else {
- $hostlog->resource_name = '';
+ } catch (moodle_exception $e) {
+ // Course not found
+ continue;
}
$processedlogs[] = array (
*/
private function obtain_dynamic_data() {
global $CFG;
- if ($this->state >= self::STATE_BUILDING_DYNAMIC) {
+ $userid = $this->modinfo->get_user_id();
+ if ($this->state >= self::STATE_BUILDING_DYNAMIC || $userid == -1) {
return;
}
$this->state = self::STATE_BUILDING_DYNAMIC;
- $userid = $this->modinfo->get_user_id();
if (!empty($CFG->enableavailability)) {
require_once($CFG->libdir. '/conditionlib.php');
*/
private function update_user_visible() {
$userid = $this->modinfo->get_user_id();
+ if ($userid == -1) {
+ return null;
+ }
$this->uservisible = true;
// If the user cannot access the activity set the uservisible flag to false.
if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly)) {
$userid = $this->modinfo->get_user_id();
+ if ($userid == -1) {
+ return null;
+ }
if (!has_capability('moodle/site:accessallgroups', $this->get_context(), $userid)) {
// If the activity has 'group members only' and you don't have accessallgroups...
$groups = $this->modinfo->get_groups($this->groupingid);
* @return bool True if the user access is restricted.
*/
public function is_user_access_restricted_by_capability() {
+ $userid = $this->modinfo->get_user_id();
+ if ($userid == -1) {
+ return null;
+ }
$capability = 'mod/' . $this->modname . ':view';
$capabilityinfo = get_capability_info($capability);
if (!$capabilityinfo) {
}
// You are blocked if you don't have the capability.
- $userid = $this->modinfo->get_user_id();
return !has_capability($capability, $this->get_context(), $userid);
}
return false;
}
- require_once($CFG->libdir. '/conditionlib.php');
+ $userid = $this->modinfo->get_user_id();
+ if ($userid == -1) {
+ return null;
+ }
// If module will always be visible anyway (but greyed out), don't bother checking anything else
if ($this->get_show_availability() == CONDITION_STUDENTVIEW_SHOW) {
}
// Can the user see hidden modules?
- $userid = $this->modinfo->get_user_id();
if (has_capability('moodle/course:viewhiddenactivities', $this->get_context(), $userid)) {
return false;
}
* @return void
*/
private function obtain_view_data() {
- if ($this->state >= self::STATE_BUILDING_VIEW) {
+ if ($this->state >= self::STATE_BUILDING_VIEW || $this->modinfo->get_user_id() == -1) {
return;
}
$this->obtain_dynamic_data();
* and recommended to have field 'cacherev') or just a course id. Just course id
* is enough when calling get_fast_modinfo() for current course or site or when
* calling for any other course for the second time.
- * @param int $userid User id to populate 'uservisible' attributes of modules and sections.
- * Set to 0 for current user (default)
+ * @param int $userid User id to populate 'availble' and 'uservisible' attributes of modules and sections.
+ * Set to 0 for current user (default). Set to -1 to avoid calculation of dynamic user-depended data.
* @param bool $resetonly whether we want to get modinfo or just reset the cache
* @return course_modinfo|null Module information for course, or null if resetting
* @throws moodle_exception when course is not found (nothing is thrown if resetting)
*/
private function get_available() {
global $CFG;
- if ($this->_available !== null) {
- // Has already been calculated.
+ $userid = $this->modinfo->get_user_id();
+ if ($this->_available !== null || $userid == -1) {
+ // Has already been calculated or does not need calculation.
return $this->_available;
}
if (!empty($CFG->enableavailability)) {
// Get availability information
$ci = new condition_info_section($this);
$this->_available = $ci->is_available($this->_availableinfo, true,
- $this->modinfo->get_user_id(), $this->modinfo);
+ $userid, $this->modinfo);
if ($this->_availableinfo === '' && $this->_groupingid) {
// Still may have some extra text in availableinfo because of groupping.
// Set as undefined so the next call to get_availabeinfo() calculates it.
private function get_availableinfo() {
// Make sure $this->_available has been calculated, it may also fill the _availableinfo property.
$this->get_available();
- if ($this->_availableinfo !== null) {
- // It has been already calculated.
+ $userid = $this->modinfo->get_user_id();
+ if ($this->_availableinfo !== null || $userid == -1) {
+ // It has been already calculated or does not need calculation.
return $this->_availableinfo;
}
$this->_availableinfo = '';
// for people with managegroups - same logic/class as grouping label
// on individual activities.
$context = context_course::instance($this->get_course());
- $userid = $this->modinfo->get_user_id();
if ($this->_groupingid && has_capability('moodle/course:managegroups', $context, $userid)) {
$groupings = groups_get_all_groupings($this->get_course());
$this->_availableinfo = html_writer::tag('span', '(' . format_string(
* @return bool
*/
private function get_uservisible() {
- if ($this->_uservisible !== null) {
- // Has already been calculated.
+ $userid = $this->modinfo->get_user_id();
+ if ($this->_uservisible !== null || $userid == -1) {
+ // Has already been calculated or does not need calculation.
return $this->_uservisible;
}
$this->_uservisible = true;
if (!$this->_visible || !$this->get_available()) {
$coursecontext = context_course::instance($this->get_course());
- $userid = $this->modinfo->get_user_id();
if (!has_capability('moodle/course:viewhiddensections', $coursecontext, $userid)) {
$this->_uservisible = false;
}