PENSPlugin.php 4.4 KB

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