예제 #1
0
파일: lib.php 프로젝트: nickbert77/moodle
/**
 * Translate message default settings from binary value to the array of string
 * representing the settings to be stored. Also validate the provided value and
 * use default if it is malformed.
 *
 * @param  int    $plugindefault Default setting suggested by plugin
 * @param  string $processorname The name of processor
 * @return array  $settings array of strings in the order: $permitted, $loggedin, $loggedoff.
 */
function translate_message_default_setting($plugindefault, $processorname) {
    // Preset translation arrays
    $permittedvalues = array(
        0x04 => 'disallowed',
        0x08 => 'permitted',
        0x0c => 'forced',
    );

    $loggedinstatusvalues = array(
        0x00 => null, // use null if loggedin/loggedoff is not defined
        0x01 => 'loggedin',
        0x02 => 'loggedoff',
    );

    // define the default setting
    $processor = get_message_processor($processorname);
    $default = $processor->get_default_messaging_settings();

    // Validate the value. It should not exceed the maximum size
    if (!is_int($plugindefault) || ($plugindefault > 0x0f)) {
        debugging(get_string('errortranslatingdefault', 'message'));
        $plugindefault = $default;
    }
    // Use plugin default setting of 'permitted' is 0
    if (!($plugindefault & MESSAGE_PERMITTED_MASK)) {
        $plugindefault = $default;
    }

    $permitted = $permittedvalues[$plugindefault & MESSAGE_PERMITTED_MASK];
    $loggedin = $loggedoff = null;

    if (($plugindefault & MESSAGE_PERMITTED_MASK) == MESSAGE_PERMITTED) {
        $loggedin = $loggedinstatusvalues[$plugindefault & MESSAGE_DEFAULT_LOGGEDIN];
        $loggedoff = $loggedinstatusvalues[$plugindefault & MESSAGE_DEFAULT_LOGGEDOFF];
    }

    return array($permitted, $loggedin, $loggedoff);
}
예제 #2
0
파일: lib.php 프로젝트: EsdrasCaleb/moodle
/**
 * Handles displaying processor settings in a fragment.
 *
 * @param array $args
 * @return bool|string
 * @throws moodle_exception
 */
function message_output_fragment_processor_settings($args = []) {
    global $PAGE;

    if (!isset($args['type'])) {
        throw new moodle_exception('Must provide a processor type');
    }

    if (!isset($args['userid'])) {
        throw new moodle_exception('Must provide a userid');
    }

    $type = $args['type'];
    $userid = $args['userid'];

    $user = core_user::get_user($userid, '*', MUST_EXIST);
    $processor = get_message_processor($type);
    $providers = message_get_providers_for_user($userid);
    $processorwrapper = new stdClass();
    $processorwrapper->object = $processor;
    $preferences = \core_message\api::get_all_message_preferences([$processorwrapper], $providers, $user);

    $processoroutput = new \core_message\output\preferences\processor($processor, $preferences, $user, $type);
    $renderer = $PAGE->get_renderer('core', 'message');

    return $renderer->render_from_template('core_message/preferences_processor', $processoroutput->export_for_template($renderer));
}
예제 #3
0
파일: lib.php 프로젝트: hatone/moodle
/**
 * Translate message default settings from binary value to the array of string
 * representing the settings to be stored. Also validate the provided value and
 * use default if it is malformed.
 *
 * @param  int    $plugindefault Default setting suggested by plugin
 * @param  string $processorname The name of processor
 * @return array  $settings array of strings in the order: $permitted, $loggedin, $loggedoff.
 */
function translate_message_default_setting($plugindefault, $processorname)
{
    // Preset translation arrays
    $permittedvalues = array(0x4 => 'disallowed', 0x8 => 'permitted', 0xc => 'forced');
    $loggedinstatusvalues = array(0x0 => null, 0x1 => 'loggedin', 0x2 => 'loggedoff');
    // define the default setting
    $processor = get_message_processor($processorname);
    $default = $processor->get_default_messaging_settings();
    // Validate the value. It should not exceed the maximum size
    if (!is_int($plugindefault) || $plugindefault > 0xf) {
        $OUTPUT->notification(get_string('errortranslatingdefault', 'message'), 'notifyproblem');
        $plugindefault = $default;
    }
    // Use plugin default setting of 'permitted' is 0
    if (!($plugindefault & MESSAGE_PERMITTED_MASK)) {
        $plugindefault = $default;
    }
    $permitted = $permittedvalues[$plugindefault & MESSAGE_PERMITTED_MASK];
    $loggedin = $loggedoff = null;
    if (($plugindefault & MESSAGE_PERMITTED_MASK) == MESSAGE_PERMITTED) {
        $loggedin = $loggedinstatusvalues[$plugindefault & MESSAGE_DEFAULT_LOGGEDIN];
        $loggedoff = $loggedinstatusvalues[$plugindefault & MESSAGE_DEFAULT_LOGGEDOFF];
    }
    return array($permitted, $loggedin, $loggedoff);
}
예제 #4
0
 /**
  * Get a message processor.
  *
  * @param int $userid
  * @param string $name the name of the processor
  * @return external_description
  * @throws moodle_exception
  * @since 3.2
  */
 public static function get_message_processor($userid = 0, $name)
 {
     global $USER, $PAGE, $CFG;
     // Check if messaging is enabled.
     if (empty($CFG->messaging)) {
         throw new moodle_exception('disabled', 'message');
     }
     $params = self::validate_parameters(self::get_message_processor_parameters(), array('userid' => $userid, 'name' => $name));
     if (empty($params['userid'])) {
         $params['userid'] = $USER->id;
     }
     $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
     core_user::require_active_user($user);
     self::validate_context(context_user::instance($params['userid']));
     $processor = get_message_processor($name);
     $processoroutput = new \core_message\output\processor($processor, $user);
     $renderer = $PAGE->get_renderer('core_message');
     return $processoroutput->export_for_template($renderer);
 }