PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/classes/plugininfo/qbehaviour.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 113 lines | 58 code | 14 blank | 41 comment | 12 complexity | f476237e55c9771a8d4d7a9ef6eead70 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Defines classes used for plugin info.
  18. *
  19. * @package core
  20. * @copyright 2011 David Mudrak <david@moodle.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. namespace core\plugininfo;
  24. use moodle_url, core_plugin_manager;
  25. defined('MOODLE_INTERNAL') || die();
  26. /**
  27. * Class for question behaviours.
  28. */
  29. class qbehaviour extends base {
  30. /**
  31. * Finds all enabled plugins, the result may include missing plugins.
  32. * @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
  33. */
  34. public static function get_enabled_plugins() {
  35. $plugins = core_plugin_manager::instance()->get_installed_plugins('qbehaviour');
  36. if (!$plugins) {
  37. return array();
  38. }
  39. if ($disabled = get_config('question', 'disabledbehaviours')) {
  40. $disabled = explode(',', $disabled);
  41. } else {
  42. $disabled = array();
  43. }
  44. $enabled = array();
  45. foreach ($plugins as $plugin => $version) {
  46. if (in_array($plugin, $disabled)) {
  47. continue;
  48. }
  49. $enabled[$plugin] = $plugin;
  50. }
  51. return $enabled;
  52. }
  53. public function is_uninstall_allowed() {
  54. global $DB;
  55. if ($this->name === 'missing') {
  56. // qbehaviour_missing is used by the system. It cannot be uninstalled.
  57. return false;
  58. }
  59. return !$DB->record_exists('question_attempts', array('behaviour' => $this->name));
  60. }
  61. /**
  62. * Pre-uninstall hook.
  63. *
  64. * This is intended for disabling of plugin, some DB table purging, etc.
  65. *
  66. * NOTE: to be called from uninstall_plugin() only.
  67. * @private
  68. */
  69. public function uninstall_cleanup() {
  70. if ($disabledbehaviours = get_config('question', 'disabledbehaviours')) {
  71. $disabledbehaviours = explode(',', $disabledbehaviours);
  72. $disabledbehaviours = array_unique($disabledbehaviours);
  73. } else {
  74. $disabledbehaviours = array();
  75. }
  76. if (($key = array_search($this->name, $disabledbehaviours)) !== false) {
  77. unset($disabledbehaviours[$key]);
  78. set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
  79. }
  80. if ($behaviourorder = get_config('question', 'behavioursortorder')) {
  81. $behaviourorder = explode(',', $behaviourorder);
  82. $behaviourorder = array_unique($behaviourorder);
  83. } else {
  84. $behaviourorder = array();
  85. }
  86. if (($key = array_search($this->name, $behaviourorder)) !== false) {
  87. unset($behaviourorder[$key]);
  88. set_config('behavioursortorder', implode(',', $behaviourorder), 'question');
  89. }
  90. parent::uninstall_cleanup();
  91. }
  92. /**
  93. * Return URL used for management of plugins of this type.
  94. * @return moodle_url
  95. */
  96. public static function get_manage_url() {
  97. return new moodle_url('/admin/qbehaviours.php');
  98. }
  99. }