bbb_plugin.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 NOT NULL,
  116. participant_id int(11) NOT NULL,
  117. in_at datetime NOT NULL,
  118. out_at datetime NOT NULL
  119. );"
  120. );
  121. $fieldLabel = 'plugin_bbb_course_users_limit';
  122. $fieldType = ExtraField::FIELD_TYPE_INTEGER;
  123. $fieldTitle = 'MaxUsersInConferenceRoom';
  124. $fieldDefault = '0';
  125. $extraField = new ExtraField('course');
  126. $fieldId = CourseManager::create_course_extra_field(
  127. $fieldLabel,
  128. $fieldType,
  129. $fieldTitle,
  130. $fieldDefault
  131. );
  132. $extraField->find($fieldId);
  133. $extraField->update(
  134. [
  135. 'id' => $fieldId,
  136. 'variable' => 'plugin_bbb_course_users_limit',
  137. 'changeable' => 1,
  138. 'visible_to_self' => 1,
  139. 'visible_to_others' => 0
  140. ]
  141. );
  142. $fieldLabel = 'plugin_bbb_session_users_limit';
  143. $extraField = new ExtraField('session');
  144. $fieldId = SessionManager::create_session_extra_field(
  145. $fieldLabel,
  146. $fieldType,
  147. $fieldTitle,
  148. $fieldDefault
  149. );
  150. $extraField->find($fieldId);
  151. $extraField->update(
  152. [
  153. 'id' => $fieldId,
  154. 'variable' => 'plugin_bbb_session_users_limit',
  155. 'changeable' => 1,
  156. 'visible_to_self' => 1,
  157. 'visible_to_others' => 0
  158. ]
  159. );
  160. // Installing course settings
  161. $this->install_course_fields_in_all_courses();
  162. }
  163. /**
  164. * Uninstall
  165. */
  166. public function uninstall()
  167. {
  168. $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  169. $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
  170. $t_tool = Database::get_course_table(TABLE_TOOL_LIST);
  171. $variables = [
  172. 'bbb_salt',
  173. 'bbb_host',
  174. 'bbb_tool_enable',
  175. 'enable_global_conference',
  176. 'enable_global_conference_link',
  177. 'enable_conference_in_course_groups',
  178. 'bbb_plugin',
  179. 'bbb_plugin_host',
  180. 'bbb_plugin_salt',
  181. 'max_users_limit',
  182. 'global_conference_allow_roles'
  183. ];
  184. foreach ($variables as $variable) {
  185. $sql = "DELETE FROM $t_settings WHERE variable = '$variable'";
  186. Database::query($sql);
  187. }
  188. $extraField = new ExtraField('course');
  189. $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(
  190. 'plugin_bbb_course_users_limit'
  191. );
  192. if (!empty($extraFieldInfo)) {
  193. $extraField->delete($extraFieldInfo['id']);
  194. }
  195. $extraField = new ExtraField('session');
  196. $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(
  197. 'plugin_bbb_session_users_limit'
  198. );
  199. if (!empty($extraFieldInfo)) {
  200. $extraField->delete($extraFieldInfo['id']);
  201. }
  202. $sql = "DELETE FROM $t_options WHERE variable = 'bbb_plugin'";
  203. Database::query($sql);
  204. // hack to get rid of Database::query warning (please add c_id...)
  205. $sql = "DELETE FROM $t_tool WHERE name = 'bbb' AND c_id != 0";
  206. Database::query($sql);
  207. Database::query('DROP TABLE IF EXISTS plugin_bbb_room');
  208. Database::query('DROP TABLE IF EXISTS plugin_bbb_meeting');
  209. // Deleting course settings
  210. $this->uninstall_course_fields_in_all_courses($this->course_settings);
  211. }
  212. }