bbb_plugin.class.php 6.6 KB

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