bbb_plugin.class.php 9.6 KB

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