diff --git a/README.md b/README.md index a9a77b7..dc2de70 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,14 @@ moodle_report_messages ====================== 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. diff --git a/db/access.php b/db/access.php new file mode 100644 index 0000000..5619fe7 --- /dev/null +++ b/db/access.php @@ -0,0 +1,43 @@ +. + +/** + * 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', + ) +); + + diff --git a/db/install.php b/db/install.php new file mode 100644 index 0000000..7eee477 --- /dev/null +++ b/db/install.php @@ -0,0 +1,32 @@ +. + +/** + * 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; + +} + diff --git a/index.php b/index.php new file mode 100644 index 0000000..cff4abb --- /dev/null +++ b/index.php @@ -0,0 +1,87 @@ +. + +/** + * 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 = "wwwroot}/user/view.php?id={$user->id}&course={$course->id}\">{$upic}"; + $link = "wwwroot/report/messages/user.php?id=$user->id&course=$course->id\">$strviewdetail"; + $messagestable->data[] = array($ulink.' '.$user->fullname, $user->totalsend, $user->totalreceive, $link); +} + +echo html_writer::table($messagestable); +echo $OUTPUT->footer(); diff --git a/lang/en/report_messages.php b/lang/en/report_messages.php new file mode 100644 index 0000000..76c436c --- /dev/null +++ b/lang/en/report_messages.php @@ -0,0 +1,36 @@ +. + +/** + * 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'; diff --git a/lang/pt_br/report_messages.php b/lang/pt_br/report_messages.php new file mode 100644 index 0000000..1e3355c --- /dev/null +++ b/lang/pt_br/report_messages.php @@ -0,0 +1,34 @@ +. + +/** + * 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'; diff --git a/lib.php b/lib.php new file mode 100644 index 0000000..e3a5e4e --- /dev/null +++ b/lib.php @@ -0,0 +1,105 @@ +. + +/** + * 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; +} diff --git a/locallib.php b/locallib.php new file mode 100644 index 0000000..ba4761c --- /dev/null +++ b/locallib.php @@ -0,0 +1,55 @@ +. + +/** + * 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 = "pix_url('icon', $mod->modname) . "\" class=\"icon\" alt=\"$mod->modfullname\" />"; + + echo "
-
"; + } + echo "