bbb_plugin.class.php 7.5 KB

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