本文整理汇总了PHP中core_plugin_manager类的典型用法代码示例。如果您正苦于以下问题:PHP core_plugin_manager类的具体用法?PHP core_plugin_manager怎么用?PHP core_plugin_manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了core_plugin_manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset_all_data
//.........这里部分代码省略.........
if ($detectchanges === true) {
if ($resetdb) {
$warnings[] = 'Warning: unexpected database modification, resetting DB state';
}
$oldcfg = self::get_global_backup('CFG');
$oldsite = self::get_global_backup('SITE');
foreach ($CFG as $k => $v) {
if (!property_exists($oldcfg, $k)) {
$warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
} else {
if ($oldcfg->{$k} !== $CFG->{$k}) {
$warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
}
}
unset($oldcfg->{$k});
}
if ($oldcfg) {
foreach ($oldcfg as $k => $v) {
$warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
if (ini_get('max_execution_time') != 0) {
// This is special warning for all resets because we do not want any
// libraries to mess with timeouts unintentionally.
// Our PHPUnit integration is not supposed to change it either.
if ($detectchanges !== false) {
$warnings[] = 'Warning: max_execution_time was changed to ' . ini_get('max_execution_time');
}
set_time_limit(0);
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$_GET = array();
$_POST = array();
$_FILES = array();
$_REQUEST = array();
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
// Empty sessison and set fresh new not-logged-in user.
\core\session\manager::init_empty_session();
// reset all static caches
\core\event\manager::phpunit_reset();
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches(true);
reset_text_filters_cache(true);
events_get_handlers('reset');
core_text::reset_caches();
get_message_processors(false, true);
filter_manager::reset_caches();
// Reset internal users.
core_user::reset_internal_users();
//TODO MDL-25290: add more resets here and probably refactor them to new core function
// Reset course and module caches.
if (class_exists('format_base')) {
// If file containing class is not loaded, there is no cache there anyway.
format_base::reset_course_cache(0);
}
get_fast_modinfo(0, 0, true);
// Reset other singletons.
if (class_exists('core_plugin_manager')) {
core_plugin_manager::reset_caches(true);
}
if (class_exists('\\core\\update\\checker')) {
\core\update\checker::reset_caches(true);
}
if (class_exists('\\core\\update\\deployer')) {
\core\update\deployer::reset_caches(true);
}
// purge dataroot directory
self::reset_dataroot();
// restore original config once more in case resetting of caches changed CFG
$CFG = self::get_global_backup('CFG');
// inform data generator
self::get_data_generator()->reset();
// fix PHP settings
error_reporting($CFG->debug);
// verify db writes just in case something goes wrong in reset
if (self::$lastdbwrites != $DB->perf_get_writes()) {
error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
self::$lastdbwrites = $DB->perf_get_writes();
}
if ($warnings) {
$warnings = implode("\n", $warnings);
trigger_error($warnings, E_USER_WARNING);
}
}
示例2: definition
protected function definition()
{
global $CFG, $OUTPUT;
$mform =& $this->_form;
$indicators = $this->_customdata['indicators'];
$mform->addElement('hidden', 'id', $this->_customdata['id']);
$mform->setType('id', PARAM_INT);
// TODO: general course-level report settings.
$mform->addElement('header', 'general', get_string('pluginname', 'report_engagement'));
$mform->addElement('header', 'weightings', get_string('weighting', 'report_engagement'));
$mform->addElement('static', 'weightings_desc', get_string('indicator', 'report_engagement'));
$mform->addHelpButton('weightings_desc', 'indicator', 'report_engagement');
foreach ($indicators as $name => $path) {
$grouparray = array();
$grouparray[] =& $mform->createElement('text', "weighting_{$name}", '', array('size' => 3));
$grouparray[] =& $mform->createElement('static', '', '', '%');
$mform->addGroup($grouparray, "weight_group_{$name}", get_string('pluginname', "engagementindicator_{$name}"), ' ', false);
$mform->addHelpButton("weight_group_{$name}", 'pluginname', "engagementindicator_{$name}");
$mform->setType("weighting_{$name}", PARAM_FLOAT);
}
$pluginman = core_plugin_manager::instance();
$instances = get_plugin_list('engagementindicator');
foreach ($indicators as $name => $path) {
$plugin = $pluginman->get_plugin_info('engagementindicator_' . $name);
$file = "{$CFG->dirroot}/mod/engagement/indicator/{$name}/thresholds_form.php";
if (file_exists($file) && $plugin->is_enabled()) {
require_once $file;
$class = "engagementindicator_{$name}_thresholds_form";
$subform = new $class();
$mform->addElement('header', 'general', get_string('pluginname', "engagementindicator_{$name}"));
$subform->definition_inner($mform);
}
}
$this->add_action_buttons();
}
示例3: __construct
/**
* Constructor.
* @throws Command_Exception.
*/
public function __construct()
{
global $DB, $STANDARD_PLUGIN_TYPES;
// Getting command description.
$cmd_name = vmoodle_get_string('cmdpluginsetupname', 'vmoodleadminset_plugins');
$cmd_desc = vmoodle_get_string('cmdpluginsetupdesc', 'vmoodleadminset_plugins');
$pm = \core_plugin_manager::instance();
$allplugins = $pm->get_plugins();
$pluginlist = array();
foreach ($allplugins as $type => $plugins) {
foreach ($plugins as $p) {
if (array_key_exists($type, $STANDARD_PLUGIN_TYPES)) {
$pluginlist[$type . '/' . $p->name] = $STANDARD_PLUGIN_TYPES[$type] . ' : ' . $p->displayname;
}
}
}
asort($pluginlist, SORT_STRING);
$plugin_param = new Command_Parameter('plugin', 'enum', vmoodle_get_string('pluginparamdesc', 'vmoodleadminset_plugins'), null, $pluginlist);
$states = array();
$states['enable'] = vmoodle_get_string('enable', 'vmoodleadminset_plugins');
$states['disable'] = vmoodle_get_string('disable', 'vmoodleadminset_plugins');
$state_param = new Command_Parameter('state', 'enum', vmoodle_get_string('pluginstateparamdesc', 'vmoodleadminset_plugins'), null, $states);
// Creating command.
parent::__construct($cmd_name, $cmd_desc, array($plugin_param, $state_param));
}
示例4: enable_plugin
/**
* Creates a new instance of the portfolio plugin
*
* @param string $name name of the instance
* @param stdClass $data config data for the instance
* @return portfolio_plugin_base
*/
protected function enable_plugin($name = 'Instance name', $data = null)
{
$data = $data ?: new stdClass();
$instance = portfolio_static_function($this->pluginname, 'create_instance', $this->pluginname, $name, $data);
core_plugin_manager::reset_caches();
return $instance;
}
示例5: get_filter_options
/**
* Retrieve the list of available filter options.
*
* @return array An array whose keys are the valid options
* And whose values are the values to display
*/
public static function get_filter_options()
{
$manager = \core_plugin_manager::instance();
$themes = $manager->get_installed_plugins('theme');
$options = [];
foreach (array_keys($themes) as $themename) {
try {
$theme = \theme_config::load($themename);
} catch (Exception $e) {
// Bad theme, just skip it for now.
continue;
}
if ($themename !== $theme->name) {
// Obsoleted or broken theme, just skip for now.
continue;
}
if ($theme->hidefromselector) {
// The theme doesn't want to be shown in the theme selector and as theme
// designer mode is switched off we will respect that decision.
continue;
}
$options[$theme->name] = get_string('pluginname', "theme_{$theme->name}");
}
return $options;
}
示例6: get_plugins
/**
* Gathers and returns the information about all plugins of the given type,
* either on disk or previously installed.
*
* @param string $type the name of the plugintype, eg. mod, auth or workshopform
* @param string $typerootdir full path to the location of the plugin dir
* @param string $typeclass the name of the actually called class
* @param core_plugin_manager $pluginman the plugin manager calling this method
* @return array of plugintype classes, indexed by the plugin name
*/
public static function get_plugins($type, $typerootdir, $typeclass, $pluginman)
{
$return = array();
$plugins = $pluginman->get_installed_plugins($type);
foreach ($plugins as $name => $version) {
$plugin = new $typeclass();
$plugin->type = $type;
$plugin->typerootdir = $typerootdir;
$plugin->name = $name;
$plugin->rootdir = null;
$plugin->displayname = $name;
$plugin->versiondb = $version;
$plugin->pluginman = $pluginman;
$plugin->init_is_standard();
$return[$name] = $plugin;
}
return $return;
}
示例7: execute
public function execute()
{
$manager = \core_plugin_manager::instance();
$types = $manager->get_plugin_types();
ksort($types);
foreach ($types as $type => $directory) {
echo $type . "," . $directory . "\n";
}
}
示例8: definition
public function definition()
{
$mform = $this->_form;
/** @var \core\task\scheduled_task $task */
$task = $this->_customdata;
$plugininfo = core_plugin_manager::instance()->get_plugin_info($task->get_component());
$plugindisabled = $plugininfo && $plugininfo->is_enabled() === false && !$task->get_run_if_component_disabled();
$lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : get_string('never');
$nextrun = $task->get_next_run_time();
if ($plugindisabled) {
$nextrun = get_string('plugindisabled', 'tool_task');
} else {
if ($task->get_disabled()) {
$nextrun = get_string('taskdisabled', 'tool_task');
} else {
if ($nextrun > time()) {
$nextrun = userdate($nextrun);
} else {
$nextrun = get_string('asap', 'tool_task');
}
}
}
$mform->addElement('static', 'lastrun', get_string('lastruntime', 'tool_task'), $lastrun);
$mform->addElement('static', 'nextrun', get_string('nextruntime', 'tool_task'), $nextrun);
$mform->addElement('text', 'minute', get_string('taskscheduleminute', 'tool_task'));
$mform->setType('minute', PARAM_RAW);
$mform->addHelpButton('minute', 'taskscheduleminute', 'tool_task');
$mform->addElement('text', 'hour', get_string('taskschedulehour', 'tool_task'));
$mform->setType('hour', PARAM_RAW);
$mform->addHelpButton('hour', 'taskschedulehour', 'tool_task');
$mform->addElement('text', 'day', get_string('taskscheduleday', 'tool_task'));
$mform->setType('day', PARAM_RAW);
$mform->addHelpButton('day', 'taskscheduleday', 'tool_task');
$mform->addElement('text', 'month', get_string('taskschedulemonth', 'tool_task'));
$mform->setType('month', PARAM_RAW);
$mform->addHelpButton('month', 'taskschedulemonth', 'tool_task');
$mform->addElement('text', 'dayofweek', get_string('taskscheduledayofweek', 'tool_task'));
$mform->setType('dayofweek', PARAM_RAW);
$mform->addHelpButton('dayofweek', 'taskscheduledayofweek', 'tool_task');
$mform->addElement('advcheckbox', 'disabled', get_string('disabled', 'tool_task'));
$mform->addHelpButton('disabled', 'disabled', 'tool_task');
$mform->addElement('advcheckbox', 'resettodefaults', get_string('resettasktodefaults', 'tool_task'));
$mform->addHelpButton('resettodefaults', 'resettasktodefaults', 'tool_task');
$mform->disabledIf('minute', 'resettodefaults', 'checked');
$mform->disabledIf('hour', 'resettodefaults', 'checked');
$mform->disabledIf('day', 'resettodefaults', 'checked');
$mform->disabledIf('dayofweek', 'resettodefaults', 'checked');
$mform->disabledIf('month', 'resettodefaults', 'checked');
$mform->disabledIf('disabled', 'resettodefaults', 'checked');
$mform->addElement('hidden', 'task', get_class($task));
$mform->setType('task', PARAM_RAW);
$mform->addElement('hidden', 'action', 'edit');
$mform->setType('action', PARAM_ALPHANUMEXT);
$this->add_action_buttons(true, get_string('savechanges'));
// Do not use defaults for existing values, the set_data() is the correct way.
$this->set_data(\core\task\manager::record_from_scheduled_task($task));
}
示例9: test_plugin_info
/**
* Tests the plugininfo class is present and working.
*/
public function test_plugin_info()
{
// This code will throw debugging information if the plugininfo class
// is missing. Unfortunately it doesn't actually cause the test to
// fail, but it's obvious when running test at least.
$pluginmanager = core_plugin_manager::instance();
$list = $pluginmanager->get_enabled_plugins('availability');
$this->assertEquals(array('completion', 'date', 'grade', 'group', 'grouping', 'profile'), array_keys($list));
}
示例10: create_target
/**
* Returns a target object, given a name.
*/
public static function create_target($name, $identifier = '')
{
// Sanity check.
$pluginman = \core_plugin_manager::instance();
$plugins = $pluginman->get_plugins_of_type('cattarget');
if (!isset($plugins[$name]) || $plugins[$name]->is_enabled() === false) {
throw new \moodle_exception("Invalid target.");
}
$target = "\\cattarget_{$name}\\{$name}";
return new $target($identifier);
}
示例11: create_rule
/**
* Return a rule object, given a name.
*/
public static function create_rule($name, $config = null)
{
// Sanity check.
$pluginman = \core_plugin_manager::instance();
$plugins = $pluginman->get_plugins_of_type('catrule');
if (!isset($plugins[$name]) || $plugins[$name]->is_enabled() === false) {
throw new \moodle_exception("Invalid rule.");
}
$ruletype = "\\catrule_{$name}\\{$name}";
return new $ruletype($config);
}
示例12: create_activity
/**
* Return a activity object, given a name.
*/
public static function create_activity($name, $data = '')
{
// Sanity check.
$pluginman = \core_plugin_manager::instance();
$plugins = $pluginman->get_plugins_of_type('catactivity');
if (!isset($plugins[$name]) || $plugins[$name]->is_enabled() === false) {
throw new \moodle_exception("Invalid activity.");
}
$activity = "\\catactivity_{$name}\\{$name}";
return new $activity($data);
}
示例13: scheduled_tasks_table
/**
* 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);
}
示例14: get_instantiable_plugins
/**
* Finds all plugins the user can instantiate in the context. The result may include missing plugins.
* Calls {@link \mod_dataform\plugininfo\dataformview::is_instantiable()}.
* Returns an associative list $pluginname => $pluginname, or null if no plugin is instantiable.
*
* @param context $context Either course or dataform (module) context.
* @return array|null
*/
public static function get_instantiable_plugins($context)
{
$return = array();
if (!($plugins = \core_plugin_manager::instance()->get_plugins_of_type('dataformview'))) {
return null;
}
foreach ($plugins as $name => $plugin) {
if ($plugin->is_instantiable($context)) {
$return[$name] = $name;
}
}
return $return;
}
示例15: get_supported_activities
/**
* Return a list of datatypes this target supports.
*
* @return array An array of valid datatypes.
*/
public function get_supported_activities()
{
$pluginman = \core_plugin_manager::instance();
$plugins = $pluginman->get_plugins_of_type('catactivity');
$rules = array();
foreach ($plugins as $plugin) {
if ($plugin->is_enabled() === false) {
continue;
}
$rules[] = $plugin->name;
}
return $rules;
}