bbb_plugin.class.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_global_conference_per_user' => 'boolean',
  43. 'enable_conference_in_course_groups' => 'boolean',
  44. 'enable_global_conference_link' => 'boolean'
  45. ]
  46. );
  47. $this->isAdminPlugin = true;
  48. }
  49. /**
  50. * @param string $variable
  51. * @return bool
  52. */
  53. public function validateCourseSetting($variable)
  54. {
  55. if ($variable === 'bbb_enable_conference_in_groups') {
  56. if ($this->get('enable_conference_in_course_groups') === 'true') {
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. }
  62. return true;
  63. }
  64. /**
  65. * @return BBBPlugin|null
  66. */
  67. public static function create()
  68. {
  69. static $result = null;
  70. return $result ? $result : $result = new self();
  71. }
  72. /**
  73. * Install
  74. */
  75. public function install()
  76. {
  77. $table = Database::get_main_table('plugin_bbb_meeting');
  78. $sql = "CREATE TABLE IF NOT EXISTS $table (
  79. id INT unsigned NOT NULL auto_increment PRIMARY KEY,
  80. c_id INT unsigned NOT NULL DEFAULT 0,
  81. group_id INT unsigned NOT NULL DEFAULT 0,
  82. user_id INT unsigned NOT NULL DEFAULT 0,
  83. meeting_name VARCHAR(255) NOT NULL DEFAULT '',
  84. attendee_pw VARCHAR(255) NOT NULL DEFAULT '',
  85. moderator_pw VARCHAR(255) NOT NULL DEFAULT '',
  86. record INT NOT NULL DEFAULT 0,
  87. status INT NOT NULL DEFAULT 0,
  88. created_at VARCHAR(255) NOT NULL,
  89. closed_at VARCHAR(255) NOT NULL,
  90. calendar_id INT DEFAULT 0,
  91. welcome_msg VARCHAR(255) NOT NULL DEFAULT '',
  92. session_id INT unsigned DEFAULT 0,
  93. remote_id CHAR(30),
  94. visibility TINYINT NOT NULL DEFAULT 1,
  95. voice_bridge INT NOT NULL DEFAULT 1,
  96. access_url INT NOT NULL DEFAULT 1,
  97. video_url TEXT NULL,
  98. has_video_m4v TINYINT NOT NULL DEFAULT 0
  99. )";
  100. Database::query($sql);
  101. Database::query(
  102. "CREATE TABLE IF NOT EXISTS plugin_bbb_room (
  103. id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  104. meeting_id int(10) unsigned NOT NULL,
  105. participant_id int(11) NOT NULL,
  106. in_at datetime NOT NULL,
  107. out_at datetime NOT NULL,
  108. FOREIGN KEY (meeting_id) REFERENCES plugin_bbb_meeting (id),
  109. FOREIGN KEY (participant_id) REFERENCES user (id)
  110. );"
  111. );
  112. // Installing course settings
  113. $this->install_course_fields_in_all_courses();
  114. }
  115. /**
  116. * Uninstall
  117. */
  118. public function uninstall()
  119. {
  120. $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  121. $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
  122. $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
  123. $variables = [
  124. 'bbb_salt',
  125. 'bbb_host',
  126. 'bbb_tool_enable',
  127. 'enable_global_conference',
  128. 'enable_global_conference_link',
  129. 'enable_conference_in_course_groups',
  130. 'bbb_plugin',
  131. 'bbb_plugin_host',
  132. 'bbb_plugin_salt'
  133. ];
  134. foreach ($variables as $variable) {
  135. $sql = "DELETE FROM $t_settings WHERE variable = '$variable'";
  136. Database::query($sql);
  137. }
  138. $sql = "DELETE FROM $t_options WHERE variable = 'bbb_plugin'";
  139. Database::query($sql);
  140. // hack to get rid of Database::query warning (please add c_id...)
  141. $sql = "DELETE FROM $t_tool WHERE name = 'bbb' AND c_id != 0";
  142. Database::query($sql);
  143. Database::query('DROP TABLE IF EXISTS plugin_bbb_room');
  144. $t = Database::get_main_table('plugin_bbb_meeting');
  145. $sql = "DROP TABLE IF EXISTS $t";
  146. Database::query($sql);
  147. // Deleting course settings
  148. $this->uninstall_course_fields_in_all_courses($this->course_settings);
  149. }
  150. }