Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 16... Línea 16...
16
namespace mod_bigbluebuttonbn;
16
namespace mod_bigbluebuttonbn;
Línea 17... Línea 17...
17
 
17
 
18
use cache;
18
use cache;
19
use cm_info;
19
use cm_info;
-
 
20
use mod_bigbluebuttonbn\local\extension\action_url_addons;
20
use mod_bigbluebuttonbn\local\extension\action_url_addons;
21
use mod_bigbluebuttonbn\local\extension\broker_meeting_events_addons;
21
use mod_bigbluebuttonbn\local\extension\custom_completion_addons;
22
use mod_bigbluebuttonbn\local\extension\custom_completion_addons;
22
use mod_bigbluebuttonbn\local\extension\mod_form_addons;
23
use mod_bigbluebuttonbn\local\extension\mod_form_addons;
23
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
24
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
24
use stdClass;
25
use stdClass;
-
 
26
use core_plugin_manager;
Línea 25... Línea 27...
25
use core_plugin_manager;
27
use core_component;
26
 
28
 
27
/**
29
/**
28
 * Generic subplugin management helper
30
 * Generic subplugin management helper
Línea 77... Línea 79...
77
     * @param array|null $newparameters additional parameters for the constructor.
79
     * @param array|null $newparameters additional parameters for the constructor.
78
     * @return array
80
     * @return array
79
     */
81
     */
80
    protected static function get_instances_implementing(string $classname, ?array $newparameters = []): array {
82
    protected static function get_instances_implementing(string $classname, ?array $newparameters = []): array {
81
        $classes = self::get_classes_implementing($classname);
83
        $classes = self::get_classes_implementing($classname);
82
        sort($classes); // Make sure all extension classes are returned in the same order. This is arbitrarily in
84
        ksort($classes); // Make sure all extension classes are returned in the correct order.
83
        // alphabetical order and depends on the classname but this one way to ensure consistency across calls.
-
 
84
        return array_map(function($targetclassname) use ($newparameters) {
85
        return array_map(function($targetclassname) use ($newparameters) {
85
            // If $newparameters is null, the constructor will be called without parameters.
86
            // If $newparameters is null, the constructor will be called without parameters.
86
            return new $targetclassname(...$newparameters);
87
            return new $targetclassname(...$newparameters);
87
        }, $classes);
88
        }, $classes);
88
    }
89
    }
Línea 97... Línea 98...
97
        // Get the class basename without Reflection API.
98
        // Get the class basename without Reflection API.
98
        $classnamecomponents = explode("\\", $classname);
99
        $classnamecomponents = explode("\\", $classname);
99
        $classbasename = end($classnamecomponents);
100
        $classbasename = end($classnamecomponents);
100
        $allsubs = core_plugin_manager::instance()->get_plugins_of_type(self::BBB_EXTENSION_PLUGIN_NAME);
101
        $allsubs = core_plugin_manager::instance()->get_plugins_of_type(self::BBB_EXTENSION_PLUGIN_NAME);
101
        $extensionclasses = [];
102
        $extensionclasses = [];
-
 
103
        $names = core_component::get_plugin_list(self::BBB_EXTENSION_PLUGIN_NAME);
-
 
104
        $sortedlist = self::get_sorted_plugins_list($names); // Make sure to use the most updated list.
-
 
105
        $sortedlist = array_flip($sortedlist);
102
        foreach ($allsubs as $sub) {
106
        foreach ($allsubs as $sub) {
103
            if (!$sub->is_enabled()) {
107
            if (!$sub->is_enabled()) {
104
                continue;
108
                continue;
105
            }
109
            }
106
            $targetclassname = "\\bbbext_{$sub->name}\\bigbluebuttonbn\\$classbasename";
110
            $targetclassname = "\\bbbext_{$sub->name}\\bigbluebuttonbn\\$classbasename";
Línea 109... Línea 113...
109
            }
113
            }
110
            if (!is_subclass_of($targetclassname, $classname)) {
114
            if (!is_subclass_of($targetclassname, $classname)) {
111
                debugging("The class $targetclassname should extend $classname in the subplugin {$sub->name}. Ignoring.");
115
                debugging("The class $targetclassname should extend $classname in the subplugin {$sub->name}. Ignoring.");
112
                continue;
116
                continue;
113
            }
117
            }
-
 
118
            if (!isset($sortedlist[$sub->name])) {
-
 
119
                debugging("The class $targetclassname does not belong to an existing subplugin. Ignoring");
-
 
120
                continue;
-
 
121
            }
-
 
122
            // Return all extension classes based on subplugin order on manage extension page.
-
 
123
            $sortorder = $sortedlist[$sub->name];
114
            $extensionclasses[] = $targetclassname;
124
            $extensionclasses[$sortorder] = $targetclassname;
115
        }
125
        }
116
        return $extensionclasses;
126
        return $extensionclasses;
117
    }
127
    }
Línea 118... Línea 128...
118
 
128
 
-
 
129
    /**
-
 
130
     * Return plugin list sorted according to order from admin extension manager.
-
 
131
     * @param array $names Array of plugin names
-
 
132
     * @return array The sorted list of plugins
-
 
133
     */
-
 
134
    public static function get_sorted_plugins_list(array $names): array {
-
 
135
        $result = [];
-
 
136
        foreach ($names as $name => $path) {
-
 
137
            $idx = get_config(self::BBB_EXTENSION_PLUGIN_NAME . '_' . $name, 'sortorder');
-
 
138
            if (!$idx) {
-
 
139
                $idx = 0;
-
 
140
            }
-
 
141
            while (array_key_exists($idx, $result)) {
-
 
142
                $idx += 1;
-
 
143
            }
-
 
144
            $result[$idx] = $name;
-
 
145
        }
-
 
146
        ksort($result);
-
 
147
        return $result;
-
 
148
    }
-
 
149
 
119
    /**
150
    /**
120
     * Get all custom_completion addons classes.
151
     * Get all custom_completion addons classes.
121
     *
152
     *
122
     * @return array of custom completion addon classes.
153
     * @return array of custom completion addon classes.
123
     */
154
     */
Línea 144... Línea 175...
144
     * @param stdClass|null $bigbluebuttondata
175
     * @param stdClass|null $bigbluebuttondata
145
     * @param string|null $suffix
176
     * @param string|null $suffix
146
     * @return array of custom completion addon classes instances
177
     * @return array of custom completion addon classes instances
147
     */
178
     */
148
    public static function mod_form_addons_instances(\MoodleQuickForm $mform, ?stdClass $bigbluebuttondata = null,
179
    public static function mod_form_addons_instances(\MoodleQuickForm $mform, ?stdClass $bigbluebuttondata = null,
149
        string $suffix = null): array {
180
        ?string $suffix = null): array {
150
        return self::get_instances_implementing(mod_form_addons::class, [$mform, $bigbluebuttondata, $suffix]);
181
        return self::get_instances_implementing(mod_form_addons::class, [$mform, $bigbluebuttondata, $suffix]);
151
    }
182
    }
Línea 152... Línea 183...
152
 
183
 
153
    /**
184
    /**
Línea 215... Línea 246...
215
        $formmanagersclasses = self::get_instances_implementing(mod_instance_helper::class);
246
        $formmanagersclasses = self::get_instances_implementing(mod_instance_helper::class);
216
        foreach ($formmanagersclasses as $fmclass) {
247
        foreach ($formmanagersclasses as $fmclass) {
217
            $fmclass->delete_instance($id);
248
            $fmclass->delete_instance($id);
218
        }
249
        }
219
    }
250
    }
-
 
251
 
-
 
252
    /**
-
 
253
     * Get all broker_meeting_events addons classes instances
-
 
254
     *
-
 
255
     * @param instance|null $instance
-
 
256
     * @param string|null $data
-
 
257
     * @return array of custom completion addon classes instances
-
 
258
     */
-
 
259
    public static function broker_meeting_events_addons_instances(instance $instance, string $data): array {
-
 
260
        return self::get_instances_implementing(broker_meeting_events_addons::class, [$instance, $data]);
-
 
261
    }
220
}
262
}