/**
  * This is function displays all user settings.
  *
  * @return int This function returns 0 always.
  *
  */
 private function view_settings()
 {
     global $USER;
     $inboxresult = block_course_message_get_mail_preference('inbox', $USER->id);
     $sentresult = block_course_message_get_mail_preference('sent', $USER->id);
     $displaypreference = block_course_message_get_display_preference($USER->id);
     echo json_encode(array('inbox' => $inboxresult, 'sent' => $sentresult, 'displaypreference' => $displaypreference));
     // TODO: remove the return value of 0 - no longer used.
     return 0;
 }
Example #2
0
/**
 * This function draws the settings view.  I think I should make it a little
 * bigger.
 *
 */
function display_settings()
{
    global $USER;
    echo '<div id="settingsview" style="display:none">';
    echo '<h2>' . get_string('settingslabel', BLOCK_CM_LANG_TABLE) . '</h2>';
    echo '<div id="sendemailsetting">';
    // Incoming Mail Setting.
    echo "<input type='checkbox' id='inboxemailsetting'";
    if (block_course_message_get_mail_preference('inbox', $USER->id)) {
        echo "checked='checked' /> &nbsp";
    } else {
        echo " /> &nbsp";
    }
    echo get_string('emailnewmail', BLOCK_CM_LANG_TABLE), ' ';
    echo '<br>';
    // Outgoing Mail Setting.
    echo "<input type='checkbox' id='sentemailsetting'";
    if (block_course_message_get_mail_preference('sent', $USER->id)) {
        echo "checked='checked' /> &nbsp";
    } else {
        echo " /> &nbsp";
    }
    echo get_string('copyofownmail', BLOCK_CM_LANG_TABLE), ' ';
    echo '<br><br>' . '<button id="submitsettings" type="button">' . get_string('submitbutton', BLOCK_CM_LANG_TABLE) . '</button>';
    echo '</div></div>';
}
 /**
  * This function tests the block_course_message_update_mail_preference() function.  It is quite simple
  * since the function itself is fairly straightforward.
  *
  */
 public function test_update_mail_preference()
 {
     $this->setUser($this->craig);
     // Make sure it is true (inbox setting).
     $this->assertTrue((bool) block_course_message_get_mail_preference('inbox', $this->craig->id));
     // Toggle to false.
     block_course_message_update_mail_preference('inbox', 'false');
     $this->assertFalse((bool) block_course_message_get_mail_preference('inbox', $this->craig->id));
     // Toggle back to true.
     block_course_message_update_mail_preference('inbox', 'true');
     $this->assertTrue((bool) block_course_message_get_mail_preference('inbox', $this->craig->id));
     // Make sure it is true (sent setting).
     $this->assertTrue((bool) block_course_message_get_mail_preference('sent', $this->craig->id));
     // Toggle to false.
     block_course_message_update_mail_preference('sent', 'false');
     $this->assertFalse((bool) block_course_message_get_mail_preference('sent', $this->craig->id));
     // Toggle back to true.
     block_course_message_update_mail_preference('sent', 'true');
     $this->assertTrue((bool) block_course_message_get_mail_preference('sent', $this->craig->id));
 }