Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 308... Línea 308...
308
            return;
308
            return;
309
        }
309
        }
Línea 310... Línea 310...
310
 
310
 
Línea 311... Línea 311...
311
        $this->presentplugins = [];
311
        $this->presentplugins = [];
312
 
312
 
313
        $plugintypes = core_component::get_plugin_types();
313
        $allplugintypes = core_component::get_all_plugin_types();
314
        foreach ($plugintypes as $type => $typedir) {
314
        foreach ($allplugintypes as $type => $typedir) {
315
            $plugs = core_component::get_plugin_list($type);
315
            $plugs = core_component::get_all_plugins_list($type);
316
            foreach ($plugs as $plug => $fullplug) {
316
            foreach ($plugs as $plug => $fullplug) {
317
                $module = new stdClass();
317
                $module = new stdClass();
318
                $plugin = new stdClass();
318
                $plugin = new stdClass();
Línea 369... Línea 369...
369
    }
369
    }
Línea 370... Línea 370...
370
 
370
 
371
    /**
371
    /**
372
     * Returns a tree of known plugins and information about them
372
     * Returns a tree of known plugins and information about them
-
 
373
     *
373
     *
374
     * @param bool $includeindeprecation whether to include plugins which are in deprecation (deprecated or deleted status).
374
     * @return array 2D array. The first keys are plugin type names (e.g. qtype);
375
     * @return array 2D array. The first keys are plugin type names (e.g. qtype);
375
     *      the second keys are the plugin local name (e.g. multichoice); and
376
     *      the second keys are the plugin local name (e.g. multichoice); and
376
     *      the values are the corresponding objects extending {@link \core\plugininfo\base}
377
     *      the values are the corresponding objects extending {@link \core\plugininfo\base}
377
     */
378
     */
378
    public function get_plugins() {
379
    public function get_plugins(bool $includeindeprecation = false) {
Línea 379... Línea 380...
379
        $this->init_pluginsinfo_property();
380
        $this->init_pluginsinfo_property();
380
 
381
 
381
        // Make sure all types are initialised.
382
        // Make sure all types are initialised.
382
        foreach ($this->pluginsinfo as $plugintype => $list) {
383
        foreach ($this->pluginsinfo as $plugintype => $list) {
383
            if ($list === null) {
384
            if ($list === null) {
384
                $this->get_plugins_of_type($plugintype);
385
                $this->get_plugins_of_type($plugintype, $includeindeprecation);
Línea -... Línea 386...
-
 
386
            }
385
            }
387
        }
-
 
388
 
-
 
389
        if ($includeindeprecation) {
-
 
390
            return $this->pluginsinfo;
-
 
391
        }
386
        }
392
        return array_filter($this->pluginsinfo, function($key) {
Línea 387... Línea 393...
387
 
393
            return !core_component::is_plugintype_in_deprecation($key);
388
        return $this->pluginsinfo;
394
        }, ARRAY_FILTER_USE_KEY);
389
    }
395
    }
390
 
396
 
391
    /**
397
    /**
392
     * Returns list of known plugins of the given type.
398
     * Returns list of known plugins of the given type.
393
     *
399
     *
-
 
400
     * This method returns the subset of the tree returned by {@link self::get_plugins()}.
394
     * This method returns the subset of the tree returned by {@link self::get_plugins()}.
401
     * If the given type is not known, empty array is returned.
395
     * If the given type is not known, empty array is returned.
402
     *
396
     *
403
     * @param string $type plugin type, e.g. 'mod' or 'workshopallocation'
397
     * @param string $type plugin type, e.g. 'mod' or 'workshopallocation'
404
     * @param bool $includeindeprecation whether to include plugins which are in deprecation (deprecated or deleted status).
Línea 398... Línea 405...
398
     * @return \core\plugininfo\base[] (string) plugin name => corresponding subclass of {@link \core\plugininfo\base}
405
     * @return \core\plugininfo\base[] (string) plugin name => corresponding subclass of {@link \core\plugininfo\base}
Línea -... Línea 406...
-
 
406
     */
399
     */
407
    public function get_plugins_of_type($type, bool $includeindeprecation = false) {
400
    public function get_plugins_of_type($type) {
408
        global $CFG;
401
        global $CFG;
409
 
Línea 402... Línea 410...
402
 
410
        $this->init_pluginsinfo_property();
403
        $this->init_pluginsinfo_property();
411
 
404
 
412
        $exclude = !$includeindeprecation && core_component::is_plugintype_in_deprecation($type);
Línea 405... Línea 413...
405
        if (!array_key_exists($type, $this->pluginsinfo)) {
413
        if (!array_key_exists($type, $this->pluginsinfo) || $exclude) {
Línea 406... Línea 414...
406
            return [];
414
            return [];
407
        }
415
        }
408
 
416
 
409
        if (is_array($this->pluginsinfo[$type])) {
417
        if (is_array($this->pluginsinfo[$type])) {
410
            return $this->pluginsinfo[$type];
418
            return $this->pluginsinfo[$type];
411
        }
419
        }
Línea 412... Línea 420...
412
 
420
 
-
 
421
        $allplugintypes = core_component::get_all_plugin_types();
413
        $types = core_component::get_plugin_types();
422
 
-
 
423
        if (!isset($allplugintypes[$type])) {
414
 
424
            // Orphaned subplugins!
Línea 415... Línea 425...
415
        if (!isset($types[$type])) {
425
            $plugintypeclass = static::resolve_plugininfo_class($type);
416
            // Orphaned subplugins!
426
            $this->pluginsinfo[$type] = $plugintypeclass::get_plugins($type, null, $plugintypeclass, $this);
Línea 433... Línea 443...
433
        if (is_array($this->pluginsinfo)) {
443
        if (is_array($this->pluginsinfo)) {
434
            return;
444
            return;
435
        }
445
        }
436
        $this->pluginsinfo = [];
446
        $this->pluginsinfo = [];
Línea -... Línea 447...
-
 
447
 
-
 
448
        // The pluginsinfo instance var contains keys for all plugin types, including those currently in deprecation.
-
 
449
        // Other methods should filter their returns as needed, based on key checks, or by checking either
-
 
450
        // $plugininfo->is_deprecated() or $plugininfo->is_deleted().
437
 
451
        $plugintypes = array_merge(
-
 
452
            $this->get_plugin_types(),
-
 
453
            \core_component::get_deprecated_plugin_types(),
438
        $plugintypes = $this->get_plugin_types();
454
            \core_component::get_deleted_plugin_types()
439
 
455
        );
440
        foreach ($plugintypes as $plugintype => $plugintyperootdir) {
456
        foreach ($plugintypes as $plugintype => $plugintyperootdir) {
441
            $this->pluginsinfo[$plugintype] = null;
457
            $this->pluginsinfo[$plugintype] = null;
Línea 442... Línea 458...
442
        }
458
        }
443
 
459
 
444
        // Add orphaned subplugin types.
460
        // Add orphaned plugins.
445
        $this->load_installed_plugins();
461
        $this->load_installed_plugins();
446
        foreach ($this->installedplugins as $plugintype => $unused) {
462
        foreach ($this->installedplugins as $plugintype => $unused) {
447
            if (!isset($plugintypes[$plugintype])) {
463
            if (!isset($plugintypes[$plugintype])) {
Línea 455... Línea 471...
455
     *
471
     *
456
     * @param string $type
472
     * @param string $type
457
     * @return string name of pluginfo class for give plugin type
473
     * @return string name of pluginfo class for give plugin type
458
     */
474
     */
459
    public static function resolve_plugininfo_class($type) {
475
    public static function resolve_plugininfo_class($type) {
460
        $plugintypes = core_component::get_plugin_types();
476
        $allplugintypes = core_component::get_all_plugin_types();
-
 
477
 
461
        if (!isset($plugintypes[$type])) {
478
        if (!isset($allplugintypes[$type])) {
462
            return '\core\plugininfo\orphaned';
479
            return '\core\plugininfo\orphaned';
463
        }
480
        }
Línea 464... Línea 481...
464
 
481
 
Línea 554... Línea 571...
554
 
571
 
555
        $this->subpluginsinfo = [];
572
        $this->subpluginsinfo = [];
556
        foreach (core_component::get_plugin_types_with_subplugins() as $type => $ignored) {
573
        foreach (core_component::get_plugin_types_with_subplugins() as $type => $ignored) {
557
            foreach (core_component::get_plugin_list($type) as $plugin => $componentdir) {
574
            foreach (core_component::get_plugin_list($type) as $plugin => $componentdir) {
558
                $component = $type . '_' . $plugin;
575
                $component = $type . '_' . $plugin;
559
                $subplugins = core_component::get_subplugins($component);
576
                $subplugins = core_component::get_subplugins($component) ?? [];
560
                if (!$subplugins) {
577
                if (!$subplugins) {
561
                    continue;
578
                    continue;
562
                }
579
                }
563
                $this->subpluginsinfo[$component] = [];
580
                $this->subpluginsinfo[$component] = [];
Línea 576... Línea 593...
576
     * Returns the name of the plugin that defines the given subplugin type
593
     * Returns the name of the plugin that defines the given subplugin type
577
     *
594
     *
578
     * If the given subplugin type is not actually a subplugin, returns false.
595
     * If the given subplugin type is not actually a subplugin, returns false.
579
     *
596
     *
580
     * @param string $subplugintype the name of subplugin type, eg. workshopform or quiz
597
     * @param string $subplugintype the name of subplugin type, eg. workshopform or quiz
-
 
598
     * @param bool $includedeprecated whether to check deprecated subplugin types.
581
     * @return false|string the name of the parent plugin, eg. mod_workshop
599
     * @return false|string the name of the parent plugin, eg. mod_workshop
582
     */
600
     */
583
    public function get_parent_of_subplugin($subplugintype) {
601
    public function get_parent_of_subplugin($subplugintype, bool $includedeprecated = false) {
-
 
602
        if (!$includedeprecated && core_component::is_plugintype_in_deprecation($subplugintype)) {
-
 
603
            return false;
-
 
604
        }
584
        $parent = core_component::get_subtype_parent($subplugintype);
605
        $parent = core_component::get_subtype_parent($subplugintype);
585
        if (!$parent) {
606
        if (!$parent) {
586
            return false;
607
            return false;
587
        }
608
        }
588
        return $parent;
609
        return $parent;
Línea 655... Línea 676...
655
     * @param string $component frankenstyle component name.
676
     * @param string $component frankenstyle component name.
656
     * @return \core\plugininfo\base|null the corresponding plugin information.
677
     * @return \core\plugininfo\base|null the corresponding plugin information.
657
     */
678
     */
658
    public function get_plugin_info($component) {
679
    public function get_plugin_info($component) {
659
        [$type, $name] = core_component::normalize_component($component);
680
        [$type, $name] = core_component::normalize_component($component);
660
        $plugins = $this->get_plugins_of_type($type);
681
        $plugins = $this->get_plugins_of_type($type, true);
661
        if (isset($plugins[$name])) {
682
        if (isset($plugins[$name])) {
662
            return $plugins[$name];
683
            return $plugins[$name];
663
        } else {
684
        } else {
664
            return null;
685
            return null;
665
        }
686
        }
Línea 1699... Línea 1720...
1699
     * @return string|bool|null
1720
     * @return string|bool|null
1700
     */
1721
     */
1701
    public function get_plugintype_root($plugintype) {
1722
    public function get_plugintype_root($plugintype) {
Línea 1702... Línea 1723...
1702
 
1723
 
-
 
1724
        $plugintypepath = null;
1703
        $plugintypepath = null;
1725
        $allplugintypes = core_component::get_all_plugin_types();
1704
        foreach (core_component::get_plugin_types() as $type => $fullpath) {
1726
        foreach ($allplugintypes as $type => $fullpath) {
1705
            if ($type === $plugintype) {
1727
            if ($type === $plugintype) {
1706
                $plugintypepath = $fullpath;
1728
                $plugintypepath = $fullpath;
1707
                break;
1729
                break;
1708
            }
1730
            }