Skip to content

Commit

Permalink
Plugin: BBB: Allow custom video name - refs BT#20225
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Oct 13, 2022
1 parent bb99787 commit 489c786
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 40 deletions.
105 changes: 96 additions & 9 deletions plugin/bbb/lib/bbb.lib.php
Expand Up @@ -398,9 +398,9 @@ public function createMeeting($params)
api_get_session_id()
);

$meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : $this->getCurrentVideoConferenceName();
$welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
$record = isset($params['record']) && $params['record'] ? 'true' : 'false';
$meetingName = $params['meeting_name'] ?? $this->generateVideoConferenceName();
$welcomeMessage = $params['welcome_msg'] ?? null;
$record = $params['record'] ? 'true' : 'false';
//$duration = isset($params['duration']) ? intval($params['duration']) : 0;
// This setting currently limits the maximum conference duration,
// to avoid lingering sessions on the video-conference server #6261
Expand Down Expand Up @@ -499,23 +499,109 @@ public function getModMeetingPassword($courseCode = null)
}

/**
* @return string
* Get the info from the current open videoconference.
* Otherwise, return false.
*
* @return array|bool
*/
public function getCurrentVideoConferenceName()
public function getCurrentVideoConference()
{
$whereConditions = [
'status = ?' => 1,
];

if ($this->isGlobalConferencePerUserEnabled()) {
return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
$whereConditions[' AND user_id = ?'] = $this->userId;
}

if ($this->isGlobalConference()) {
return 'url_'.api_get_current_access_url_id();
$whereConditions[' AND access_url = ?'] = api_get_current_access_url_id();
}

if ($this->hasGroupSupport()) {
return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
$whereConditions[' AND group_id = ?'] = api_get_group_id();
}

$cId = api_get_course_int_id();
$sessionId = api_get_session_id();

if ($cId) {
$whereConditions[' AND c_id = ?'] = api_get_course_int_id();
}

if ($sessionId) {
$whereConditions[' AND session_id = ?'] = api_get_session_id();
}

return api_get_course_id().'-'.api_get_session_id();
return Database::select(
'*',
$this->table,
[
'where' => $whereConditions,
'order' => 'created_at DESC',
],
'first'
);
}

public function generateVideoConferenceName(string $defaultName = null): string
{
$nameFilter = function ($name) {
return URLify::filter(
$name,
64,
'',
true,
true,
true,
false
);
};

if (!empty($defaultName)) {
$name = $nameFilter($defaultName);

if (!empty($name)) {
return $name;
}
}

$urlId = api_get_current_access_url_id();

if ($this->isGlobalConferencePerUserEnabled()) {
return $nameFilter("url_{$this->userId}_$urlId");
}

if ($this->isGlobalConference()) {
return $nameFilter("url_$urlId");
}

$course = api_get_course_entity();
$session = api_get_session_entity();
$group = api_get_group_entity();

if ($this->hasGroupSupport()) {
$name = implode(
'-',
[
$course->getCode(),
$session ? $session->getName() : '',
$group ? $group->getName() : '',
]
);

return $nameFilter($name);
}

$name = implode(
'-',
[
$course->getCode(),
$session ? $session->getName() : '',
]
);

return $nameFilter($name);
}

/**
Expand Down Expand Up @@ -990,6 +1076,7 @@ public function getMeetings(
$newMeetingList = array();
foreach ($meetingList as $meetingDB) {
$item = array();
$item['metting_name'] = $meetingDB['meeting_name'];
$courseId = $meetingDB['c_id'];
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = '';
Expand Down
44 changes: 37 additions & 7 deletions plugin/bbb/listing.php
Expand Up @@ -396,7 +396,10 @@
$usersOnline = $bbb->getUsersOnlineInCurrentRoom();
$maxUsers = $bbb->getMaxUsersLimit();
$status = $bbb->isServerRunning();
$videoConferenceName = $bbb->getCurrentVideoConferenceName();
$currentOpenConference = $bbb->getCurrentVideoConference();
$videoConferenceName = $currentOpenConference
? $currentOpenConference['meeting_name']
: $bbb->generateVideoConferenceName();
$meetingExists = $bbb->meetingExists($videoConferenceName);
$showJoinButton = false;

Expand Down Expand Up @@ -468,13 +471,40 @@
}
}

// Default URL
$urlList[] = Display::url(
$plugin->get_lang('EnterConference'),
$conferenceUrl,
['target' => '_blank', 'class' => 'btn btn-primary btn-large']
$frmEnterConference = new FormValidator(
'enter_conference',
'get',
api_get_path(WEB_PLUGIN_PATH).'bbb/start.php',
'_blank'
);
$frmEnterConference->addText('name', get_lang('Name'));
$frmEnterConference->applyFilter('name', 'trim');
$frmEnterConference->addButtonNext($plugin->get_lang('EnterConference'));

$conferenceUrlQueryParams = [];

parse_str(
parse_url($conferenceUrl, PHP_URL_QUERY),
$conferenceUrlQueryParams
);

foreach ($conferenceUrlQueryParams as $key => $value) {
$frmEnterConference->addHidden($key, $value);
}

if ($meetingExists) {
$meetingInfo = $bbb->getMeetingByName($videoConferenceName);

if (1 === (int) $meetingInfo['status']) {
$frmEnterConference->freeze(['name']);
}
}

$frmEnterConference->setDefaults(['name' => $videoConferenceName]);

// Default URL
$enterConferenceLink = $frmEnterConference->returnForm();

$tpl = new Template($tool_name);

$tpl->assign('allow_to_edit', $allowToEdit);
Expand All @@ -487,7 +517,7 @@
$tpl->assign('show_join_button', $showJoinButton);
$tpl->assign('message', $message);
$tpl->assign('form', $formToString);
$tpl->assign('enter_conference_links', $urlList);
$tpl->assign('enter_conference_links', $enterConferenceLink);
$tpl->assign('page_number', $pageNumber);
$tpl->assign('page_id', $pageId);

Expand Down
2 changes: 1 addition & 1 deletion plugin/bbb/start.php
Expand Up @@ -68,7 +68,7 @@
}

$meetingParams = [];
$meetingParams['meeting_name'] = $bbb->getCurrentVideoConferenceName();
$meetingParams['meeting_name'] = $bbb->generateVideoConferenceName($_GET['name'] ?? null);
$url = null;
if ($bbb->meetingExists($meetingParams['meeting_name'])) {
$joinUrl = $bbb->joinMeeting($meetingParams['meeting_name']);
Expand Down
49 changes: 26 additions & 23 deletions plugin/bbb/view/listing.tpl
Expand Up @@ -12,39 +12,40 @@
</style>
<div class ="row">
{% if bbb_status == true %}
<div class ="col-md-12" style="text-align:center">
<div class ="col-md-12">
{{ form }}
{% if show_join_button == true %}
{{ enter_conference_links.0 }}
<br />
<strong>{{ 'UrlMeetingToShare'| get_plugin_lang('BBBPlugin') }}</strong>
<div class="well">
<div class="form-inline">
<div class="form-group">
<input id="share_button"
type="text"
style="width:600px"
class="form-control" readonly value="{{ conference_url }}">
<button onclick="copyTextToClipBoard('share_button');" class="btn btn-default">
<span class="fa fa-copy"></span> {{ 'CopyTextToClipboard' | get_lang }}
</button>
{{ enter_conference_links }}
<div class="text-center">
<strong>{{ 'UrlMeetingToShare'| get_plugin_lang('BBBPlugin') }}</strong>
<div class="well">
<div class="form-inline">
<div class="form-group">
<input id="share_button"
type="text"
style="width:600px"
class="form-control" readonly value="{{ conference_url }}">
<button onclick="copyTextToClipBoard('share_button');" class="btn btn-default">
<span class="fa fa-copy"></span> {{ 'CopyTextToClipboard' | get_lang }}
</button>
</div>
</div>
</div>
</div>
<p>
<p>
<span id="users_online" class="label label-warning">
{{ 'XUsersOnLine'| get_plugin_lang('BBBPlugin') | format(users_online) }}
</span>
</p>
</p>
{% if max_users_limit > 0 %}
{% if conference_manager == true %}
<p>{{ 'MaxXUsersWarning' | get_plugin_lang('BBBPlugin') | format(max_users_limit) }}</p>
{% elseif users_online >= max_users_limit/2 %}
<p>{{ 'MaxXUsersWarning' | get_plugin_lang('BBBPlugin') | format(max_users_limit) }}</p>
{% if max_users_limit > 0 %}
{% if conference_manager == true %}
<p>{{ 'MaxXUsersWarning' | get_plugin_lang('BBBPlugin') | format(max_users_limit) }}</p>
{% elseif users_online >= max_users_limit/2 %}
<p>{{ 'MaxXUsersWarning' | get_plugin_lang('BBBPlugin') | format(max_users_limit) }}</p>
{% endif %}
{% endif %}
{% endif %}
</div>
</div>
{% elseif max_users_limit > 0 %}
{% if conference_manager == true %}
Expand All @@ -61,6 +62,7 @@
</div>
<table class="table">
<tr>
<th>{{ 'Name'|get_lang }}</th>
<th>{{ 'CreatedAt'| get_plugin_lang('BBBPlugin') }}</th>
<th>{{ 'Status'| get_lang }}</th>
<th>{{ 'Records'| get_plugin_lang('BBBPlugin') }}</th>
Expand All @@ -71,6 +73,7 @@
{% for meeting in meetings %}
<tr>
<!-- td>{{ meeting.id }}</td -->
<td>{{ meeting.metting_name }}</td>
{% if meeting.visibility == 0 %}
<td class="muted">{{ meeting.created_at }}</td>
{% else %}
Expand Down

0 comments on commit 489c786

Please sign in to comment.