Browse Source

First commit

master
Sesostris Vieira 10 years ago
parent
commit
93cfb7e250
  1. 11
      README.md
  2. 43
      db/access.php
  3. 32
      db/install.php
  4. 87
      index.php
  5. 36
      lang/en/report_messages.php
  6. 34
      lang/pt_br/report_messages.php
  7. 105
      lib.php
  8. 55
      locallib.php
  9. 8
      styles.css
  10. 124
      user.php
  11. 30
      version.php

11
README.md

@ -2,3 +2,14 @@ moodle_report_messages
====================== ======================
A simple report to view message exchanges between user from a course A simple report to view message exchanges between user from a course
To install, clone this plugin in $MOODLE/report/messages folder:
$ cd $MOODLE/report
$ git clone https://github.com/interlegis/moodle_report_messages.git messages
Enter in your moodle site as admin user and install the plugin
Usage:
In a course, click in Administration > Report > Messages report to see a
synthesis report for all enrolled users. Click in {view details} link to
see all messages sended from/to that user.

43
db/access.php

@ -0,0 +1,43 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capabilities
*
* @package report_outline
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'report/messages:view' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'coursereport/messages:view',
)
);

32
db/install.php

@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Post installation and migration code.
*
* @package report
* @subpackage messages
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
function xmldb_report_messages_install() {
global $DB;
}

87
index.php

@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Display user messages reports for a course (totals)
*
* @package report
* @subpackage messages
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->dirroot.'/report/messages/locallib.php');
$id = required_param('id',PARAM_INT); // course id
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
$PAGE->set_url('/report/messages/index.php', array('id'=>$id));
$PAGE->set_pagelayout('report');
require_login($course);
$context = context_course::instance($course->id);
require_capability('report/messages:view', $context);
add_to_log($course->id, 'course', 'report messages', "report/messages/index.php?id=$course->id", $course->id);
$strviewdetail = get_string('viewdetail', 'report_messages');
$stractivityreport = get_string('pluginname', 'report_messages');
$stractivity = get_string('activity');
$strlast = get_string('lastaccess');
$strreports = get_string('reports');
$strviews = get_string('views');
$strrelatedblogentries = get_string('relatedblogentries', 'blog');
$PAGE->set_title($course->shortname .': '. $stractivityreport);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($course->fullname));
$messagestable = new html_table();
$messagestable->attributes['class'] = 'generaltable boxaligncenter';
$messagestable->cellpadding = 5;
$messagestable->id = 'messagestable';
$messagestable->head = array(get_string('fullname'), get_string('totalsended', 'report_messages'),
get_string('totalreceived','report_messages'), $strviewdetail);
$messagestable->align = array('left', 'right', 'right', 'center');
$messagestable->data = array();
$userlist = get_enrolled_users($context, '', 0, 'u.id');
list($in_user, $param_users) = $DB->get_in_or_equal(array_keys($userlist), SQL_PARAMS_QM);
$fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
$sql = "
select u.id, $fullname as fullname, u.picture, u.firstname, u.lastname, u.imagealt, u.email,
(select count(*) from mdl_message where useridfrom=u.id and useridto<>u.id and useridto $in_user) as totalsend,
(select count(*) from mdl_message where useridto=u.id and useridfrom<>u.id and useridfrom $in_user) as totalreceive
from mdl_user u
where u.id $in_user
";
$data = $DB->get_records_sql($sql, array_merge($param_users,$param_users,$param_users));
foreach ($data as $user) {
$upic = $OUTPUT->user_picture($user);
$ulink = "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}\">{$upic}</a>";
$link = "<a href=\"$CFG->wwwroot/report/messages/user.php?id=$user->id&course=$course->id\">$strviewdetail</a>";
$messagestable->data[] = array($ulink.' '.$user->fullname, $user->totalsend, $user->totalreceive, $link);
}
echo html_writer::table($messagestable);
echo $OUTPUT->footer();

36
lang/en/report_messages.php

@ -0,0 +1,36 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings
*
* @package report
* @subpackage messages
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['messages:view'] = 'View activity report';
$string['page-report-messages-x'] = 'Any messages report';
$string['page-report-messages-index'] = 'Course messages report';
$string['page-report-messages-user'] = 'User course messages report';
$string['pluginname'] = 'Messages report';
$string['reporttitle'] = 'Message report to user {$a->fullname}';
$string['exchangedmessages'] = '{$a->userlink} {$a->total_messages} messages exchanged with {$a->fullname}';
$string['message'] = 'Message body';
$string['viewdetail'] = 'View details';
$string['totalsended'] = 'Total sended messages';
$string['totalreceived'] = 'Total received messages';

34
lang/pt_br/report_messages.php

@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings
*
* @package report
* @subpackage messages
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['messages:view'] = 'Ver relatório de mensagens';
$string['page-report-messages-x'] = 'Um relatório de mensagens';
$string['page-report-messages-index'] = 'Relatório de mensagens do curso';
$string['page-report-messages-user'] = 'Relatório de mensagens do usuário no curso';
$string['pluginname'] = 'Relatório de Mensagens';
$string['reporttitle'] = 'Relatório de mensagens do usuário {$a->fullname}';
$string['exchangedmessages'] = '{$a->userlink} {$a->total_messages} mensagens trocadas com {$a->fullname}';
$string['message'] = 'Texto da mensagem';
$string['viewdetail'] = 'Ver detalhes';

105
lib.php

@ -0,0 +1,105 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains public API of messages report
*
* @package report
* @subpackage messages
* @copyright 2009 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* This function extends the course navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param stdClass $context The context of the course
*/
function report_messages_extend_navigation_course($navigation, $course, $context) {
if (has_capability('report/messages:view', $context)) {
$url = new moodle_url('/report/messages/index.php', array('id'=>$course->id));
$navigation->add(get_string('pluginname', 'report_messages'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
}
/**
* This function extends the course navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $user
* @param stdClass $course The course to object for the report
*/
function report_messages_extend_navigation_user($navigation, $user, $course) {
if (report_messages_can_access_user_report($user, $course)) {
$url = new moodle_url('/report/messages/user.php', array('id'=>$user->id, 'course'=>$course->id));
$navigation->add(get_string('pluginname', 'report_messages'), $url);
}
}
/**
* Is current user allowed to access this report
*
* @private defined in lib.php for performance reasons
*
* @param stdClass $user
* @param stdClass $course
* @return bool
*/
function report_messages_can_access_user_report($user, $course) {
global $USER;
$coursecontext = context_course::instance($course->id);
$personalcontext = context_user::instance($user->id);
if (has_capability('report/messages:view', $coursecontext)) {
return true;
}
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
return true;
}
} else if ($user->id == $USER->id) {
if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
return true;
}
}
return false;
}
/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
* @return array
*/
function report_messages_page_type_list($pagetype, $parentcontext, $currentcontext) {
$array = array(
'*' => get_string('page-x', 'pagetype'),
'report-*' => get_string('page-report-x', 'pagetype'),
'report-messages-*' => get_string('page-report-messages-x', 'report_messages'),
'report-messages-index' => get_string('page-report-messages-index', 'report_messages'),
'report-messages-user' => get_string('page-report-messages-user', 'report_messages')
);
return $array;
}

55
locallib.php

@ -0,0 +1,55 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains functions used by the outline reports
*
* @package report
* @subpackage outline
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once(dirname(__FILE__).'/lib.php');
require_once($CFG->dirroot.'/course/lib.php');
function report_outline_print_row($mod, $instance, $result) {
global $OUTPUT, $CFG;
$image = "<img src=\"" . $OUTPUT->pix_url('icon', $mod->modname) . "\" class=\"icon\" alt=\"$mod->modfullname\" />";
echo "<tr>";
echo "<td valign=\"top\">$image</td>";
echo "<td valign=\"top\" style=\"width:300\">";
echo " <a title=\"$mod->modfullname\"";
echo " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".format_string($instance->name,true)."</a></td>";
echo "<td>&nbsp;&nbsp;&nbsp;</td>";
echo "<td valign=\"top\">";
if (isset($result->info)) {
echo "$result->info";
} else {
echo "<p style=\"text-align:center\">-</p>";
}
echo "</td>";
echo "<td>&nbsp;&nbsp;&nbsp;</td>";
if (!empty($result->time)) {
$timeago = format_time(time() - $result->time);
echo "<td valign=\"top\" style=\"white-space: nowrap\">".userdate($result->time)." ($timeago)</td>";
}
echo "</tr>";
}

8
styles.css

@ -0,0 +1,8 @@
#page-report-outline-index td.numviews {text-align:right;}
#page-report-outline-index tr.section {text-align: center;}
#page-report-outline-index td.lastaccess {font-size: 0.8em;}
#page-report-outline-user .section .content {margin-left: 30px;margin-right: 30px;}
#page-report-outline-user .section h2 {margin-top: 0;}
#page-report-outline-user .section {margin-left: 30px;margin-right: 30px;margin-bottom: 20px;}
#page-report-outline-user .section {border-width:1px;border-style:solid;padding:10px;}

124
user.php

@ -0,0 +1,124 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Display user activity reports for a course (totals)
*
* @package report
* @subpackage outline
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once('locallib.php');
$userid = required_param('id', PARAM_INT);
$courseid = required_param('course', PARAM_INT);
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
$coursecontext = context_course::instance($course->id);
$personalcontext = context_user::instance($user->id);
if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)
and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) {
//TODO: do not require parents to be enrolled in courses - this is a hack!
require_login();
$PAGE->set_course($course);
} else {
require_login($course);
}
if (!report_messages_can_access_user_report($user, $course, true)) {
require_capability('report/messages:view', $coursecontext);
}
add_to_log($course->id, 'course', 'report messages', "report/messages/user.php?id=$user->id&course=$course->id", $course->id);
$PAGE->set_pagelayout('admin');
$PAGE->set_url('/report/messages/user.php', array('id'=>$user->id, 'course'=>$course->id));
$PAGE->navigation->extend_for_user($user);
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
$PAGE->set_title($course->shortname.': '.get_string('pluginname', 'report_messages'));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo '<h2>'.get_string('reporttitle','report_messages',array('fullname'=>fullname($user))).'</h2>';
$from = $DB->get_records_sql('select distinct m.useridfrom as id from {message} m where m.useridto = ? and m.useridfrom <> ?', array($user->id, $user->id));
$to = $DB->get_records_sql('select distinct m.useridto as id from {message} m where m.useridfrom = ? and m.useridto <> ?', array($user->id, $user->id));
$contacts = array();
$sqlfullname = $DB->sql_fullname('u.firstname','u.lastname');
$sql = "
select u.id, $sqlfullname as fullname, count(*) as total_messages, u.picture, u.firstname, u.lastname, u.imagealt, u.email
from {user} u, {message} m
where u.id = ? and
((m.useridfrom = ? and m.useridto = ?) or
(m.useridfrom = ? and m.useridto = ?))
group by u.id, u.username, u.firstname, u.lastname, u.email
";
foreach ($from as $u) {
if (is_enrolled($coursecontext, $u)) {
$contacts[$u->id] = $DB->get_record_sql($sql, array($u->id, $u->id, $user->id, $user->id, $u->id));
}
}
foreach ($to as $u) {
if (is_enrolled($coursecontext, $u)) {
$contacts[$u->id] = $DB->get_record_sql($sql, array($u->id, $u->id, $user->id, $user->id, $u->id));
}
}
if (empty($contacts)) {
echo $OUTPUT->notification(get_string('nothingtodisplay'));
} else {
$sqlfromname = $DB->sql_fullname('fu.firstname','fu.lastname');
$sqltoname = $DB->sql_fullname('tu.firstname','tu.lastname');
$sql = "
select m.timecreated, $sqlfromname as fromuser, $sqltoname as touser, m.fullmessage, m.fullmessageformat
from {message} m
inner join {user} fu on fu.id = m.useridfrom
inner join {user} tu on tu.id = m.useridto
where (m.useridfrom = ? and m.useridto = ?) or
(m.useridfrom = ? and m.useridto = ?)
order by m.timecreated desc
";
foreach ($contacts as $contact) {
echo $OUTPUT->box_start();
$upic = $OUTPUT->user_picture($contact);
$ulink = "<a href=\"{$CFG->wwwroot}/user/view.php?id={$contact->id}&course={$course->id}\">{$upic}</a>";
$a = array('userlink'=>$ulink, 'total_messages'=>$contact->total_messages, 'fullname'=>$contact->fullname);
$head = get_string('exchangedmessages', 'report_messages', $a);
echo "<h3>$head</h3>";
$table = new html_table();
$tabl->attributes['class'] = 'generaltable boxaligncenter';
$table->head = array(get_string('date'), get_string('from'), get_string('to'), get_string('message', 'report_messages'));
$messages = $DB->get_records_sql($sql, array($user->id, $contact->id, $contact->id, $user->id));
$table->data = array();
foreach ($messages as $message) {
$table->data[] = array(userdate($message->timecreated), $message->fromuser, $message->touser, format_text($message->fullmessage, $message->fullmessageformat));
}
echo html_writer::table($table);
echo $OUTPUT->box_end();
}
}
echo $OUTPUT->footer();

30
version.php

@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version info
*
* @package report
* @subpackage messages
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2013050100; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2013050100; // Requires this Moodle version
$plugin->component = 'report_messages'; // Full name of the plugin (used for diagnostics)
Loading…
Cancel
Save