Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 124... Línea 124...
124
        }
124
        }
Línea 125... Línea 125...
125
 
125
 
126
        return $return;
126
        return $return;
Línea -... Línea 127...
-
 
127
    }
-
 
128
 
-
 
129
    #[\Override]
-
 
130
    public static function enable_plugin(string $pluginname, int $enabled): bool {
-
 
131
        $enabledfactors = array_map(fn($f) => $f->name, self::get_enabled_factors());
-
 
132
        $currentlyenabled = in_array($pluginname, $enabledfactors);
-
 
133
 
-
 
134
        // Determine if there's a change in the enabled status.
-
 
135
        if ($enabled && !$currentlyenabled) {
-
 
136
            $action = 'enable';
-
 
137
        } else if (!$enabled && $currentlyenabled) {
-
 
138
            $action = 'disable';
-
 
139
        } else {
-
 
140
            return false; // No change needed.
-
 
141
        }
-
 
142
 
-
 
143
        // Execute the configuration and action based on the determined action.
-
 
144
        \tool_mfa\manager::set_factor_config(['enabled' => $enabled], 'factor_' . $pluginname);
-
 
145
        \tool_mfa\manager::do_factor_action($pluginname, $action);
-
 
146
 
-
 
147
        \core\session\manager::gc(); // Remove stale sessions.
-
 
148
        \core_plugin_manager::reset_caches();
-
 
149
 
-
 
150
        return true;
127
    }
151
    }
128
 
152
 
129
    /**
153
    /**
130
     * Finds active factors for a user.
154
     * Finds active factors for a user.
131
     * If user is not specified, current user is used.
155
     * If user is not specified, current user is used.
Línea 254... Línea 278...
254
     * @param \part_of_admin_tree $adminroot
278
     * @param \part_of_admin_tree $adminroot
255
     * @param string $parentnodename
279
     * @param string $parentnodename
256
     * @param bool $hassiteconfig whether the current user has moodle/site:config capability
280
     * @param bool $hassiteconfig whether the current user has moodle/site:config capability
257
     */
281
     */
258
    public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig): void {
282
    public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig): void {
-
 
283
        global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
-
 
284
        /** @var \admin_root $ADMIN */
-
 
285
        $ADMIN = $adminroot; // May be used in settings.php.
-
 
286
        $plugininfo = $this; // Also can be used inside settings.php.
Línea 259... Línea 287...
259
 
287
 
260
        if (!$this->is_installed_and_upgraded()) {
288
        if (!$this->is_installed_and_upgraded()) {
261
            return;
289
            return;
Línea 267... Línea 295...
267
 
295
 
Línea 268... Línea 296...
268
        $section = $this->get_settings_section_name();
296
        $section = $this->get_settings_section_name();
Línea 269... Línea -...
269
 
-
 
270
        $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
297
 
271
 
-
 
Línea 272... Línea 298...
272
        if ($adminroot->fulltree) {
298
        $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
273
            include($this->full_path('settings.php'));
299
 
Línea 274... Línea 300...
274
        }
300
        include($this->full_path('settings.php'));
Línea 318... Línea 344...
318
     */
344
     */
319
    public function is_uninstall_allowed(): bool {
345
    public function is_uninstall_allowed(): bool {
320
        return $this->name !== 'nosetup';
346
        return $this->name !== 'nosetup';
321
    }
347
    }
Línea -... Línea 348...
-
 
348
 
-
 
349
    #[\Override]
-
 
350
    public static function plugintype_supports_disabling(): bool {
-
 
351
        return true;
-
 
352
    }
-
 
353
 
-
 
354
    #[\Override]
-
 
355
    public static function plugintype_supports_ordering(): bool {
-
 
356
        return true;
-
 
357
    }
322
 
358
 
323
    /**
359
    /**
324
     * Pre-uninstall hook.
360
     * Pre-uninstall hook.
325
     *
361
     *
326
     * This is intended for disabling of plugin, some DB table purging, etc.
362
     * This is intended for disabling of plugin, some DB table purging, etc.
Línea 381... Línea 417...
381
            return $factor->has_input();
417
            return $factor->has_input();
382
        }));
418
        }));
Línea 383... Línea 419...
383
 
419
 
384
        return $count > 1;
420
        return $count > 1;
-
 
421
    }
-
 
422
 
-
 
423
    #[\Override]
-
 
424
    public static function get_sorted_plugins(bool $enabledonly = false): ?array {
-
 
425
        $pluginmanager = \core_plugin_manager::instance();
-
 
426
        $plugins = $pluginmanager->get_plugins_of_type('factor');
-
 
427
        $orders = self::get_factors();
-
 
428
        $sortedplugins = [];
-
 
429
        foreach ($orders as $order) {
-
 
430
            $sortedplugins[$order->name] = $plugins[$order->name];
-
 
431
        }
-
 
432
 
-
 
433
        return $sortedplugins;
-
 
434
    }
-
 
435
 
-
 
436
    #[\Override]
-
 
437
    public static function change_plugin_order(string $pluginname, int $direction): bool {
-
 
438
        $activefactors = array_keys(self::get_sorted_plugins(true));
-
 
439
        $key = array_search($pluginname, $activefactors);
-
 
440
 
-
 
441
        if ($key === false) {
-
 
442
            return false;
-
 
443
        }
-
 
444
 
-
 
445
        if ($direction === self::MOVE_DOWN && $key < (count($activefactors) - 1)) {
-
 
446
            $action = 'down';
-
 
447
        } else if ($direction === self::MOVE_UP && $key >= 1) {
-
 
448
            $action = 'up';
-
 
449
        } else {
-
 
450
            return false;
-
 
451
        }
-
 
452
 
-
 
453
        \tool_mfa\manager::do_factor_action($pluginname, $action);
-
 
454
 
-
 
455
        \core\session\manager::gc(); // Remove stale sessions.
-
 
456
        \core_plugin_manager::reset_caches();
-
 
457
 
-
 
458
        return true;
385
    }
459
    }