Merge branch 'MDL-47990_27' of git://github.com/timhunt/moodle into MOODLE_27_STABLE
[moodle.git] / user / portfoliologs.php
blobc7503a1af0bc4643ae40f9ed72d3abffe6942e8e
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file is part of the User section Moodle
20 * @copyright 1999 Martin Dougiamas http://dougiamas.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 * @package core_user
25 require_once(dirname(dirname(__FILE__)) . '/config.php');
27 if (empty($CFG->enableportfolios)) {
28 print_error('disabled', 'portfolio');
31 require_once($CFG->libdir . '/portfoliolib.php');
32 require_once($CFG->libdir . '/portfolio/exporter.php');
34 $courseid = optional_param('courseid', SITEID, PARAM_INT);
35 $page = optional_param('page', 0, PARAM_INT);
36 $perpage = optional_param('perpage', 10, PARAM_INT);
38 if (! $course = $DB->get_record("course", array("id" => $courseid))) {
39 print_error('invalidcourseid');
42 require_login($course, false);
44 $user = $USER;
45 $fullname = fullname($user);
46 $strportfolios = get_string('portfolios', 'portfolio');
48 $url = new moodle_url('/user/portfoliologs.php', array('courseid' => $courseid));
50 navigation_node::override_active_url(new moodle_url('/user/portfoliologs.php', array('courseid' => $courseid)));
52 if ($page !== 0) {
53 $url->param('page', $page);
55 if ($perpage !== 0) {
56 $url->param('perpage', $perpage);
59 $PAGE->set_url($url);
60 $PAGE->set_title("$course->fullname: $fullname: $strportfolios");
61 $PAGE->set_heading($course->fullname);
62 $PAGE->set_context(context_user::instance($user->id));
63 $PAGE->set_pagelayout('report');
65 echo $OUTPUT->header();
67 $showroles = 1;
68 $somethingprinted = false;
70 echo $OUTPUT->box_start();
72 $queued = $DB->get_records('portfolio_tempdata', array('userid' => $USER->id), 'expirytime DESC', 'id, expirytime');
73 if (count($queued) > 0) {
74 $table = new html_table();
75 $table->head = array(
76 get_string('displayarea', 'portfolio'),
77 get_string('plugin', 'portfolio'),
78 get_string('displayinfo', 'portfolio'),
79 get_string('displayexpiry', 'portfolio'),
80 '',
82 $table->data = array();
83 $now = time();
84 foreach ($queued as $q) {
85 $e = portfolio_exporter::rewaken_object($q->id);
86 $e->verify_rewaken(true);
87 $queued = $e->get('queued');
88 $baseurl = new moodle_url('/portfolio/add.php', array('id' => $q->id, 'logreturn' => 1, 'sesskey' => sesskey()));
90 $iconstr = $OUTPUT->action_icon(new moodle_url($baseurl, array('cancel' => 1)), new pix_icon('t/stop', get_string('cancel')));
92 if (!$e->get('queued') && $e->get('expirytime') > $now) {
93 $iconstr .= $OUTPUT->action_icon($baseurl, new pix_icon('t/go', get_string('continue')));
95 $table->data[] = array(
96 $e->get('caller')->display_name(),
97 (($e->get('instance')) ? $e->get('instance')->get('name') : get_string('noinstanceyet', 'portfolio')),
98 $e->get('caller')->heading_summary(),
99 userdate($q->expirytime),
100 $iconstr,
102 unset($e); // This could potentially be quite big, so free it.
104 echo $OUTPUT->heading(get_string('queuesummary', 'portfolio'));
105 echo html_writer::table($table);
106 $somethingprinted = true;
108 // Paging - get total count separately.
109 $logcount = $DB->count_records('portfolio_log', array('userid' => $USER->id));
110 if ($logcount > 0) {
111 $table = new html_table();
112 $table->head = array(
113 get_string('plugin', 'portfolio'),
114 get_string('displayarea', 'portfolio'),
115 get_string('transfertime', 'portfolio'),
117 $logs = $DB->get_records('portfolio_log', array('userid' => $USER->id), 'time DESC', '*', ($page * $perpage), $perpage);
118 foreach ($logs as $log) {
119 if (!empty($log->caller_file)) {
120 portfolio_include_callback_file($log->caller_file);
121 } else if (!empty($log->caller_component)) {
122 portfolio_include_callback_file($log->caller_component);
123 } else { // Errrmahgerrrd - this should never happen. Skipping.
124 continue;
126 $class = $log->caller_class;
127 $pluginname = '';
128 try {
129 $plugin = portfolio_instance($log->portfolio);
130 $url = $plugin->resolve_static_continue_url($log->continueurl);
131 if ($url) {
132 $pluginname = '<a href="' . $url . '">' . $plugin->get('name') . '</a>';
133 } else {
134 $pluginname = $plugin->get('name');
136 } catch (portfolio_exception $e) { // May have been deleted.
137 $pluginname = get_string('unknownplugin', 'portfolio');
140 $table->data[] = array(
141 $pluginname,
142 '<a href="' . $log->returnurl . '">' . call_user_func(array($class, 'display_name')) . '</a>',
143 userdate($log->time),
146 echo $OUTPUT->heading(get_string('logsummary', 'portfolio'));
147 $pagingbar = new paging_bar($logcount, $page, $perpage, $CFG->wwwroot . '/user/portfoliologs.php?');
148 echo $OUTPUT->render($pagingbar);
149 echo html_writer::table($table);
150 echo $OUTPUT->render($pagingbar);
151 $somethingprinted = true;
153 if (!$somethingprinted) {
154 echo $OUTPUT->heading($strportfolios);
155 echo get_string('nologs', 'portfolio');
157 echo $OUTPUT->box_end();
158 echo $OUTPUT->footer();