NodeMeeting.php in BigBlueButton 8
File
modules/bbb_node/src/Service/NodeMeeting.php
View source
<?php
namespace Drupal\bbb_node\Service;
use BigBlueButton\Parameters\CreateMeetingParameters;
use Drupal\bbb\Service\Meeting as BbbMeeting;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\node\NodeTypeInterface;
class NodeMeeting {
use StringTranslationTrait;
protected $currentUser;
protected $entityTypeManager;
protected $meetingApi;
public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, BbbMeeting $meeting_api) {
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->meetingApi = $meeting_api;
}
public function isOwner(NodeInterface $node, $account = NULL) {
if (!$account) {
$account = $this->currentUser;
}
return $account
->id() === $node
->getOwnerId();
}
public function isTypeOf($typeOrNode) {
if ($typeOrNode instanceof NodeInterface) {
$typeOrNode = $typeOrNode
->getType();
}
if ($typeOrNode instanceof NodeTypeInterface) {
$typeOrNode = $typeOrNode
->id();
}
$settings = $this->entityTypeManager
->getStorage('bbb_node_type')
->load($typeOrNode);
if (!$settings) {
return FALSE;
}
return (bool) $settings
->active();
}
public function get(NodeInterface $node, $account = NULL, $cached = TRUE) {
return $this->meetingApi
->get($node
->uuid(), $account, $cached);
}
public function init(NodeInterface $node, CreateMeetingParameters $params = NULL) {
if (empty($params)) {
$params = new CreateMeetingParameters($node
->uuid(), $node
->getTitle());
}
$bbb_config = $this->entityTypeManager
->getStorage('bbb_node_type')
->load($node
->getType());
$params
->setMeetingName($params
->getMeetingName() ?: $node
->getTitle());
$params
->setWelcomeMessage($params
->getWelcomeMessage() ?: $bbb_config
->get('welcome') ?: $this
->t('Welcome to @title', [
'@title' => $node
->getTitle(),
]));
$params
->setDialNumber($params
->getDialNumber() ?: $bbb_config
->get('dialNumber') ?: NULL);
$params
->setModeratorPassword($params
->getModeratorPassword() ?: $bbb_config
->get('moderatorPW') ?: user_password());
$params
->setAttendeePassword($params
->getAttendeePassword() ?: $bbb_config
->get('attendeePW') ?: user_password());
$logout_url = $bbb_config
->get('logoutURL');
$params
->setLogoutUrl($params
->getLogoutUrl() ?: (empty($logout_url) ? NULL : Url::fromUserInput($bbb_config
->get('logoutURL'), [
'absolute' => TRUE,
])
->toString()));
$params
->setRecord($params
->isRecorded() ?: (bool) $bbb_config
->get('record'));
$params
->setVoiceBridge($params
->getVoiceBridge() ?: random_int(10000, 99999));
return $params;
}
public function update(NodeInterface $node, CreateMeetingParameters $params = NULL) {
$params = $this
->init($node, $params);
return $this->meetingApi
->update($node
->uuid(), $params);
}
public function create(NodeInterface $node, CreateMeetingParameters $params) {
$this
->init($node, $params);
return $this->meetingApi
->create($node
->uuid(), $params);
}
public function store($node, CreateMeetingParameters $params) {
return $this
->update($node, $params);
}
public function delete(NodeInterface $node) {
$this->meetingApi
->delete($node
->uuid());
}
}