bbb_plugin.class.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. /**
  12. * Class BBBPlugin
  13. */
  14. class BBBPlugin extends Plugin
  15. {
  16. const INTERFACE_FLASH = 0;
  17. const INTERFACE_HTML5 = 1;
  18. const LAUNCH_TYPE_DEFAULT = 0;
  19. const LAUNCH_TYPE_SET_BY_TEACHER = 1;
  20. const LAUNCH_TYPE_SET_BY_STUDENT = 2;
  21. public $isCoursePlugin = true;
  22. // When creating a new course this settings are added to the course
  23. public $course_settings = [
  24. [
  25. 'name' => 'big_blue_button_record_and_store',
  26. 'type' => 'checkbox',
  27. ],
  28. [
  29. 'name' => 'bbb_enable_conference_in_groups',
  30. 'type' => 'checkbox',
  31. ],
  32. [
  33. 'name' => 'bbb_force_record_generation',
  34. 'type' => 'checkbox',
  35. ]
  36. ];
  37. /**
  38. * BBBPlugin constructor.
  39. */
  40. protected function __construct()
  41. {
  42. parent::__construct(
  43. '2.8.1',
  44. 'Julio Montoya, Yannick Warnier, Angel Fernando Quiroz Campos',
  45. [
  46. 'tool_enable' => 'boolean',
  47. 'host' => 'text',
  48. 'salt' => 'text',
  49. 'enable_global_conference' => 'boolean',
  50. 'enable_global_conference_per_user' => 'boolean',
  51. 'enable_conference_in_course_groups' => 'boolean',
  52. 'enable_global_conference_link' => 'boolean',
  53. 'disable_download_conference_link' => 'boolean',
  54. 'max_users_limit' => 'text',
  55. 'global_conference_allow_roles' => [
  56. 'type' => 'select',
  57. 'options' => [
  58. PLATFORM_ADMIN => get_lang('Administrator'),
  59. COURSEMANAGER => get_lang('Teacher'),
  60. STUDENT => get_lang('Student'),
  61. STUDENT_BOSS => get_lang('StudentBoss')
  62. ],
  63. 'attributes' => ['multiple' => 'multiple']
  64. ],
  65. 'interface' => [
  66. 'type' => 'select',
  67. 'options' => [
  68. self::INTERFACE_FLASH => 'Flash',
  69. self::INTERFACE_HTML5 => 'HTML5',
  70. ]
  71. ],
  72. 'launch_type' => [
  73. 'type' => 'select',
  74. 'options' => [
  75. self::LAUNCH_TYPE_DEFAULT => 'SetByDefault',
  76. self::LAUNCH_TYPE_SET_BY_TEACHER => 'SetByTeacher',
  77. self::LAUNCH_TYPE_SET_BY_STUDENT => 'SetByStudent',
  78. ],
  79. 'translate_options' => true, // variables will be translated using the plugin->get_lang
  80. ],
  81. 'allow_regenerate_recording' => 'boolean',
  82. ]
  83. );
  84. $this->isAdminPlugin = true;
  85. }
  86. /**
  87. * @param string $variable
  88. * @return bool
  89. */
  90. public function validateCourseSetting($variable)
  91. {
  92. if ($variable === 'bbb_enable_conference_in_groups') {
  93. if ($this->get('enable_conference_in_course_groups') === 'true') {
  94. return true;
  95. }
  96. return false;
  97. }
  98. return true;
  99. }
  100. /**
  101. * @return BBBPlugin|null
  102. */
  103. public static function create()
  104. {
  105. static $result = null;
  106. return $result ? $result : $result = new self();
  107. }
  108. /**
  109. * Install
  110. */
  111. public function install()
  112. {
  113. $sql = "CREATE TABLE IF NOT EXISTS plugin_bbb_meeting (
  114. id INT unsigned NOT NULL auto_increment PRIMARY KEY,
  115. c_id INT unsigned NOT NULL DEFAULT 0,
  116. group_id INT unsigned NOT NULL DEFAULT 0,
  117. user_id INT unsigned NOT NULL DEFAULT 0,
  118. meeting_name VARCHAR(255) NOT NULL DEFAULT '',
  119. attendee_pw VARCHAR(255) NOT NULL DEFAULT '',
  120. moderator_pw VARCHAR(255) NOT NULL DEFAULT '',
  121. record INT NOT NULL DEFAULT 0,
  122. status INT NOT NULL DEFAULT 0,
  123. created_at VARCHAR(255) NOT NULL,
  124. closed_at VARCHAR(255) NOT NULL,
  125. calendar_id INT DEFAULT 0,
  126. welcome_msg VARCHAR(255) NOT NULL DEFAULT '',
  127. session_id INT unsigned DEFAULT 0,
  128. remote_id CHAR(30),
  129. internal_meeting_id VARCHAR(255) DEFAULT NULL,
  130. visibility TINYINT NOT NULL DEFAULT 1,
  131. voice_bridge INT NOT NULL DEFAULT 1,
  132. access_url INT NOT NULL DEFAULT 1,
  133. video_url TEXT NULL,
  134. has_video_m4v TINYINT NOT NULL DEFAULT 0,
  135. interface INT NOT NULL DEFAULT 0
  136. )";
  137. Database::query($sql);
  138. Database::query(
  139. "CREATE TABLE IF NOT EXISTS plugin_bbb_room (
  140. id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  141. meeting_id int NOT NULL,
  142. participant_id int(11) NOT NULL,
  143. in_at datetime,
  144. out_at datetime,
  145. interface int NOT NULL DEFAULT 0
  146. );"
  147. );
  148. $fieldLabel = 'plugin_bbb_course_users_limit';
  149. $fieldType = ExtraField::FIELD_TYPE_INTEGER;
  150. $fieldTitle = 'MaxUsersInConferenceRoom';
  151. $fieldDefault = '0';
  152. $extraField = new ExtraField('course');
  153. $fieldId = CourseManager::create_course_extra_field(
  154. $fieldLabel,
  155. $fieldType,
  156. $fieldTitle,
  157. $fieldDefault
  158. );
  159. $extraField->find($fieldId);
  160. $extraField->update(
  161. [
  162. 'id' => $fieldId,
  163. 'variable' => 'plugin_bbb_course_users_limit',
  164. 'changeable' => 1,
  165. 'visible_to_self' => 1,
  166. 'visible_to_others' => 0
  167. ]
  168. );
  169. $fieldLabel = 'plugin_bbb_session_users_limit';
  170. $extraField = new ExtraField('session');
  171. $fieldId = SessionManager::create_session_extra_field(
  172. $fieldLabel,
  173. $fieldType,
  174. $fieldTitle,
  175. $fieldDefault
  176. );
  177. $extraField->find($fieldId);
  178. $extraField->update(
  179. [
  180. 'id' => $fieldId,
  181. 'variable' => 'plugin_bbb_session_users_limit',
  182. 'changeable' => 1,
  183. 'visible_to_self' => 1,
  184. 'visible_to_others' => 0
  185. ]
  186. );
  187. // Installing course settings
  188. $this->install_course_fields_in_all_courses();
  189. }
  190. /**
  191. * Uninstall
  192. */
  193. public function uninstall()
  194. {
  195. $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  196. $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
  197. $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
  198. $variables = [
  199. 'bbb_salt',
  200. 'bbb_host',
  201. 'bbb_tool_enable',
  202. 'enable_global_conference',
  203. 'enable_global_conference_per_user',
  204. 'enable_global_conference_link',
  205. 'disable_download_conference_link',
  206. 'enable_conference_in_course_groups',
  207. 'bbb_plugin',
  208. 'bbb_plugin_host',
  209. 'bbb_plugin_salt',
  210. 'max_users_limit',
  211. 'global_conference_allow_roles',
  212. 'interface',
  213. 'launch_type',
  214. ];
  215. foreach ($variables as $variable) {
  216. $sql = "DELETE FROM $t_settings WHERE variable = '$variable'";
  217. Database::query($sql);
  218. }
  219. $extraField = new ExtraField('course');
  220. $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(
  221. 'plugin_bbb_course_users_limit'
  222. );
  223. if (!empty($extraFieldInfo)) {
  224. $extraField->delete($extraFieldInfo['id']);
  225. }
  226. $extraField = new ExtraField('session');
  227. $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(
  228. 'plugin_bbb_session_users_limit'
  229. );
  230. if (!empty($extraFieldInfo)) {
  231. $extraField->delete($extraFieldInfo['id']);
  232. }
  233. $sql = "DELETE FROM $t_options WHERE variable = 'bbb_plugin'";
  234. Database::query($sql);
  235. // hack to get rid of Database::query warning (please add c_id...)
  236. $sql = "DELETE FROM $t_tool WHERE name = 'bbb' AND c_id != 0";
  237. Database::query($sql);
  238. Database::query('DROP TABLE IF EXISTS plugin_bbb_room');
  239. Database::query('DROP TABLE IF EXISTS plugin_bbb_meeting');
  240. // Deleting course settings
  241. $this->uninstall_course_fields_in_all_courses($this->course_settings);
  242. }
  243. /**
  244. * Return an array with URL
  245. *
  246. * @param string $conferenceUrl
  247. *
  248. * @return array
  249. */
  250. public function getUrlInterfaceLinks($conferenceUrl)
  251. {
  252. $urlList[] = $this->getFlashUrl($conferenceUrl);
  253. $urlList[] = $this->getHtmlUrl($conferenceUrl);
  254. return $urlList;
  255. }
  256. /**
  257. * @param string $conferenceUrl
  258. *
  259. * @return array
  260. */
  261. public function getFlashUrl($conferenceUrl)
  262. {
  263. $data = [
  264. 'text' => $this->get_lang('EnterConferenceFlash'),
  265. 'url' => $conferenceUrl.'&interface='.self::INTERFACE_FLASH,
  266. 'icon' => 'resources/img/64/videoconference_flash.png'
  267. ];
  268. return $data;
  269. }
  270. /**
  271. * @param string $conferenceUrl
  272. *
  273. * @return array
  274. */
  275. public function getHtmlUrl($conferenceUrl)
  276. {
  277. $data = [
  278. 'text' => $this->get_lang('EnterConferenceHTML5'),
  279. 'url' => $conferenceUrl.'&interface='.self::INTERFACE_HTML5,
  280. 'icon' => 'resources/img/64/videoconference_html5.png',
  281. ];
  282. return $data;
  283. }
  284. }