From dd685310ab0362b6170a0aaab6ddd465776a6651 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 16 Sep 2014 14:02:00 +0200 Subject: [PATCH] initial commit --- plugins/moodle/modules/moodle_mod_forum.php | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/moodle/modules/moodle_mod_forum.php diff --git a/plugins/moodle/modules/moodle_mod_forum.php b/plugins/moodle/modules/moodle_mod_forum.php new file mode 100644 index 00000000..bbca5516 --- /dev/null +++ b/plugins/moodle/modules/moodle_mod_forum.php @@ -0,0 +1,72 @@ +#!/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 = getenv('graph_period'); +$graph_period = time() - 5*60; + + +if (count($argv) === 2 && $argv[1] === 'config') { + echo "graph_title Moodle Forum Posts\n"; + echo "graph_args --base 1000 --lower-limit 0\n"; + echo "graph_vlabel number\n"; + echo "graph_category Moodle\n"; + echo "graph_scale no\n"; + echo "graph_info Displays the sum of new forums posts / discussions in your Moodle site\n"; + echo "forum_posts.label posts\n"; + echo "forum_posts.min 0\n"; + echo "forum_posts.draw AREA\n"; + echo "forum_discussion.draw STACK\n"; + echo "forum_discussion.min 0\n"; + echo "forum_discussion.label discussions\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); +} + +$nb = 0; +if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}forum_posts WHERE timemodified > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "forum_posts.value $nb\n"; + +$nb = 0; +if (($stmt = $dbh->query("SELECT count(id) FROM {$table_prefix}forum_discussions WHERE timemodified > $graph_period")) != false) { + $nb = $stmt->fetchColumn(); +} +echo "forum_discussions.value $nb\n"; \ No newline at end of file