From 019b9b407ab74c1b381fe13d98626a1797ef8dbe Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Mon, 29 Sep 2014 13:42:29 +0200 Subject: [PATCH] add plugin for chat module display users connected and users active in chat sessions --- plugins/moodle/modules/moodle_mod_chat.php | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 plugins/moodle/modules/moodle_mod_chat.php diff --git a/plugins/moodle/modules/moodle_mod_chat.php b/plugins/moodle/modules/moodle_mod_chat.php new file mode 100644 index 00000000..bfbdb147 --- /dev/null +++ b/plugins/moodle/modules/moodle_mod_chat.php @@ -0,0 +1,71 @@ +#!/usr/bin/php + + * @version 1.0 2014 + * + */ +$dbh = null; +$db = getenv('db'); +$type = getenv('type'); +$host = getenv('host'); +$user = getenv('user'); +$pass = getenv('pass'); +$table_prefix = getenv('table_prefix'); +$port = getenv('port'); +if (!$port) + $port = 3306; +$graph_period = time() - 5*60; + + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Chat Users\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel users\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the number of users connected and posting message in chat sessions\n"; + echo "chat_users_connected.label users connected\n"; + echo "chat_users_connected.min 0\n"; + echo "chat_users_active.label users posting messages\n"; + echo "chat_users_active.min 0\n"; + exit(0); +} + +try { + $dsn = $type . ':host=' . $host . ';port=' . $port . ';dbname=' . $db; + $dbh = new PDO($dsn, $user, $pass); +} catch (Exception $e) { + echo "Connection failed\n"; + exit(1); +} + +//Connected +$nb=0; +if (($stmt = $dbh->query("SELECT COUNT(DISTINCT userid) FROM {$table_prefix}chat_users WHERE lastping > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "chat_users_connected.value $nb\n"; + +//Active +$nb=0; +if (($stmt = $dbh->query("SELECT COUNT(DISTINCT userid) FROM {$table_prefix}chat_users WHERE lastmessageping > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "chat_users_active.value $nb\n";