Example #1
0
/**
 * invites user to a wiziq class
 *
 * @param int $session_id helpmenow_session.id
 * @param int $class_id wiziq class id
 */
function helpmenow_wiziq_invite($session_id, $class_id)
{
    global $CFG, $USER, $DB;
    if ($s2p_rec = $DB->get_record('block_helpmenow_s2p', array('sessionid' => $session_id, 'plugin' => 'wiziq'))) {
        $s2p = new helpmenow_session2plugin_wiziq(null, $s2p_rec);
        $method = 'update';
    } else {
        $s2p = new helpmenow_session2plugin_wiziq(null, (object) array('sessionid' => $session_id));
        $method = 'insert';
    }
    if (!in_array($class_id, $s2p->classes)) {
        $s2p->classes[] = $class_id;
        $s2p->{$method}();
    }
    $join_url = new moodle_url("{$CFG->wwwroot}/blocks/helpmenow/plugins/wiziq/join.php");
    $join_url->param('classid', $class_id);
    $join_url->param('sessionid', $session_id);
    $join_url = $join_url->out();
    $message = fullname($USER) . ' has invited you to use voice, video, and whiteboarding, <a target="wiziq_session" href="' . $join_url . '">click here</a> to join.';
    return helpmenow_message($session_id, null, $message);
}
Example #2
0
/**
 * chat refresh
 *
 * @param object $request request from client
 * @param object $response response
 */
function helpmenow_serverfunc_refresh($request, &$response)
{
    global $USER, $CFG, $DB;
    $session2user = helpmenow_get_s2u($request->session);
    # unless something has gone wrong, we should already have a response ready:
    if ($request->last_message == $session2user->optimistic_last_message) {
        $response_cache = json_decode($session2user->cache);
        $response = (object) array_merge((array) $response, (array) $response_cache);
    } else {
        # unread messages
        $messages = helpmenow_get_unread($request->session, $USER->id);
        # todo: move this to the client
        if ($messages) {
            if (!isset($response->html)) {
                $response->html = '';
            }
            $response->html .= helpmenow_format_messages($messages);
            # determine if we need to beep
            foreach ($messages as $m) {
                if ($m->notify) {
                    $response->title_flash = format_string($m->message);
                    $response->beep = true;
                }
                $response->last_message = $m->id;
            }
        } else {
            $response->last_message = $request->last_message;
        }
    }
    if (!isset($response->last_message)) {
        $response->last_message = null;
    }
    /**
     * if there aren't any new messages check to see if we should add a "sent: _time_" message
     *
     * yes, it sucks, it's one of the many things todo: move to client
     * -dzaharee
     */
    if ($response->last_message == $request->last_message) {
        $sql = "\n            SELECT *\n            FROM {block_helpmenow_message}\n            WHERE id = (\n                SELECT max(id)\n                FROM {block_helpmenow_message}\n                WHERE sessionid = {$request->session}\n            )";
        if ($last_message = $DB->get_record_sql($sql)) {
            if (!is_null($last_message->userid) and $last_message->time < time() - 30) {
                $message = get_string('sent', 'block_helpmenow') . ': ' . userdate($last_message->time, '%r');
                helpmenow_message($request->session, null, $message, 0);
            }
        }
    }
    # update session2user
    $session2user->last_message = $request->last_message;
    $session2user->optimistic_last_message = $response->last_message;
    $session2user->last_refresh = time();
    $session2user->cache = json_encode((object) array('html' => '', 'beep' => false, 'last_message' => $request->last_message));
    if (!$DB->update_record('block_helpmenow_session2user', $session2user)) {
        $response->html = '';
        $response->beep = false;
        $response->last_message = $request->last_message;
        throw new Exception('Could not update session2user record');
    }
    # call subplugin on_chat_refresh methods
    foreach (helpmenow_plugin::get_plugins() as $pluginname) {
        $class = "helpmenow_plugin_{$pluginname}";
        $class::on_chat_refresh($request, $response);
    }
}