Esempio n. 1
0
 public static function process_course_module_deleted(\core\event\course_module_deleted $event)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/local/morph/classes/logger/Logger.php";
     require_once $CFG->dirroot . "/mod/project/projectadminlib.php";
     $log = new moodle\local\morph\Logger(array("prefix" => 'project_'));
     $log->debug("OBSERVED COURSE MODULE CREATED DELETED");
     $eventdata = $event->get_data();
     if ($eventdata['other']['modulename'] === 'project') {
         $other = $eventdata["other"];
         $projectid = $other['instanceid'];
         if ($project_tools = $DB->get_record('project_tools', array('project_id' => $projectid))) {
             $chat_cm = get_coursemodule_from_instance("chat", $project_tools->chat_id);
             $DB->delete_records('chat', array('id' => $chat_cm->instance));
             $DB->delete_records('course_modules', array('id' => $chat_cm->id));
             $forum_cm = get_coursemodule_from_instance("forum", $project_tools->forum_id);
             $DB->delete_records('forum', array('id' => $forum_cm->instance));
             $DB->delete_records('course_modules', array('id' => $forum_cm->id));
         }
         $log->debug("DELETED PROJECT");
     }
 }
/**
 * Created by PhpStorm.
 * User: zoran
 * Date: 28/10/16
 * Time: 3:27 PM
 */
function handle_new_project_created_event($event)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . "/local/morph/classes/logger/Logger.php";
    $log = new moodle\local\morph\Logger(array("prefix" => 'project_'));
    $eventdata = $event->get_data();
    $other = $eventdata["other"];
    $cm = get_coursemodule_from_instance($other["modulename"], $other["instanceid"]);
    $section = $DB->get_record("course_sections", array('id' => $cm->section));
    $courseid = $eventdata['courseid'];
    $projectname = $other['name'];
    $projectid = $other['instanceid'];
    $forumname = $projectname . " (forum)";
    $log->debug("CREATING PROJECT:" . $projectname . " in section:" . $section->section);
    $forum = create_project_forum($courseid, $projectname, $section->section);
    $chat = create_project_chat($courseid, $projectname, $section->section);
    $project_tools = new stdClass();
    $project_tools->project_id = $projectid;
    $project_tools->forum_id = $forum->id;
    $project_tools->chat_id = $chat->id;
    $DB->insert_record("project_tools", $project_tools);
}
Esempio n. 3
0
function checkChatAlerts($chatuser, $courseid)
{
    global $DB, $CFG, $USER, $PAGE;
    require_once $CFG->dirroot . "/local/morph/classes/logger/Logger.php";
    $log = new moodle\local\morph\Logger(array("prefix" => 'chat_'));
    $config = get_config('project');
    $currentgroup = $chatuser->groupid;
    sleep(1);
    /* Chat participation level analysis */
    /*OLD AVG
    	$averages = $DB->get_record_sql('SELECT avg(message_char) as avgMsgSize
    FROM (
        SELECT distinct A.userid, coalesce(sum(LENGTH(message)),0) as message_char FROM `mdl_groups_members` A LEFT JOIN `mdl_chat_messages` B ON A.userid = B.userid  WHERE A.groupid = '.$currentgroup.' AND system = 0
    GROUP BY userid) C');*/
    $averages = $DB->get_record_sql('SELECT avg(LENGTH(message)) as avgmessage_char FROM {chat_messages_current} WHERE groupid =  ' . $currentgroup . ' AND system = 0')->avgmessage_char;
    $message_size = new stdClass();
    $message_size->small = $averages * $config->smallmsg;
    $message_size->medium = $averages * 1.0;
    $message_size->large = $averages * $config->largemsg;
    $log->debug("CONFIG:" . json_encode($config));
    $charCount = new stdClass();
    $query = 'SELECT t4.userid, coalesce(t5.Schars,0) as Schars, coalesce(t1.Mchars,0) as Mchars, coalesce(t2.Lchars,0) as Lchars, coalesce(t3.Tchars,0) as Tchars
FROM
	(SELECT userid FROM {groups_members}
     WHERE groupid = ' . $currentgroup . ' ) t4
LEFT JOIN
	(SELECT userid, SUM(LENGTH(message)) as Mchars
	FROM {chat_messages_current}
	WHERE groupid = ' . $currentgroup . '  AND system = 0 AND LENGTH(message) BETWEEN ' . $message_size->small . ' AND ' . $message_size->large . '
	GROUP BY userid) t1
ON t4.userid = t1.userid
LEFT JOIN
	(SELECT userid, SUM(LENGTH(message)) as Lchars
	FROM {chat_messages_current}
	WHERE groupid = ' . $currentgroup . '  AND system = 0 AND LENGTH(message) >  ' . $message_size->large . '
	GROUP BY userid) t2
ON t1.userid = t2.userid
LEFT JOIN
	(SELECT userid, SUM(LENGTH(message)) as Tchars
	FROM {chat_messages_current}
	WHERE groupid = ' . $currentgroup . '  AND system = 0 AND LENGTH(message) > ' . $message_size->small . '
	GROUP BY userid )t3
ON t1.userid = t3.userid
LEFT JOIN
	(SELECT userid, SUM(LENGTH(message)) as Schars
	FROM {chat_messages_current}
	WHERE groupid = ' . $currentgroup . '  AND system = 0 AND LENGTH(message) < ' . $message_size->small . '
	GROUP BY userid )t5
ON t4.userid = t5.userid';
    $charCount = $DB->get_records_sql($query);
    $stats = new stdClass();
    $stats = $DB->get_record_sql('SELECT SUM(LENGTH(message)) as Sum FROM {chat_messages_current} WHERE groupid = ' . $currentgroup . '  AND system = 0 AND LENGTH(message) >  ' . $message_size->small);
    $stats->avg = $stats->sum / count($charCount);
    $stats->low = $stats->avg * $config->lowthreshold;
    $stats->high = $stats->avg * $config->highthreshold;
    //create alert object
    /*$statsmsg = new stdclass();
    	$statsmsg->chatid = 0;
    	$statsmsg->userid = 0;
    	$statsmsg->groupid = $currentgroup;
    	$statsmsg->message =  'stats: avg: '.$averages.' avg by members:'.$stats->avg.' lo:'.$stats->low.' hi:'.$stats->high.' ms:'.$message_size->small.' mm:'.$message_size->medium.' ml: '.$message_size->large;
    	$statsmsg->system = 1;
    	$statsmsg->timestamp = time();
    */
    //insert alert message to the database
    $messageid = $DB->insert_record('chat_messages', $statsmsg);
    //$DB->insert_record('chat_messages_current', $statsmsg);
    //$log->debug("inserted into chat_messages_current:".json_encode($statsmsg));
    //Iterate through all members of a chat and find any who has a word count lower or higher than the thresholds
    $alerts_controller = new alerts_controller();
    $theme = 'bubble';
    foreach ($charCount as $member) {
        if ($member->tchars < $stats->low) {
            $currentuser = $DB->get_record('user', array('id' => $member->userid));
            $member->alert = "Low";
            $header = "SYSTEM ALERT!";
            $tz = get_user_timezone($currentuser->timezone);
            //$strtime = userdate(time(), get_string('strftimemessage', 'chat'), $tz);
            $content = get_string('alert-low', 'mod_project', $currentuser->firstname);
            $alerts_controller->create_top_panel_notification_alert($currentuser->id, $courseid, 0, "error", $header, $content);
        } else {
            if ($member->tchars > $stats->high) {
                $member->alert = "High";
                $currentuser = $DB->get_record('user', array('id' => $member->userid));
                $header = "SYSTEM ALERT!";
                $content = get_string('alert-high', 'mod_project', $currentuser->firstname);
                $alerts_controller->create_top_panel_notification_alert($currentuser->id, $courseid, 0, "success", $header, $content);
            } else {
                $member->alert = null;
            }
        }
    }
    return;
}
Esempio n. 4
0
<?php

/**
 * Created by PhpStorm.
 * User: zoran
 * Date: 04/11/16
 * Time: 3:32 PM
 */
require_once dirname(__FILE__) . '/../../config.php';
global $CFG, $DB;
require_once $CFG->dirroot . "/local/morph/classes/logger/Logger.php";
$context = context_system::instance();
require_login();
$PAGE->set_context($context);
$log = new moodle\local\morph\Logger(array("prefix" => "project_"));
$log->debug("PROJECT GROUP AJAX PROCESSING");
session_write_close();
if (is_ajax()) {
    if (isset($_POST["action"]) && !empty($_POST["action"])) {
        //Checks if action value exists
        $action = $_POST["action"];
        switch ($action) {
            //Switch case for value of action
            case 'projectgroupactivate':
                $log->debug("project group activate action..." . $_POST["courseid"] . " " . $_POST["projectid"] . " " . $_POST["groupid"]);
                if ($projectgroup = $DB->get_record('project_group_mapping', array('course_id' => $_POST["courseid"], 'project_id' => $_POST["projectid"], 'group_id' => $_POST["groupid"]))) {
                    $projectgroup->disabled = filter_var($_POST["disabled"], FILTER_VALIDATE_BOOLEAN);
                    $log->debug("UPDATE DISABLE/ENABLE GROUP:" . json_encode($projectgroup));
                    $DB->update_record('project_group_mapping', $projectgroup);
                } else {
                    $projectgroup = new stdClass();
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * project module version information
 *
 * @package    mod
 * @subpackage project
 * @copyright  2009 Petr Skoda (http://skodak.org)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require '../../config.php';
require_once $CFG->dirroot . '/mod/project/edit_form.php';
require_once $CFG->dirroot . '/mod/project/locallib.php';
require_once $CFG->dirroot . "/mod/project/classes/event/history_imported.php";
require_once $CFG->dirroot . "/local/morph/classes/logger/Logger.php";
$log = new moodle\local\morph\Logger(array('prefix' => "import_"));
$log->debug("IMPORTING HISTORY CALLED");
//require_once($CFG->libdir.'/completionlib.php');
$cmid = required_param('cmid', PARAM_INT);
// Project Module ID
$mapped = optional_param('mapped', 0, PARAM_RAW);
//$id      = optional_param('id', 0, PARAM_INT); // Course Module ID
$cm = get_coursemodule_from_id('project', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$project = $DB->get_record('project', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
$currentgroup = groups_get_activity_group($cm, true);
$members = getGroupMembers($currentgroup);
$project->currentgroup = $currentgroup;
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);