$string['onlyfromme'] = 'Only messages from me';
$string['onlymycourses'] = 'Only in my courses';
$string['onlytome'] = 'Only messages to me';
+$string['outputdisabled'] = 'Output disabled';
+$string['outputdoesnotexist'] = 'Message output does not exists';
+$string['outputenabled'] = 'Output enabled';
+$string['outputnotavailable'] = 'Not available';
+$string['outputnotconfigured'] = 'Not configured';
$string['pagerefreshes'] = 'This page refreshes automatically every {$a} seconds';
+$string['permitted'] = 'Permitted';
+ $string['page-message-x'] = 'Any message pages';
$string['private_config'] = 'Popup message window';
$string['processortag'] = 'Destination';
$string['providers_config'] = 'Configure notification methods for incoming messages';
return $patterns;
}
-
-function my_pagetypelist($pagetype, $parentcontext = null, $currentcontext = null) {
-
-}
+ /**
+ * Given a specific page type, parent context and currect context, return all the page type patterns
+ * that might be used by this block.
+ *
+ * @param string $pagetype for example 'course-view-weeks' or 'mod-quiz-view'.
+ * @param stdClass $parentcontext Block's parent context
+ * @param stdClass $currentcontext Current context of block
+ * @return array an array of all the page type patterns that might match this page type.
+ */
+ function generate_page_type_patterns($pagetype, $parentcontext = null, $currentcontext = null) {
+ global $CFG;
+
+ $bits = explode('-', $pagetype);
+
+ $component = clean_param(reset($bits), PARAM_ALPHANUMEXT);
+ $function = 'default_pagetypelist';
+
+ $core = get_core_subsystems();
+ $plugins = get_plugin_types();
+
+ // First check to see if the initial component is a core component
+ // if its not check to see if it is a plugin component.
+ if (array_key_exists($component, $core) && !empty($core[$component])) {
+ $libfile = $CFG->dirroot.'/'.$core[$component].'/lib.php';
+ if (file_exists($libfile)) {
+ require_once($libfile);
+ if (function_exists($component.'_pagetypelist')) {
+ $function = $component.'_pagetypelist';
+ }
+ }
+ } else if (array_key_exists($component, $plugins) && !empty($plugins[$component])) {
+ $function = 'plugin_pagetypelist';
+ if (function_exists($component.'_pagetypelist')) {
+ $function = $component.'_pagetypelist';
+ }
+ }
+ // Call the most appropriate function we could determine
+ $patterns = $function($pagetype, $parentcontext, $currentcontext);
+ if (empty($patterns)) {
+ // If there are no patterns default to just the current pattern.
+ $patterns = array($pagetype => $pagetype);
+ }
+ return $patterns;
+ }
+
+ /**
+ * Generates a default page type list when a more appropriate callback cannot be decided upon.
+ *
+ * @param string $pagetype
+ * @param stdClass $parentcontext
+ * @param stdClass $currentcontext
+ * @return array
+ */
+ function default_pagetypelist($pagetype, $parentcontext = null, $currentcontext = null) {
+ // Generate page type patterns based on current page type if
+ // callbacks haven't been defined
+ $patterns = array($pagetype => $pagetype);
+ $bits = explode('-', $pagetype);
+ while (count($bits) > 0) {
+ $pattern = implode('-', $bits) . '-*';
+ $pagetypestringname = 'page-'.str_replace('*', 'x', $pattern);
+ // guessing page type description
+ if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
+ $patterns[$pattern] = get_string($pagetypestringname, 'pagetype');
+ } else {
+ $patterns[$pattern] = $pattern;
+ }
+ array_pop($bits);
+ }
+ $patterns['*'] = get_string('page-x', 'pagetype');
+ return $patterns;
+ }
+
+ /**
+ * Generates a page type list for plugins
+ *
+ * @param string $pagetype
+ * @param stdClass $parentcontext
+ * @param stdClass $currentcontext
+ * @return array
+ */
+ function plugin_pagetypelist($pagetype, $parentcontext = null, $currentcontext = null) {
+ global $CFG;
+
+ // for modules
+ $bits = explode('-', $pagetype);
+ $plugintype = $bits[0];
+ $pluginname = $bits[1];
+ $directory = get_plugin_directory($plugintype, $pluginname);
+ if (empty($directory)) {
+ return array();
+ }
+ $libfile = $directory.'/lib.php';
+ require_once($libfile);
+ $function = $pluginname.'_pagetypelist';
+ if (!function_exists($function)) {
+ return array();
+ }
+ $patterns = $function($pagetype, $parentcontext, $currentcontext);
+ if ($parentcontext->contextlevel == CONTEXT_COURSE) {
+ // including course page type
+ require_once("$CFG->dirroot/course/lib.php");
+ $patterns = array_merge(course_pagetypelist($pagetype, $parentcontext, $currentcontext), $patterns);
+ }
+ return $patterns;
+ }
+
+ /**
+ * Generates the page type list for a module by either locating and using the modules callback
+ * or by generating a default list.
+ *
+ * @param string $pagetype
+ * @param stdClass $parentcontext
+ * @param stdClass $currentcontext
+ * @return array
+ */
+ function mod_pagetypelist($pagetype, $parentcontext = null, $currentcontext = null) {
+ $patterns = plugin_pagetypelist($pagetype, $parentcontext, $currentcontext);
+ if (empty($patterns)) {
+ // if modules don't have callbacks
+ // generate two default page type patterns for modules only
+ $bits = explode('-', $pagetype);
+ $patterns = array($pagetype => $pagetype);
+ if ($bits[2] == 'view') {
+ $patterns['mod-*-view'] = get_string('page-mod-x-view', 'pagetype');
+ } else if ($bits[2] == 'index') {
+ $patterns['mod-*-index'] = get_string('page-mod-x-index', 'pagetype');
+ }
+ }
+ return $patterns;
+ }
/// Functions update the blocks if required by the request parameters ==========
/**
* @param string $ithcontexts
* @param moodle_url export file url
*/
-function question_make_export_url($contextid, $categoryid, $format, $withcategories, $withcontexts, $filename) {
+function question_make_export_url($contextid, $categoryid, $format, $withcategories,
+ $withcontexts, $filename) {
global $CFG;
$urlbase = "$CFG->httpswwwroot/pluginfile.php";
- return moodle_url::make_file_url($urlbase, "/$contextid/question/export/{$categoryid}/{$format}/{$withcategories}/{$withcontexts}/{$filename}", true);
+ return moodle_url::make_file_url($urlbase,
+ "/$contextid/question/export/{$categoryid}/{$format}/{$withcategories}" .
+ "/{$withcontexts}/{$filename}", true);
}
+
+ /**
+ * Return a list of page types
+ * @param string $pagetype current page type
+ * @param stdClass $parentcontext Block's parent context
+ * @param stdClass $currentcontext Current context of block
+ */
+ function question_pagetypelist($pagetype, $parentcontext, $currentcontext) {
+ global $CFG;
+ $types = array(
+ 'question-*'=>get_string('page-question-x', 'question'),
+ 'question-edit'=>get_string('page-question-edit', 'question'),
+ 'question-category'=>get_string('page-question-category', 'question'),
+ 'question-export'=>get_string('page-question-export', 'question'),
+ 'question-import'=>get_string('page-question-import', 'question')
+ );
+ if ($currentcontext->contextlevel == CONTEXT_COURSE) {
+ require_once($CFG->dirroot . '/course/lib.php');
+ return array_merge(course_pagetypelist($pagetype, $parentcontext, $currentcontext), $types);
+ } else {
+ return $types;
+ }
+ }
echo html_writer::end_tag('tr');
}
+/**
+ * Get all message processors, validate corresponding plugin existance and
+ * system configuration
+ *
+ * @param bool $ready only return ready-to-use processors
+ * @return mixed $processors array of objects containing information on message processors
+ */
+function get_message_processors($ready = false) {
+ global $DB, $CFG;
+
+ static $processors;
+
+ if (empty($processors)) {
+ // Get all processors, ensure the name column is the first so it will be the array key
+ $processors = $DB->get_records('message_processors', null, 'name DESC', 'name, id, enabled');
+ foreach ($processors as &$processor){
+ $processorfile = $CFG->dirroot. '/message/output/'.$processor->name.'/message_output_'.$processor->name.'.php';
+ if (is_readable($processorfile)) {
+ include_once($processorfile);
+ $processclass = 'message_output_' . $processor->name;
+ if (class_exists($processclass)) {
+ $pclass = new $processclass();
+ $processor->object = $pclass;
+ $processor->configured = 0;
+ if ($pclass->is_system_configured()) {
+ $processor->configured = 1;
+ }
+ $processor->hassettings = 0;
+ if (is_readable($CFG->dirroot.'/message/output/'.$processor->name.'/settings.php')) {
+ $processor->hassettings = 1;
+ }
+ $processor->available = 1;
+ } else {
+ print_error('errorcallingprocessor', 'message');
+ }
+ } else {
+ $processor->available = 0;
+ }
+ }
+ }
+ if ($ready) {
+ // Filter out enabled and system_configured processors
+ $readyprocessors = $processors;
+ foreach ($readyprocessors as $readyprocessor) {
+ if (!($readyprocessor->enabled && $readyprocessor->configured)) {
+ unset($readyprocessors[$readyprocessor->name]);
+ }
+ }
+ return $readyprocessors;
+ }
+
+ return $processors;
+}
+
+/**
+ * Get messaging outputs default (site) preferences
+ *
+ * @return object $processors object containing information on message processors
+ */
+function get_message_output_default_preferences() {
+ $preferences = get_config('message');
+ if (!$preferences) {
+ $preferences = new stdClass();
+ }
+ return $preferences;
+}
+
+/**
+ * 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
+ if ($processorname == 'email') {
+ $default = MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF;
+ } else {
+ $default = MESSAGE_PERMITTED;
+ }
+
+ // Validate the value. It should not exceed the maximum size
+ if (!is_int($plugindefault) || ($plugindefault > 0x0f)) {
+ $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);
+}
++
+ /**
+ * Return a list of page types
+ * @param string $pagetype current page type
+ * @param stdClass $parentcontext Block's parent context
+ * @param stdClass $currentcontext Current context of block
+ */
+ function message_pagetypelist($pagetype, $parentcontext, $currentcontext) {
+ return array('messages-*'=>get_string('page-message-x', 'message'));
+ }
$string['overrides'] = 'Overrides';
$string['overrideuser'] = 'Override user';
$string['overrideusereventname'] = '{$a->quiz} - Override';
+ $string['page-mod-quiz-x'] = 'Any quiz module page';
$string['pagesize'] = 'Attempts shown per page:';
-$string['paragraphquestion'] = 'Paragraph question not supported at line {$a}. The question will be ignored.';
$string['parent'] = 'Parent';
$string['parentcategory'] = 'Parent category';
$string['parsingquestions'] = 'Parsing questions from import file.';