You are here

class Meeting in BigBlueButton 8

Class Meeting.

@package Drupal\bbb\Service

Hierarchy

Expanded class hierarchy of Meeting

1 file declares its use of Meeting
NodeMeeting.php in modules/bbb_node/src/Service/NodeMeeting.php
1 string reference to 'Meeting'
bbb.services.yml in ./bbb.services.yml
bbb.services.yml
1 service uses Meeting
bbb.meeting in ./bbb.services.yml
Drupal\bbb\Service\Meeting

File

src/Service/Meeting.php, line 22

Namespace

Drupal\bbb\Service
View source
class Meeting implements MeetingInterface {
  use StringTranslationTrait;

  /**
   * Current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * Entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Meetings storage.
   *
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   */
  protected $meetingCollection;

  /**
   * Logger.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $log;

  /**
   * Drupal API for BigBlueButton service.
   *
   * @var \Drupal\bbb\Service\Api
   */
  protected $api;

  /**
   * Private key service.
   *
   * @var \Drupal\Core\PrivateKey
   */
  protected $privateKey;

  /**
   * Meetings info cached collection.
   *
   * @var array
   */
  protected static $meetings = [];

  /**
   * Meeting constructor.
   *
   * @param \Drupal\bbb\Service\Api $api
   *   Drupal API for BigBlueButton service.
   * @param \Drupal\Core\PrivateKey $private_key
   *   Private key service.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   Module handler.
   * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $keyvalue
   *   Keyvalue service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   Current user instance.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
   *   Logger factory.
   */
  public function __construct(Api $api, PrivateKey $private_key, ModuleHandlerInterface $module_handler, KeyValueFactoryInterface $keyvalue, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, LoggerChannelFactoryInterface $logger_factory) {
    $this->api = $api;
    $this->privateKey = $private_key;
    $this->currentUser = $current_user;
    $this->entityTypeManager = $entity_type_manager;
    $this->moduleHandler = $module_handler;
    $this->meetingCollection = $keyvalue
      ->get('bbb_meetings');
    $this->log = $logger_factory
      ->get('bbb');
  }

  /**
   * {@inheritdoc}
   */
  public function get($id, AccountInterface $account = NULL, $cached = TRUE) {
    if (empty($account)) {
      $account = $this->currentUser;
    }
    if (!isset(self::$meetings[$id]) || !$cached) {

      /** @var \BigBlueButton\Parameters\CreateMeetingParameters $meeting_created */
      $meeting_created = $this->meetingCollection
        ->get($id);
      if ($meeting_created) {
        $meeting_info = $this->api
          ->getMeetingInfo(new GetMeetingInfoParameters($meeting_created
          ->getMeetingId(), $meeting_created
          ->getModeratorPassword()));
        if ($meeting_info) {
          $url = [
            'attend' => $this->api
              ->joinMeeting(new JoinMeetingParameters($meeting_created
              ->getMeetingId(), $account
              ->getDisplayName(), $meeting_created
              ->getAttendeePassword())),
            'moderate' => $this->api
              ->joinMeeting(new JoinMeetingParameters($meeting_created
              ->getMeetingId(), $account
              ->getDisplayName(), $meeting_created
              ->getModeratorPassword())),
          ];
          $meeting = [
            'info' => $meeting_info,
            'created' => $meeting_created,
            'url' => $url,
          ];

          // Allow alteration for e.g. access control
          // Just implement hook_bbb_meeting_alter(&$data) {} in your module.
          $this->moduleHandler
            ->alter('bbb_get_meeting', $meeting);

          // Static cache.
          self::$meetings[$id] = $meeting;
        }
      }
    }
    return isset(self::$meetings[$id]) ? self::$meetings[$id] : [];
  }

  /**
   * {@inheritdoc}
   */
  public function update($key, CreateMeetingParameters $params) {
    $this->meetingCollection
      ->set($key, $params);
    return $key;
  }

  /**
   * {@inheritdoc}
   */
  public function create($key, CreateMeetingParameters $params) {
    if ($data = $this->api
      ->createMeeting($params)) {
      return $data;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function store($key, CreateMeetingParameters $params) {
    return $this
      ->update($key, $params);
  }

  /**
   * {@inheritdoc}
   */
  public function delete($key) {
    if ($this->meetingCollection
      ->has($key)) {
      $this->meetingCollection
        ->delete($key);
    }
    else {
      $this->log
        ->warning($this
        ->t('Meeting @key not found during removal: It was removed before manually or never exists.', [
        '@key' => $key,
      ]));
    }
    $meeting = $this
      ->get($key);
    $params = new EndMeetingParameters($meeting->meetingID, $meeting->moderatorPW);
    $request = $this->api
      ->endMeeting($params);
    return $request;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Meeting::$api protected property Drupal API for BigBlueButton service.
Meeting::$currentUser protected property Current user.
Meeting::$entityTypeManager protected property Entity type manager.
Meeting::$log protected property Logger.
Meeting::$meetingCollection protected property Meetings storage.
Meeting::$meetings protected static property Meetings info cached collection.
Meeting::$moduleHandler protected property Module handler.
Meeting::$privateKey protected property Private key service.
Meeting::create public function Create meeting. Overrides MeetingInterface::create
Meeting::delete public function Delete meeting. Overrides MeetingInterface::delete
Meeting::get public function Return a meeting object. Overrides MeetingInterface::get
Meeting::store public function Store meeting. Overrides MeetingInterface::store
Meeting::update public function Update meeting. Overrides MeetingInterface::update
Meeting::__construct public function Meeting constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.