_base.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org) and is released under the GNU GPL v3.
  3. /**
  4. * Defines the base class for all SLOODLE Plugins.
  5. *
  6. * @package sloodle
  7. * @copyright Copyright (c) 2009 Sloodle (various contributors)
  8. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. * @since Sloodle 0.4.1
  10. *
  11. * @contributor Peter R. Bloomfield
  12. *
  13. */
  14. /**
  15. * Base class for all SLOODLE plugins.
  16. * All SLOODLE plugins should be derived from this (directly or indirectly).
  17. * Specific plugin types will likely have their own base classes, which should be sub-classes of this.
  18. * For example, the Presenter has plugin base classes for "slide" and "import" plugins.
  19. * New plugins should be derived directly from those.
  20. *
  21. * Plugin classes should have names starting with "SloodlePlugin".
  22. * Make sure your class name does not conflict with any existing plugin classes, even if it is a different type of plugin.
  23. * Instantiating a plugin class should require no parameters, and should perform minimal processing. This is to allow the plugin loader to be as efficient as possible.
  24. *
  25. * @package sloodle
  26. */
  27. class SloodlePluginBase
  28. {
  29. // DATA //
  30. // OVERRIDABLE FUNCTIONS //
  31. // These are functions which can be overridden by sub-classes.
  32. /**
  33. * Gets the human-readable name of this plugin.
  34. * This MUST be overridden by base classes. If not, it will just return the name of the class.
  35. * @param string $lang Optional -- can specify the language we want the plugin name in, as an identifier like "en_utf8". If unspecified, then the current Moodle language should be used.
  36. * @access public
  37. * @return string The human-readable name of this plugin
  38. */
  39. function get_plugin_name($lang = null)
  40. {
  41. return strtolower(get_class($this));
  42. }
  43. /**
  44. * Gets the human-readable description of this plugin.
  45. * This should be overridden by base classes. If not, it will just return an empty string.
  46. * @param string $lang Optional -- can specify the language we want the description in, as an identifier like "en_utf8". If unspecified, then the current Moodle language should be used.
  47. * @access public
  48. * @return string The human-readable description of this plugin
  49. */
  50. function get_plugin_description($lang = null)
  51. {
  52. return '';
  53. }
  54. /**
  55. * Gets the identifier of this plugin.
  56. * This function MUST be overridden by sub-classes to return an ID that is unique to the category.
  57. * It is possible to have different plugins of the same ID in different categories.
  58. * This function is given a very explicitly sloodley name as it lets us ignore any classes which don't declare it.
  59. * @access public
  60. * @return string|bool The ID of this plugin, or boolean false if this is a base class and should not be instantiated as a plugin.
  61. */
  62. function sloodle_get_plugin_id()
  63. {
  64. return false;
  65. }
  66. /**
  67. * Gets the category to which this plugin belongs.
  68. * For example, Presenters have two plugin categories: slides, and importers.
  69. * This function must be overriden.
  70. * A useful approach would be to have a derived plugin base class for a particular category of plugins.
  71. * Each derived base class would report the appropriate category by overriding this function.
  72. * The actual plugin classes would simply have to inherit that derived base, without needing to specify their own category.
  73. * @access public
  74. * @return string The name of this category of plugin.
  75. */
  76. function get_category()
  77. {
  78. return 'base';
  79. }
  80. /**
  81. * Gets the internal version number of this plugin.
  82. * This MUST be overridden.
  83. * This should be a number like the internal version number for Moodle modules, containing the date and release number.
  84. * Format is: YYYYMMDD##.
  85. * For example, "2009012302" would be the 3rd release on the 23rd January 2009.
  86. * @return int The version number of this module.
  87. */
  88. function get_version()
  89. {
  90. return 0;
  91. }
  92. /**
  93. * Checks the compatibility of this plugin with the current installation.
  94. * Override this for any plugin which has non-standard requirements, such as relying on particular PHP extensions.
  95. * Note that the default (base class) implementation of this function returns true.
  96. * @return bool True if plugin is compatible, or false if not.
  97. */
  98. function check_compatibility()
  99. {
  100. return true;
  101. }
  102. /**
  103. * After check_compatibility() has been called, this function will return a string summarising the compatibility of the plugin.
  104. * For example, it may explain that a particular extension is being used, or that it could not be loaded.
  105. * @return string A summary of the compatibility of the plugin.
  106. */
  107. function get_compatibility_summary()
  108. {
  109. return '';
  110. }
  111. /**
  112. * Run a full compatibility test and output the results to the webpage.
  113. * @return void
  114. */
  115. function run_compatibility_test()
  116. {
  117. return get_string('nocompatibilityproblems', 'sloodle');
  118. }
  119. }
  120. ?>