PENSPlugin.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class PENSPlugin
  5. * This class is used to add an advanced subscription allowing the admin to
  6. * create user queues requesting a subscribe to a session
  7. * @package chamilo.plugin.pens
  8. */
  9. class PENSPlugin extends Plugin implements HookPluginInterface
  10. {
  11. protected $strings;
  12. private $errorMessages;
  13. const TABLE_PENS = 'plugin_pens';
  14. /**
  15. * Constructor
  16. */
  17. public function __construct()
  18. {
  19. $parameters = array(
  20. );
  21. parent::__construct($this->get_version(), $this->get_author(), $parameters);
  22. $this->errorMessages = array();
  23. }
  24. /**
  25. * Instance the plugin
  26. * @staticvar null $result
  27. * @return AdvancedSubscriptionPlugin
  28. */
  29. public static function create()
  30. {
  31. static $result = null;
  32. return $result ? $result : $result = new self();
  33. }
  34. /**
  35. * Install the plugin
  36. * @return void
  37. */
  38. public function install()
  39. {
  40. $this->installDatabase();
  41. $this->installHook();
  42. }
  43. /**
  44. * Uninstall the plugin
  45. * @return void
  46. */
  47. public function uninstall()
  48. {
  49. $setting = api_get_setting('plugin_pens');
  50. if (!empty($setting)) {
  51. $this->uninstallHook();
  52. // Note: Keeping area field data is intended so it will not be removed
  53. $this->uninstallDatabase();
  54. }
  55. }
  56. /**
  57. * Create the database tables for the plugin
  58. * @return void
  59. */
  60. private function installDatabase()
  61. {
  62. $pensTable = Database::get_main_table(PENSPlugin::TABLE_PENS);
  63. $sql = "CREATE TABLE $pensTable (
  64. id int unsigned NOT NULL auto_increment,
  65. pens_version varchar(255) NOT NULL,
  66. package_type varchar(255) NOT NULL,
  67. package_type_version varchar(255) NOT NULL,
  68. package_format varchar(255) NOT NULL,
  69. package_id varchar (255) NOT NULL,
  70. client varchar(255) NOT NULL,
  71. vendor_data text,
  72. package_name varchar(255) NOT NULL,
  73. created_at datetime NOT NULL,
  74. updated_at datetime NULL,
  75. PRIMARY KEY (id),
  76. UNIQUE KEY package_id (package_id)
  77. ";
  78. Database::query($sql);
  79. }
  80. /**
  81. * Drop the database tables for the plugin
  82. * @return void
  83. */
  84. private function uninstallDatabase()
  85. {
  86. /* Drop plugin tables */
  87. $pensTable = Database::get_main_table(PENSPlugin::TABLE_PENS);
  88. $sql = "DROP TABLE IF EXISTS $pensTable; ";
  89. Database::query($sql);
  90. /* Delete settings */
  91. $settingsTable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  92. Database::query("DELETE FROM $settingsTable WHERE subkey = 'plugin_pens'");
  93. }
  94. /**
  95. * Get the error messages list
  96. * @return array The message list
  97. */
  98. public function getErrorMessages()
  99. {
  100. return $this->errorMessages;
  101. }
  102. /**
  103. * This method will call the Hook management insertHook to add Hook observer from this plugin
  104. * @return int
  105. */
  106. public function installHook()
  107. {
  108. }
  109. /**
  110. * This method will call the Hook management deleteHook to disable Hook observer from this plugin
  111. * @return int
  112. */
  113. public function uninstallHook()
  114. {
  115. }
  116. /**
  117. * Copied and fixed from plugin.class.php
  118. * Returns the "system" name of the plugin in lowercase letters
  119. * @return string
  120. */
  121. public function get_name()
  122. {
  123. return 'PENS';
  124. }
  125. /**
  126. * Get author(s)
  127. * @return string
  128. */
  129. public function get_author()
  130. {
  131. return 'Guillaume Viguier-Just, Yannick Warnier';
  132. }
  133. /**
  134. * Returns the plugin version
  135. * @return string
  136. */
  137. public function get_version()
  138. {
  139. return '1.1';
  140. }
  141. /**
  142. * Get generic plugin info
  143. * @return array
  144. */
  145. public function get_info()
  146. {
  147. $result = array();
  148. $result['title'] = $this->get_name();
  149. $result['comment'] = 'Provides support for the PENS course exchange standard. Read the readme.txt file in the plugin/pens/ folder for a complete installation.';
  150. $result['version'] = $this->get_version();
  151. $result['author'] = $this->get_author();
  152. $result['plugin_class'] = get_class($this);
  153. $result['is_course_plugin'] = false;
  154. $result['is_mail_plugin'] = false;
  155. return $result;
  156. }
  157. }