bbb_plugin.class.php 9.7 KB

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