コード例 #1
0
 /**
  * Returns all recent enrollments
  *
  * @todo MDL-36993 this function always return empty array
  * @return array array of entries from {user} table
  */
 protected function get_recent_enrolments()
 {
     return get_recent_enrolments($this->page->course->id, $this->get_timestart());
 }
コード例 #2
0
ファイル: lib.php プロジェクト: numbas/moodle
/**
 * This function trawls through the logs looking for
 * anything new since the user's last login
 */
function print_recent_activity($course)
{
    // $course is an object
    global $CFG, $USER, $SESSION, $DB, $OUTPUT;
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
    $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2);
    // better db caching for guests - 100 seconds
    if (!isguestuser()) {
        if (!empty($USER->lastcourseaccess[$course->id])) {
            if ($USER->lastcourseaccess[$course->id] > $timestart) {
                $timestart = $USER->lastcourseaccess[$course->id];
            }
        }
    }
    echo '<div class="activitydate">';
    echo get_string('activitysince', '', userdate($timestart));
    echo '</div>';
    echo '<div class="activityhead">';
    echo '<a href="' . $CFG->wwwroot . '/course/recent.php?id=' . $course->id . '">' . get_string('recentactivityreport') . '</a>';
    echo "</div>\n";
    $content = false;
    /// Firstly, have there been any new enrolments?
    $users = get_recent_enrolments($course->id, $timestart);
    //Accessibility: new users now appear in an <OL> list.
    if ($users) {
        echo '<div class="newusers">';
        echo $OUTPUT->heading(get_string("newusers") . ':', 3);
        $content = true;
        echo "<ol class=\"list\">\n";
        foreach ($users as $user) {
            $fullname = fullname($user, $viewfullnames);
            echo '<li class="name"><a href="' . "{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$course->id}\">{$fullname}</a></li>\n";
        }
        echo "</ol>\n</div>\n";
    }
    /// Next, have there been any modifications to the course structure?
    $modinfo = get_fast_modinfo($course);
    $changelist = array();
    $logs = $DB->get_records_select('log', "time > ? AND course = ? AND\n                                            module = 'course' AND\n                                            (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')", array($timestart, $course->id), "id ASC");
    if ($logs) {
        $actions = array('add mod', 'update mod', 'delete mod');
        $newgones = array();
        // added and later deleted items
        foreach ($logs as $key => $log) {
            if (!in_array($log->action, $actions)) {
                continue;
            }
            $info = explode(' ', $log->info);
            // note: in most cases I replaced hardcoding of label with use of
            // $cm->has_view() but it was not possible to do this here because
            // we don't necessarily have the $cm for it
            if ($info[0] == 'label') {
                // Labels are ignored in recent activity
                continue;
            }
            if (count($info) != 2) {
                debugging("Incorrect log entry info: id = " . $log->id, DEBUG_DEVELOPER);
                continue;
            }
            $modname = $info[0];
            $instanceid = $info[1];
            if ($log->action == 'delete mod') {
                // unfortunately we do not know if the mod was visible
                if (!array_key_exists($log->info, $newgones)) {
                    $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
                    $changelist[$log->info] = array('operation' => 'delete', 'text' => $strdeleted);
                }
            } else {
                if (!isset($modinfo->instances[$modname][$instanceid])) {
                    if ($log->action == 'add mod') {
                        // do not display added and later deleted activities
                        $newgones[$log->info] = true;
                    }
                    continue;
                }
                $cm = $modinfo->instances[$modname][$instanceid];
                if (!$cm->uservisible) {
                    continue;
                }
                if ($log->action == 'add mod') {
                    $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
                    $changelist[$log->info] = array('operation' => 'add', 'text' => "{$stradded}:<br /><a href=\"{$CFG->wwwroot}/mod/{$cm->modname}/view.php?id={$cm->id}\">" . format_string($cm->name, true) . "</a>");
                } else {
                    if ($log->action == 'update mod' and empty($changelist[$log->info])) {
                        $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
                        $changelist[$log->info] = array('operation' => 'update', 'text' => "{$strupdated}:<br /><a href=\"{$CFG->wwwroot}/mod/{$cm->modname}/view.php?id={$cm->id}\">" . format_string($cm->name, true) . "</a>");
                    }
                }
            }
        }
    }
    if (!empty($changelist)) {
        echo $OUTPUT->heading(get_string("courseupdates") . ':', 3);
        $content = true;
        foreach ($changelist as $changeinfo => $change) {
            echo '<p class="activity">' . $change['text'] . '</p>';
        }
    }
    /// Now display new things from each module
    $usedmodules = array();
    foreach ($modinfo->cms as $cm) {
        if (isset($usedmodules[$cm->modname])) {
            continue;
        }
        if (!$cm->uservisible) {
            continue;
        }
        $usedmodules[$cm->modname] = $cm->modname;
    }
    foreach ($usedmodules as $modname) {
        // Each module gets it's own logs and prints them
        if (file_exists($CFG->dirroot . '/mod/' . $modname . '/lib.php')) {
            include_once $CFG->dirroot . '/mod/' . $modname . '/lib.php';
            $print_recent_activity = $modname . '_print_recent_activity';
            if (function_exists($print_recent_activity)) {
                // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
                $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
            }
        } else {
            debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
        }
    }
    if (!$content) {
        echo '<p class="message">' . get_string('nothingnew') . '</p>';
    }
}
コード例 #3
0
function print_recent_activity($course)
{
    // $course is an object
    // This function trawls through the logs looking for
    // anything new since the user's last login
    global $CFG, $USER, $SESSION;
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    $timestart = time() - COURSE_MAX_RECENT_PERIOD;
    if (!has_capability('moodle/legacy:guest', $context, NULL, false)) {
        if (!empty($USER->lastcourseaccess[$course->id])) {
            if ($USER->lastcourseaccess[$course->id] > $timestart) {
                $timestart = $USER->lastcourseaccess[$course->id];
            }
        }
    }
    echo '<div class="activitydate">';
    echo get_string('activitysince', '', userdate($timestart));
    echo '</div>';
    echo '<div class="activityhead">';
    echo '<a href="' . $CFG->wwwroot . '/course/recent.php?id=' . $course->id . '">' . get_string('recentactivityreport') . '</a>';
    echo "</div>\n";
    // Firstly, have there been any new enrolments?
    $heading = false;
    $content = false;
    $users = get_recent_enrolments($course->id, $timestart);
    //Accessibility: new users now appear in an <OL> list.
    if ($users) {
        echo '<div class="newusers">';
        if (!$heading) {
            print_headline(get_string("newusers") . ':', 3);
            $heading = true;
            $content = true;
        }
        echo "<ol class=\"list\">\n";
        foreach ($users as $user) {
            $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
            echo '<li class="name"><a href="' . $CFG->wwwroot . "/user/view.php?id={$user->id}&amp;course={$course->id}\">{$fullname}</a></li>\n";
        }
        echo "</ol>\n</div>\n";
    }
    // Next, have there been any modifications to the course structure?
    $logs = get_records_select('log', "time > '{$timestart}' AND course = '{$course->id}' AND\n                                       module = 'course' AND action LIKE '% mod'", "time ASC");
    if ($logs) {
        foreach ($logs as $key => $log) {
            $info = split(' ', $log->info);
            if ($info[0] == 'label') {
                // Labels are special activities
                continue;
            }
            $modname = get_field($info[0], 'name', 'id', $info[1]);
            //Create a temp valid module structure (course,id)
            $tempmod->course = $log->course;
            $tempmod->id = $info[1];
            //Obtain the visible property from the instance
            $modvisible = instance_is_visible($info[0], $tempmod);
            //Only if the mod is visible
            if ($modvisible) {
                switch ($log->action) {
                    case 'add mod':
                        $stradded = get_string('added', 'moodle', get_string('modulename', $info[0]));
                        $changelist[$log->info] = array('operation' => 'add', 'text' => "{$stradded}:<br /><a href=\"{$CFG->wwwroot}/course/{$log->url}\">" . format_string($modname, true) . "</a>");
                        break;
                    case 'update mod':
                        $strupdated = get_string('updated', 'moodle', get_string('modulename', $info[0]));
                        if (empty($changelist[$log->info])) {
                            $changelist[$log->info] = array('operation' => 'update', 'text' => "{$strupdated}:<br /><a href=\"{$CFG->wwwroot}/course/{$log->url}\">" . format_string($modname, true) . "</a>");
                        }
                        break;
                    case 'delete mod':
                        if (!empty($changelist[$log->info]['operation']) and $changelist[$log->info]['operation'] == 'add') {
                            $changelist[$log->info] = NULL;
                        } else {
                            $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $info[0]));
                            $changelist[$log->info] = array('operation' => 'delete', 'text' => $strdeleted);
                        }
                        break;
                }
            }
        }
    }
    if (!empty($changelist)) {
        foreach ($changelist as $changeinfo => $change) {
            if ($change) {
                $changes[$changeinfo] = $change;
            }
        }
        if (isset($changes)) {
            if (count($changes) > 0) {
                print_headline(get_string('courseupdates') . ':', 3);
                $content = true;
                foreach ($changes as $changeinfo => $change) {
                    echo '<p class="activity">' . $change['text'] . '</p>';
                }
            }
        }
    }
    // Now display new things from each module
    $mods = get_records('modules', 'visible', '1', 'name', 'id, name');
    $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
    foreach ($mods as $mod) {
        // Each module gets it's own logs and prints them
        if (file_exists($CFG->dirroot . '/mod/' . $mod->name . '/lib.php')) {
            include_once $CFG->dirroot . '/mod/' . $mod->name . '/lib.php';
            $print_recent_activity = $mod->name . '_print_recent_activity';
            if (function_exists($print_recent_activity)) {
                //
                // NOTE:
                //   $isteacher (second parameter below) is to be deprecated!
                //
                // TODO:
                //   1) Make sure that all _print_recent_activity functions are
                //      not using the $isteacher value.
                //   2) Eventually, remove the $isteacher parameter from the
                //      function calls.
                //
                $modcontent = $print_recent_activity($course, $viewfullnames, $timestart);
                if ($modcontent) {
                    $content = true;
                }
            }
        } else {
            /// Really need to indicate an error here to admins. Is there a way to do this?
        }
    }
    if (!$content) {
        echo '<p class="message">' . get_string('nothingnew') . '</p>';
    }
}