public function render_navigation()
 {
     global $USER;
     $conversations = local_simple_message_conversation::find_conversations_for_user($USER->id);
     $output = '';
     foreach ($conversations as $conversation) {
         $url = new moodle_url('/local/simple_message/index.php', array('conversation' => $conversation->id));
         $unreadcount = $conversation->get_unread_count($USER->id);
         $unreadinfo = $unreadcount > 0 ? " <span class='sm-unread-count'>" . $unreadcount . "</span></a></li>" : "";
         $output .= "<li><a data-conversation-id='" . $conversation->id . "' href='" . $url->out(true) . "'>" . $conversation->get_name() . $unreadinfo . "\n";
     }
     return "<nav id='sm-navigation'>\n        <h5>Messages</h5>\n        <h6>Direct <a href='newconversation.php'>new message</a></h6>\n        <ol>\n          {$output}\n        </ol>\n        <h6>Course <a href='#sm-conversation'>new message</a></h6>\n        <ol>\n          <li>Course title <span class='sm-unread-count'>3</span></li>\n          <li>Course title <span class='sm-unread-count'>1</span></li>\n          <li>Course title </li>\n        </ol>\n        <h6>Group <a href='#sm-conversation'>new message</a></h6>\n        <ol>\n          <li>Group title <span class='sm-unread-count'>5</span></li>\n          <li>Group title </li>\n          <li>Group title </li>\n        </ol>\n        </nav>";
 }
$cancelbtn = optional_param('cancelbtn', false, PARAM_ALPHA);
require_login();
if ($cancelbtn) {
    redirect('index.php');
    die;
} else {
    if ($sendbtn) {
        //$messagebody = optional_param('sm_message', false, PARAM_TEXT);
        $messagebody = optional_param('sm_message', false, PARAM_RAW);
        $recipients = optional_param_array('recipient', false, PARAM_INT);
        $url = 'index.php';
        if (!empty($recipients) && !empty($messagebody)) {
            $recipients[] = $USER->id;
            $recipients = array_flip($recipients);
            $recipients = array_keys($recipients);
            $conversation = local_simple_message_conversation::create_conversation($recipients);
            $conversation->send_message($USER->id, $messagebody);
            $url = 'index.php?conversation=' . $conversation->id . '#sm-conversation';
        }
        redirect($url);
        die;
    }
}
$PAGE->set_context($context);
//TODO:
// - set url (when selected a new conversation..)
// - title
// Initialize $PAGE
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('ui');
$PAGE->requires->jquery_plugin('ui-css');
Beispiel #3
0
$PAGE->requires->jquery_plugin('ui');
$PAGE->requires->jquery_plugin('ui-css');
$PAGE->requires->js(new moodle_url($CFG->wwwroot . '/local/simple_message/js/sm.js'));
// Import strings for dialog boxes
$PAGE->requires->string_for_js('cantsendempty', 'local_simple_message');
$PAGE->requires->string_for_js('wannadiscard', 'local_simple_message');
$PAGE->requires->string_for_js('wannadelete', 'local_simple_message');
// Initialize $PAGE
$PAGE->set_url('/local/simple_message/message.php');
$PAGE->set_title(get_string('title', 'local_simple_message'));
$PAGE->set_heading(get_string('title', 'local_simple_message'));
$renderer = $PAGE->get_renderer('local_simple_message');
/// Print the page header
echo $OUTPUT->header();
echo "<div id='sm-wrapper' class='clearfix'>";
echo $renderer->render_navigation();
if ($conversationid >= 0) {
    global $DB;
    if ($DB->count_records('sm_conversation_users', array('conversationid' => $conversationid, 'userid' => $USER->id)) == 0) {
        // no entry for current user in conversation, so user can't view messages
        error('You cannot view this conversation.');
    }
    $conversation = local_simple_message_conversation::find_converstation_by_id($conversationid);
    // print_r($conversation);
    echo $renderer->render_conversation($conversation);
    $conversation->update_last_read();
} else {
    echo $renderer->render_welcome_message();
}
echo "</div>";
echo $OUTPUT->footer();