/** * Parse all callbacks and builds the tree. * * @param integer $user ID of the user for which the profile is displayed. * @param bool $iscurrentuser true if the profile being viewed is of current user, else false. * @param \stdClass $course Course object * * @return tree Fully build tree to be rendered on my profile page. */ public static function build_tree($user, $iscurrentuser, $course = null) { global $CFG; $tree = new tree(); // Add core nodes. require_once $CFG->libdir . "/myprofilelib.php"; core_myprofile_navigation($tree, $user, $iscurrentuser, $course); // Core components. $components = \core_component::get_core_subsystems(); foreach ($components as $component => $directory) { if (empty($directory)) { continue; } $file = $directory . "/lib.php"; if (is_readable($file)) { require_once $file; $function = "core_" . $component . "_myprofile_navigation"; if (function_exists($function)) { $function($tree, $user, $iscurrentuser, $course); } } } // Plugins. $types = \core_component::get_plugin_types(); foreach ($types as $type => $dir) { $pluginlist = get_plugin_list_with_function($type, "myprofile_navigation", "lib.php"); foreach ($pluginlist as $function) { $function($tree, $user, $iscurrentuser, $course); } } $tree->sort_categories(); return $tree; }
function definition() { global $CFG; $mform =& $this->_form; //$mform->addElement('html', get_string('unplagexplain', 'plagiarism_unplag')); $mform->addElement('checkbox', 'unplag_use', get_string('useunplag', 'plagiarism_unplag')); $mform->addElement('text', 'unplag_client_id', get_string('unplag_client_id', 'plagiarism_unplag')); $mform->addHelpButton('unplag_client_id', 'unplag_client_id', 'plagiarism_unplag'); $mform->addRule('unplag_client_id', null, 'required', null, 'client'); $mform->setType('unplag_client_id', PARAM_TEXT); $mform->addElement('text', 'unplag_api_secret', get_string('unplag_api_secret', 'plagiarism_unplag')); $mform->addHelpButton('unplag_api_secret', 'unplag_api_secret', 'plagiarism_unplag'); $mform->addRule('unplag_api_secret', null, 'required', null, 'client'); $mform->setType('unplag_api_secret', PARAM_TEXT); $mform->addElement('text', 'unplag_lang', get_string('unplag_lang', 'plagiarism_unplag')); $mform->addHelpButton('unplag_lang', 'unplag_lang', 'plagiarism_unplag'); $mform->addRule('unplag_lang', null, 'required', null, 'client'); $mform->setDefault('unplag_lang', 'en-US'); $mform->setType('unplag_lang', PARAM_TEXT); $mform->addElement('textarea', 'unplag_student_disclosure', get_string('studentdisclosure', 'plagiarism_unplag'), 'wrap="virtual" rows="6" cols="50"'); $mform->addHelpButton('unplag_student_disclosure', 'studentdisclosure', 'plagiarism_unplag'); $mform->setDefault('unplag_student_disclosure', get_string('studentdisclosuredefault', 'plagiarism_unplag')); $mform->setType('unplag_student_disclosure', PARAM_TEXT); $mods = core_component::get_plugin_list('mod'); foreach ($mods as $mod => $modname) { if (plugin_supports('mod', $mod, FEATURE_PLAGIARISM)) { $modstring = 'unplag_enable_mod_' . $mod; $mform->addElement('checkbox', $modstring, get_string('unplag_enableplugin', 'plagiarism_unplag', $mod)); } } $this->add_action_buttons(true); }
/** * Parse all callbacks and builds the tree. * * @param integer $user ID of the user for which the profile is displayed. * @param bool $iscurrentuser true if the profile being viewed is of current user, else false. * @param \stdClass $course Course object * * @return tree Fully build tree to be rendered on my profile page. */ public static function build_tree($user, $iscurrentuser, $course = null) { global $CFG; $tree = new tree(); //print_r($user); // Add core nodes. require_once $CFG->libdir . "/myprofilelib.php"; core_myprofile_navigation($tree, $user, $iscurrentuser, $course); // Core components. $components = \core_component::get_core_subsystems(); foreach ($components as $component => $directory) { if (empty($directory)) { continue; } $file = $directory . "/lib.php"; if (is_readable($file)) { require_once $file; $function = "core_" . $component . "_myprofile_navigation"; //print_r($function); if (function_exists($function)) { //echo "Current function: ".$function."<br>"; $function($tree, $user, $iscurrentuser, $course); } } } // Plugins. $pluginswithfunction = get_plugins_with_function('myprofile_navigation', 'lib.php'); foreach ($pluginswithfunction as $plugins) { foreach ($plugins as $function) { $function($tree, $user, $iscurrentuser, $course); } } $tree->sort_categories(); return $tree; }
/** * Returns instances of enrol plugins * @param bool $enabled return enabled only * @return array of enrol plugins name=>instance */ function enrol_get_plugins($enabled) { global $CFG; $result = array(); if ($enabled) { // sorted by enabled plugin order $enabled = explode(',', $CFG->enrol_plugins_enabled); $plugins = array(); foreach ($enabled as $plugin) { $plugins[$plugin] = "{$CFG->dirroot}/enrol/{$plugin}"; } } else { // sorted alphabetically $plugins = core_component::get_plugin_list('enrol'); ksort($plugins); } foreach ($plugins as $plugin => $location) { if (!file_exists("{$location}/lib.php")) { continue; } include_once "{$location}/lib.php"; $class = "enrol_{$plugin}_plugin"; if (!class_exists($class)) { continue; } $result[$plugin] = new $class(); } return $result; }
function scorm_report_list($context) { global $CFG; static $reportlist; if (!empty($reportlist)) { return $reportlist; } $installed = core_component::get_plugin_list('scormreport'); foreach ($installed as $reportname => $notused) { // Moodle 2.8+ style of autoloaded classes. $classname = "scormreport_{$reportname}\\report"; if (class_exists($classname)) { $report = new $classname(); if ($report->canview($context)) { $reportlist[] = $reportname; } continue; } // Legacy style of naming classes. $pluginfile = $CFG->dirroot . '/mod/scorm/report/' . $reportname . '/report.php'; if (is_readable($pluginfile)) { debugging("Please use autoloaded classnames for your plugin. Refer MDL-46469 for details", DEBUG_DEVELOPER); include_once $pluginfile; $reportclassname = "scorm_{$reportname}_report"; if (class_exists($reportclassname)) { $report = new $reportclassname(); if ($report->canview($context)) { $reportlist[] = $reportname; } } } } return $reportlist; }
public function test_get_course_formats() { $result = tool_uploadcourse_helper::get_course_formats(); $this->assertSame(array_keys(core_component::get_plugin_list('format')), $result); // Should be similar as first result, as cached. $this->assertSame($result, tool_uploadcourse_helper::get_course_formats()); }
/** * Given a component name, will load the list of tasks in the db/tasks.php file for that component. * * @param string $componentname - The name of the component to fetch the tasks for. * @return \core\task\scheduled_task[] - List of scheduled tasks for this component. */ public static function load_default_scheduled_tasks_for_component($componentname) { $dir = \core_component::get_component_directory($componentname); if (!$dir) { return array(); } $file = $dir . '/' . CORE_TASK_TASKS_FILENAME; if (!file_exists($file)) { return array(); } $tasks = null; include $file; if (!isset($tasks)) { return array(); } $scheduledtasks = array(); foreach ($tasks as $task) { $record = (object) $task; $scheduledtask = self::scheduled_task_from_record($record); // Safety check in case the task in the DB does not match a real class (maybe something was uninstalled). if ($scheduledtask) { $scheduledtask->set_component($componentname); $scheduledtasks[] = $scheduledtask; } } return $scheduledtasks; }
/** * Get the relative path for a plugin given it's type * * @param string $type * The plugin type (example: 'auth', 'block') * @param string $moodleversion * The version of moodle we are running (example: '1.9', '2.9') * @return string * The installation path relative to dirroot (example: 'auth', 'blocks', * 'course/format') */ private function get_install_path($type, $moodleversion) { global $CFG; // Convert moodle version to a float for more acurate comparison if (!is_float($moodleversion)) { $moodleversion = floatval($moodleversion); } if ($moodleversion >= 2.6) { $types = \core_component::get_plugin_types(); } else { if ($moodleversion >= 2.0) { $types = get_plugin_types(); } else { // Moodle 1.9 does not give us a way to determine plugin // installation paths. $types = array(); } } if (empty($types) || !array_key_exists($type, $types)) { // Either the moodle version is lower than 2.0, in which case we // don't have a reliable way of determining the install path, or the // plugin is of an unknown type. // // Let's fall back to make our best guess. return $CFG->dirroot . '/' . $type; } return $types[$type]; }
/** * Tests the backup and restore of single activity to same course (duplicate) * when it contains fields and views. */ public function test_duplicate() { global $DB, $CFG; $this->resetAfterTest(true); $this->setAdminUser(); $generator = $this->getDataGenerator(); $dataformgenerator = $generator->get_plugin_generator('mod_dataform'); // Create a course. $course = $generator->create_course(); // DATAFORM 1. $params = array('course' => $course->id, 'grade' => 100); $dataform1 = $dataformgenerator->create_instance($params); $df1 = mod_dataform_dataform::instance($dataform1->id); // Add fields. $fieldtypes = array_keys(core_component::get_plugin_list('dataformfield')); $fieldtypescount = count($fieldtypes); foreach ($fieldtypes as $type) { $df1->field_manager->add_field($type); } // Add views. $viewtypes = array_keys(core_component::get_plugin_list('dataformview')); $viewtypescount = count($viewtypes); foreach ($viewtypes as $type) { $df1->view_manager->add_view($type); } // Fetch the grade item. $params = array('itemtype' => 'mod', 'itemmodule' => 'dataform', 'iteminstance' => $dataform1->id, 'courseid' => $course->id, 'itemnumber' => 0); $gradeitem1 = grade_item::fetch($params); // Check number of dataforms. $this->assertEquals(1, $DB->count_records('dataform')); // Check number of fields. $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields')); $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform1->id))); // Check number of views. $this->assertEquals($viewtypescount, $DB->count_records('dataform_views')); $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform1->id))); // Check number of filters. // $this->assertEquals(2, $DB->count_records('dataform_filters')); // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform1->id)));. // DUPLICATE the dataform instance. $dataform2 = $dataformgenerator->duplicate_instance($course, $dataform1->cmid); // Check number of dataforms. $this->assertEquals(2, $DB->count_records('dataform')); // Check duplication of fields. $this->assertEquals($fieldtypescount * 2, $DB->count_records('dataform_fields')); $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform1->id))); $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform2->id))); // Check duplication of views. $this->assertEquals($viewtypescount * 2, $DB->count_records('dataform_views')); $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform1->id))); $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform2->id))); // Check number of filters. // $this->assertEquals(4, $DB->count_records('dataform_filters'); // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform1->id)); // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform2->id));. // Dataform cleanup. $dataformgenerator->delete_all_instances(); }
public function test_get_submission_plugins() { $this->setUser($this->editingteachers[0]); $assign = $this->create_instance(); $installedplugins = array_keys(core_component::get_plugin_list('assignsubmission')); foreach ($assign->get_submission_plugins() as $plugin) { $this->assertContains($plugin->get_type(), $installedplugins, 'Submission plugin not in list of installed plugins'); } }
/** * Test field events for standard types. */ public function test_field_events() { $this->setAdminUser(); $df = $this->get_a_dataform(); $fieldtypes = array_keys(core_component::get_plugin_list('dataformfield')); foreach ($fieldtypes as $type) { $this->try_crud_field($type, $df); } }
/** * Is this the last plugin in the list? * * @return bool */ public final function is_last() { $lastindex = count(core_component::get_plugin_list($this->get_subtype())) - 1; $currentindex = get_config($this->get_subtype() . '_' . $this->get_type(), 'sortorder'); if ($lastindex == $currentindex) { return true; } return false; }
/** * Returns a list of calendar typess available for use. * * @return array the list of calendar types */ public static function get_list_of_calendar_types() { $calendars = array(); $calendardirs = \core_component::get_plugin_list('calendartype'); foreach ($calendardirs as $name => $location) { $calendars[$name] = get_string('name', "calendartype_{$name}"); } return $calendars; }
/** * Returns detailed function information * * @param string|object $function name of external function or record from external_function * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * MUST_EXIST means throw exception if no record or multiple records found * @return stdClass description or false if not found or exception thrown * @since Moodle 2.0 */ function external_function_info($function, $strictness = MUST_EXIST) { global $DB, $CFG; if (!is_object($function)) { if (!($function = $DB->get_record('external_functions', array('name' => $function), '*', $strictness))) { return false; } } //first find and include the ext implementation class $function->classpath = empty($function->classpath) ? core_component::get_component_directory($function->component) . '/externallib.php' : $CFG->dirroot . '/' . $function->classpath; if (!file_exists($function->classpath)) { throw new coding_exception('Can not find file with external function implementation'); } require_once $function->classpath; $function->parameters_method = $function->methodname . '_parameters'; $function->returns_method = $function->methodname . '_returns'; // make sure the implementaion class is ok if (!method_exists($function->classname, $function->methodname)) { throw new coding_exception('Missing implementation method of ' . $function->classname . '::' . $function->methodname); } if (!method_exists($function->classname, $function->parameters_method)) { throw new coding_exception('Missing parameters description'); } if (!method_exists($function->classname, $function->returns_method)) { throw new coding_exception('Missing returned values description'); } // fetch the parameters description $function->parameters_desc = call_user_func(array($function->classname, $function->parameters_method)); if (!$function->parameters_desc instanceof external_function_parameters) { throw new coding_exception('Invalid parameters description'); } // fetch the return values description $function->returns_desc = call_user_func(array($function->classname, $function->returns_method)); // null means void result or result is ignored if (!is_null($function->returns_desc) and !$function->returns_desc instanceof external_description) { throw new coding_exception('Invalid return description'); } //now get the function description //TODO MDL-31115 use localised lang pack descriptions, it would be nice to have // easy to understand descriptions in admin UI, // on the other hand this is still a bit in a flux and we need to find some new naming // conventions for these descriptions in lang packs $function->description = null; $servicesfile = core_component::get_component_directory($function->component) . '/db/services.php'; if (file_exists($servicesfile)) { $functions = null; include $servicesfile; if (isset($functions[$function->name]['description'])) { $function->description = $functions[$function->name]['description']; } if (isset($functions[$function->name]['testclientpath'])) { $function->testclientpath = $functions[$function->name]['testclientpath']; } } return $function; }
/** * Do not instantinate this directly, use {@link grading_manager::get_controller()} * * @param stdClass $context the context of the form * @param string $component the frankenstyle name of the component * @param string $area the name of the gradable area * @param int $areaid the id of the gradable area record */ public function __construct(stdClass $context, $component, $area, $areaid) { global $DB; $this->context = $context; list($type, $name) = core_component::normalize_component($component); $this->component = $type . '_' . $name; $this->area = $area; $this->areaid = $areaid; $this->load_definition(); }
/** * This function will render one beautiful table with all the scheduled tasks. * * @param \core\task\scheduled_task[] $tasks - list of all scheduled tasks. * @return string HTML to output. */ public function scheduled_tasks_table($tasks) { global $CFG; $table = new html_table(); $table->head = array(get_string('name'), get_string('component', 'tool_task'), get_string('edit'), get_string('lastruntime', 'tool_task'), get_string('nextruntime', 'tool_task'), get_string('taskscheduleminute', 'tool_task'), get_string('taskschedulehour', 'tool_task'), get_string('taskscheduleday', 'tool_task'), get_string('taskscheduledayofweek', 'tool_task'), get_string('taskschedulemonth', 'tool_task'), get_string('faildelay', 'tool_task'), get_string('default', 'tool_task')); $table->attributes['class'] = 'admintable generaltable'; $data = array(); $yes = get_string('yes'); $no = get_string('no'); $never = get_string('never'); $asap = get_string('asap', 'tool_task'); $disabled = get_string('disabled', 'tool_task'); foreach ($tasks as $task) { $customised = $task->is_customised() ? $no : $yes; $lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : $never; $nextrun = $task->get_next_run_time(); if ($task->get_disabled()) { $nextrun = $disabled; } else { if ($nextrun > time()) { $nextrun = userdate($nextrun); } else { $nextrun = $asap; } } if (empty($CFG->preventscheduledtaskchanges)) { $configureurl = new moodle_url('/admin/tool/task/scheduledtasks.php', array('action' => 'edit', 'task' => get_class($task))); $editlink = $this->action_icon($configureurl, new pix_icon('t/edit', get_string('edittaskschedule', 'tool_task', $task->get_name()))); } else { $editlink = $this->render(new pix_icon('t/locked', get_string('scheduledtaskchangesdisabled', 'tool_task'))); } $namecell = new html_table_cell($task->get_name() . "\n" . html_writer::tag('span', '\\' . get_class($task), array('class' => 'task-class'))); $namecell->header = true; $component = $task->get_component(); list($type, $plugin) = core_component::normalize_component($component); if ($type === 'core') { $componentcell = new html_table_cell(get_string('corecomponent', 'tool_task')); } else { if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) { $plugininfo->init_display_name(); $componentcell = new html_table_cell($plugininfo->displayname); } else { $componentcell = new html_table_cell($component); } } $row = new html_table_row(array($namecell, $componentcell, new html_table_cell($editlink), new html_table_cell($lastrun), new html_table_cell($nextrun), new html_table_cell($task->get_minute()), new html_table_cell($task->get_hour()), new html_table_cell($task->get_day()), new html_table_cell($task->get_day_of_week()), new html_table_cell($task->get_month()), new html_table_cell($task->get_fail_delay()), new html_table_cell($customised))); if ($task->get_disabled()) { $row->attributes['class'] = 'disabled'; } $data[] = $row; } $table->data = $data; return html_writer::table($table); }
/** * Install the plugin. */ function xmldb_dataform_install() { // Enable existing field plugins. $type = 'dataformfield'; $enabled = array_keys(core_component::get_plugin_list($type)); set_config("enabled_{$type}", implode(',', $enabled), 'mod_dataform'); // Enable existing view plugins. $type = 'dataformview'; $enabled = array_keys(core_component::get_plugin_list($type)); set_config("enabled_{$type}", implode(',', $enabled), 'mod_dataform'); }
public function run($command) { global $CFG; $data = $CFG->dataroot . '/tool_composer'; $composerfile = $data . '/composer.json'; if (!is_writable($data)) { throw new \moodle_exception('notwritable'); } if (!file_exists($data)) { mkdir($data, $CFG->directorypermissions, true); } $vendordir = $data . '/vendor'; $autoloadphp = '$CFG->dataroot . \'tool_composer/vendor/autoload.php\''; if ($this->installincodebase) { $vendordir = $CFG->dirroot . '/lib/vendor'; $autoloadphp = '$CFG->dirroot . \'/lib/vendor/autoload.php\''; } $composer = new \stdClass(); $composer->require = ['wikimedia/composer-merge-plugin' => '^1.3']; $include = []; foreach (\core_component::get_plugin_types() as $type => $dir) { $plugins = \core_component::get_plugin_list_with_file($type, 'composer.json'); foreach ($plugins as $pluginname => $filepath) { // Ignore this plugin if ($type == 'tool' && $pluginname == 'composer') { continue; } $include[] = $filepath; // Overwrite the autoload files if necessary $autoload = dirname($filepath) . '/vendor/autoload.php'; if (file_exists($autoload)) { if (!is_writable($autoload)) { throw new \moodle_exception('notwritable'); } // Back up the file if we haven't done so already. if (!file_exists($autoload . '.bak')) { file_put_contents($autoload . '.bak', file_get_contents($autoload)); } file_put_contents($autoload, '<?php require_once ' . $autoloadphp . ';'); } } } $composer->extra = (object) ['merge-plugin' => (object) ['include' => $include]]; file_put_contents($composerfile, json_encode($composer)); putenv('COMPOSER=' . $composerfile); putenv('COMPOSER_VENDOR_DIR=' . $vendordir); if ($this->installincodebase) { // Allow us to install Moodle plugins into the codebase chdir($CFG->dirroot); } // TODO: We may want to force --no-dev here for install / update passthru('composer --no-interaction ' . $command); }
/** * Get the absolute install directory path within Moodle. * * @param string $component Moodle component, EG: mod_forum * * @return string Absolute path, EG: /path/to/mod/forum */ public function getComponentInstallDirectory($component) { $this->requireConfig(); /* @noinspection PhpUndefinedClassInspection */ list($type, $name) = \core_component::normalize_component($component); /* @noinspection PhpUndefinedClassInspection */ $types = \core_component::get_plugin_types(); if (!array_key_exists($type, $types)) { throw new \InvalidArgumentException(sprintf('The component %s has an unknown plugin type of %s', $component, $type)); } return $types[$type] . '/' . $name; }
/** * Test report_log_supports_logstore. */ public function test_report_participation_supports_logstore() { $logmanager = get_log_manager(); $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\\store'); $supportedstores = array('logstore_legacy' => '\\logstore_legacy\\log\\store', 'logstore_standard' => '\\logstore_standard\\log\\store'); // Make sure all supported stores are installed. $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); $stores = $logmanager->get_supported_logstores('report_outline'); $stores = array_keys($stores); foreach ($expectedstores as $expectedstore) { $this->assertContains($expectedstore, $stores); } }
/** * Returns an array of reports to which the current user has access to. * @return array reports are ordered as they should be for display in tabs. */ function rcontent_report_list() { global $DB; static $reportlist = null; if (!is_null($reportlist)) { return $reportlist; } $reportdirs = core_component::get_plugin_list('rcontent'); // Add any reports, which are on disc but not in the DB, on the end. foreach ($reportdirs as $reportname => $notused) { $reportlist[] = $reportname; } return $reportlist; }
/** * Get a list of services available in this Moodle installation. * * @return array plugin name => array('name' => '\class\implementing\service') */ public static function service_list() { global $CFG; $result = array(); foreach (\core_component::get_plugin_types() as $plugintype => $fulldir) { foreach (\core_component::get_plugin_list($plugintype) as $name => $dir) { $frankenstyle = $plugintype . '_' . $name; if ($services = self::get_services($frankenstyle)) { $result[$frankenstyle] = $services; } } } return $result; }
/** * Loads the events definitions for the component (from file). If no * events are defined for the component, we simply return an empty array. * * @access protected To be used from eventslib only * * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results' * @return array Array of capabilities or empty array if not exists */ function events_load_def($component) { global $CFG; if ($component === 'unittest') { $defpath = $CFG->dirroot . '/lib/tests/fixtures/events.php'; } else { $defpath = core_component::get_component_directory($component) . '/db/events.php'; } $handlers = array(); if (file_exists($defpath)) { require $defpath; } // make sure the definitions are valid and complete; tell devs what is wrong foreach ($handlers as $eventname => $handler) { if ($eventname === 'reset') { debugging("'reset' can not be used as event name."); unset($handlers['reset']); continue; } if (!is_array($handler)) { debugging("Handler of '{$eventname}' must be specified as array'"); unset($handlers[$eventname]); continue; } if (!isset($handler['handlerfile'])) { debugging("Handler of '{$eventname}' must include 'handlerfile' key'"); unset($handlers[$eventname]); continue; } if (!isset($handler['handlerfunction'])) { debugging("Handler of '{$eventname}' must include 'handlerfunction' key'"); unset($handlers[$eventname]); continue; } if (!isset($handler['schedule'])) { $handler['schedule'] = 'instant'; } if ($handler['schedule'] !== 'instant' and $handler['schedule'] !== 'cron') { debugging("Handler of '{$eventname}' must include valid 'schedule' type (instant or cron)'"); unset($handlers[$eventname]); continue; } if (!isset($handler['internal'])) { $handler['internal'] = 1; } $handlers[$eventname] = $handler; } return $handlers; }
public function definition() { $mform =& $this->_form; $mform->addElement('html', get_string('urkundexplain', 'plagiarism_urkund')); $mform->addElement('checkbox', 'urkund_use', get_string('useurkund', 'plagiarism_urkund')); $mform->addElement('text', 'urkund_api', get_string('urkund_api', 'plagiarism_urkund')); $mform->addHelpButton('urkund_api', 'urkund_api', 'plagiarism_urkund'); $mform->addRule('urkund_api', null, 'required', null, 'client'); $mform->setDefault('urkund_api', 'https://secure.urkund.com/api/submissions'); $mform->setType('urkund_api', PARAM_URL); $mform->addElement('text', 'urkund_username', get_string('urkund_username', 'plagiarism_urkund')); $mform->addHelpButton('urkund_username', 'urkund_username', 'plagiarism_urkund'); $mform->addRule('urkund_username', null, 'required', null, 'client'); $mform->setType('urkund_username', PARAM_TEXT); $mform->addElement('passwordunmask', 'urkund_password', get_string('urkund_password', 'plagiarism_urkund')); $mform->addHelpButton('urkund_password', 'urkund_password', 'plagiarism_urkund'); $mform->addRule('urkund_password', null, 'required', null, 'client'); $mform->setType('urkund_password', PARAM_TEXT); $mform->addElement('text', 'urkund_lang', get_string('urkund_lang', 'plagiarism_urkund')); $mform->addHelpButton('urkund_lang', 'urkund_lang', 'plagiarism_urkund'); $mform->addRule('urkund_lang', null, 'required', null, 'client'); $mform->setDefault('urkund_lang', 'en-US'); $mform->setType('urkund_lang', PARAM_TEXT); $mform->addElement('textarea', 'urkund_student_disclosure', get_string('studentdisclosure', 'plagiarism_urkund'), 'wrap="virtual" rows="6" cols="50"'); $mform->addHelpButton('urkund_student_disclosure', 'studentdisclosure', 'plagiarism_urkund'); $mform->setDefault('urkund_student_disclosure', get_string('studentdisclosuredefault', 'plagiarism_urkund')); $mform->setType('urkund_student_disclosure', PARAM_TEXT); $mform->addElement('checkbox', 'urkund_optout', get_string('urkund_enableoptout', 'plagiarism_urkund'), '<br/>' . get_string('urkund_enableoptoutdesc', 'plagiarism_urkund')); $mform->setDefault('urkund_optout', true); $mform->addElement('text', 'urkund_wordcount', get_string('wordcount', 'plagiarism_urkund')); $mform->addHelpButton('urkund_wordcount', 'wordcount', 'plagiarism_urkund'); $mform->setType('urkund_wordcount', PARAM_INT); $mform->addRule('urkund_wordcount', null, 'required', null, 'client'); $mform->setDefault('urkund_wordcount', '50'); $mods = core_component::get_plugin_list('mod'); foreach ($mods as $mod => $modname) { if (plugin_supports('mod', $mod, FEATURE_PLAGIARISM)) { $modstring = 'urkund_enable_mod_' . $mod; $mform->addElement('checkbox', $modstring, get_string('urkund_enableplugin', 'plagiarism_urkund', $mod)); if ($modname == 'assign') { $mform->setDefault($modstring, 1); } } } $this->add_action_buttons(true); }
/** * Test requirejs loader */ public function test_requirejs() { global $CFG; // Find a core module. $result = core_requirejs::find_one_amd_module('core', 'templates', false); $expected = ['core/templates' => $CFG->dirroot . '/lib/amd/build/templates.min.js']; $this->assertEquals($expected, $result); $result = core_requirejs::find_one_amd_module('core', 'templates', true); $expected = ['core/templates' => $CFG->dirroot . '/lib/amd/src/templates.js']; $this->assertEquals($expected, $result); // Find a subsystem module (none exist yet). $result = core_requirejs::find_one_amd_module('core_group', 'doesnotexist', false); $expected = []; $this->assertEquals($expected, $result); // Find a plugin module. $result = core_requirejs::find_one_amd_module('mod_assign', 'grading_panel', true); $expected = ['mod_assign/grading_panel' => $CFG->dirroot . '/mod/assign/amd/src/grading_panel.js']; $this->assertEquals($expected, $result); // Find all modules - no debugging. $result = core_requirejs::find_all_amd_modules(true); foreach ($result as $key => $path) { // Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not. list($component, $template) = explode('/', $key, 2); // Can we resolve it to a valid dir? $dir = core_component::get_component_directory($component); $this->assertNotEmpty($dir); // Only "core" is allowed to have no _ in component names. if (strpos($component, '_') === false) { $this->assertEquals('core', $component); } $this->assertNotContains('.min', $path); } // Find all modules - debugging. $result = core_requirejs::find_all_amd_modules(false); foreach ($result as $key => $path) { // Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not. list($component, $template) = explode('/', $key, 2); $dir = core_component::get_component_directory($component); $this->assertNotEmpty($dir); // Only "core" is allowed to have no _ in component names. if (strpos($component, '_') === false) { $this->assertEquals('core', $component); } $this->assertContains('.min', $path); } }
public function load_choices() { if (is_array($this->choices)) { return true; } $this->choices = array('mathjax' => get_string('settingmathsdisplay_mathjax', 'qtype_stack')); // Remove this if statement once we no longer need to support Moodle 2.5.x. if (class_exists('core_component') && method_exists('core_component', 'get_plugin_list_with_file')) { $filters = core_component::get_plugin_list_with_file('filter', 'filter.php'); } else { $filters = get_plugin_list_with_file('filter', 'filter.php'); } if (array_key_exists('tex', $filters)) { $this->choices['tex'] = get_string('settingmathsdisplay_tex', 'qtype_stack'); } if (array_key_exists('maths', $filters)) { $this->choices['maths'] = get_string('settingmathsdisplay_maths', 'qtype_stack'); } return true; }
/** * Load all the blocks information needed for a given path within moodle2 backup * * This function, given one full path (course, activities/xxxx) will look for all the * blocks existing in the backup file, returning one array used to build the * proper restore plan by the @restore_plan_builder */ public static function get_blocks_from_path($path) { global $DB; $blocks = array(); // To return results static $availableblocks = array(); // Get and cache available blocks if (empty($availableblocks)) { $availableblocks = array_keys(core_component::get_plugin_list('block')); } $path = $path . '/blocks'; // Always look under blocks subdir if (!is_dir($path)) { return array(); } if (!($dir = opendir($path))) { return array(); } while (false !== ($file = readdir($dir))) { if ($file == '.' || $file == '..') { // Skip dots continue; } if (is_dir($path . '/' . $file)) { // Dir found, check it's a valid block if (!file_exists($path . '/' . $file . '/block.xml')) { // Skip if xml file not found continue; } // Extract block name $blockname = preg_replace('/(.*)_\\d+/', '\\1', $file); // Check block exists and is installed if (in_array($blockname, $availableblocks) && $DB->record_exists('block', array('name' => $blockname))) { $blocks[$path . '/' . $file] = $blockname; } } } closedir($dir); return $blocks; }
function scorm_report_list($context) { global $CFG; static $reportlist; if (!empty($reportlist)) { return $reportlist; } $installed = core_component::get_plugin_list('scormreport'); foreach ($installed as $reportname => $notused) { $pluginfile = $CFG->dirroot . '/mod/scorm/report/' . $reportname . '/report.php'; if (is_readable($pluginfile)) { include_once $pluginfile; $reportclassname = "scorm_{$reportname}_report"; if (class_exists($reportclassname)) { $report = new $reportclassname(); if ($report->canview($context)) { $reportlist[] = $reportname; } } } } return $reportlist; }
/** * Given a component name, will load the list of tasks in the db/tasks.php file for that component. * * @param string $componentname - The name of the component to fetch the tasks for. * @return \core\task\scheduled_task[] - List of scheduled tasks for this component. */ public static function load_default_scheduled_tasks_for_component($componentname) { $dir = \core_component::get_component_directory($componentname); if (!$dir) { return array(); } $file = $dir . '/' . CORE_TASK_TASKS_FILENAME; if (!file_exists($file)) { return array(); } $tasks = null; require_once $file; if (!isset($tasks)) { return array(); } $scheduledtasks = array(); foreach ($tasks as $task) { $record = (object) $task; $scheduledtask = self::scheduled_task_from_record($record); $scheduledtask->set_component($componentname); $scheduledtasks[] = $scheduledtask; } return $scheduledtasks; }
public function definition() { $mform = $this->_form; $behaviour = array('deferredfeedback' => 'Deferred feedback', 'adaptive' => 'Adaptive', 'adaptivenopenalty' => 'Adaptive (no penalties)'); $qtypes = core_component::get_plugin_list('qtype'); foreach ($qtypes as $qtype => $notused) { $qtypes[$qtype] = get_string('pluginname', 'qtype_' . $qtype); } $mform->addElement('header', 'h1', 'Either extract a specific question_session'); $mform->addElement('text', 'attemptid', 'Quiz attempt id', array('size' => '10')); $mform->setType('attemptid', PARAM_INT); $mform->addElement('text', 'questionid', 'Question id', array('size' => '10')); $mform->setType('questionid', PARAM_INT); $mform->addElement('header', 'h2', 'Or find and extract an example by type'); $mform->addElement('select', 'behaviour', 'Behaviour', $behaviour); $mform->setType('behaviour', PARAM_ALPHA); $mform->addElement('text', 'statehistory', 'State history', array('size' => '10')); $mform->setType('statehistory', PARAM_RAW); $mform->addElement('select', 'qtype', 'Question type', $qtypes); $mform->setType('qtype', PARAM_PLUGIN); $mform->addElement('text', 'extratests', 'Extra conditions', array('size' => '50')); $mform->setType('extratests', PARAM_RAW); $this->add_action_buttons(false, 'Create test case'); }