bbb_plugin.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /* To show the plugin course icons you need to add these icons:
  4. * main/img/icons/22/plugin_name.png
  5. * main/img/icons/64/plugin_name.png
  6. * main/img/icons/64/plugin_name_na.png
  7. */
  8. /**
  9. * Videoconference plugin with BBB
  10. */
  11. //namespace Chamilo\Plugin\BBB;
  12. /**
  13. * Class BBBPlugin
  14. */
  15. class BBBPlugin extends Plugin
  16. {
  17. public $isCoursePlugin = true;
  18. // When creating a new course this settings are added to the course
  19. public $course_settings = [
  20. [
  21. 'name' => 'big_blue_button_record_and_store',
  22. 'type' => 'checkbox',
  23. ],
  24. [
  25. 'name' => 'bbb_enable_conference_in_groups',
  26. 'type' => 'checkbox',
  27. ]
  28. ];
  29. /**
  30. * BBBPlugin constructor.
  31. */
  32. protected function __construct()
  33. {
  34. parent::__construct(
  35. '2.5',
  36. 'Julio Montoya, Yannick Warnier, Angel Fernando Quiroz Campos',
  37. [
  38. 'tool_enable' => 'boolean',
  39. 'host' => 'text',
  40. 'salt' => 'text',
  41. 'enable_global_conference' => 'boolean',
  42. 'enable_conference_in_course_groups' => 'boolean',
  43. ]
  44. );
  45. $this->isAdminPlugin = true;
  46. }
  47. /**
  48. * @param string $variable
  49. * @return bool
  50. */
  51. public function validateCourseSetting($variable)
  52. {
  53. if ($variable == 'bbb_enable_conference_in_groups') {
  54. if ($this->get('enable_conference_in_course_groups') === 'true') {
  55. return true;
  56. } else {
  57. return false;
  58. }
  59. }
  60. return true;
  61. }
  62. /**
  63. * @return BBBPlugin|null
  64. */
  65. public static function create()
  66. {
  67. static $result = null;
  68. return $result ? $result : $result = new self();
  69. }
  70. /**
  71. * Install
  72. */
  73. public function install()
  74. {
  75. $table = Database::get_main_table('plugin_bbb_meeting');
  76. $sql = "CREATE TABLE IF NOT EXISTS $table (
  77. id INT unsigned NOT NULL auto_increment PRIMARY KEY,
  78. c_id INT unsigned NOT NULL DEFAULT 0,
  79. group_id INT unsigned NOT NULL DEFAULT 0,
  80. meeting_name VARCHAR(255) NOT NULL DEFAULT '',
  81. attendee_pw VARCHAR(255) NOT NULL DEFAULT '',
  82. moderator_pw VARCHAR(255) NOT NULL DEFAULT '',
  83. record INT NOT NULL DEFAULT 0,
  84. status INT NOT NULL DEFAULT 0,
  85. created_at VARCHAR(255) NOT NULL,
  86. closed_at VARCHAR(255) NOT NULL,
  87. calendar_id INT DEFAULT 0,
  88. welcome_msg VARCHAR(255) NOT NULL DEFAULT '',
  89. session_id INT unsigned DEFAULT 0,
  90. remote_id CHAR(30),
  91. visibility TINYINT NOT NULL DEFAULT 1,
  92. voice_bridge INT NOT NULL DEFAULT 1,
  93. video_url TEXT NULL,
  94. has_video_m4v TINYINT NOT NULL DEFAULT 0
  95. )";
  96. Database::query($sql);
  97. Database::query(
  98. "CREATE TABLE IF NOT EXISTS plugin_bbb_room (
  99. id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  100. meeting_id int(10) unsigned NOT NULL,
  101. participant_id int(11) NOT NULL,
  102. in_at datetime NOT NULL,
  103. out_at datetime NOT NULL,
  104. FOREIGN KEY (meeting_id) REFERENCES plugin_bbb_meeting (id),
  105. FOREIGN KEY (participant_id) REFERENCES user (id)
  106. );"
  107. );
  108. // Installing course settings
  109. $this->install_course_fields_in_all_courses();
  110. }
  111. /**
  112. * Uninstall
  113. */
  114. public function uninstall()
  115. {
  116. $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  117. $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
  118. $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
  119. $variables = [
  120. 'bbb_salt',
  121. 'bbb_host',
  122. 'bbb_tool_enable',
  123. 'enable_global_conference',
  124. 'enable_conference_in_course_groups',
  125. 'bbb_plugin',
  126. 'bbb_plugin_host',
  127. 'bbb_plugin_salt'
  128. ];
  129. foreach ($variables as $variable) {
  130. $sql = "DELETE FROM $t_settings WHERE variable = '$variable'";
  131. Database::query($sql);
  132. }
  133. $sql = "DELETE FROM $t_options WHERE variable = 'bbb_plugin'";
  134. Database::query($sql);
  135. // hack to get rid of Database::query warning (please add c_id...)
  136. $sql = "DELETE FROM $t_tool WHERE name = 'bbb' AND c_id != 0";
  137. Database::query($sql);
  138. $t = Database::get_main_table('plugin_bbb_room');
  139. $sql = "DROP TABLE IF EXISTS $t";
  140. Database::query($sql);
  141. $t = Database::get_main_table('plugin_bbb_meeting');
  142. $sql = "DROP TABLE IF EXISTS $t";
  143. Database::query($sql);
  144. Database::query('DROP TABLE IF EXISTS plugin_bbb_room');
  145. // Deleting course settings
  146. $this->uninstall_course_fields_in_all_courses($this->course_settings);
  147. }
  148. }