You are here

class BBBMeetingTypeController in BigBlueButton 8

Class BBBMeetingTypeController.

@package Drupal\bbb\Controller

Hierarchy

Expanded class hierarchy of BBBMeetingTypeController

File

modules/bbb_node/src/Controller/BBBMeetingTypeController.php, line 25

Namespace

Drupal\bbb_node\Controller
View source
class BBBMeetingTypeController extends ControllerBase {
  use StringTranslationTrait;

  /**
   * Node storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected $nodeStorage;

  /**
   * Node based Meeting api.
   *
   * @var \Drupal\bbb_node\Service\NodeMeeting
   */
  protected $nodeMeeting;

  /**
   * Api wrapper.
   *
   * @var \Drupal\bbb\Service\Api
   */
  protected $api;

  /**
   * Module settings.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('messenger'), $container
      ->get('bbb.api'), $container
      ->get('bbb_node.meeting'), $container
      ->get('config.factory'));
  }

  /**
   * BBBMeetingTypeController constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   * @param \Drupal\bbb\Service\Api $api
   * @param \Drupal\bbb_node\Service\NodeMeeting $node_meeting
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, MessengerInterface $messenger, Api $api, NodeMeeting $node_meeting, ConfigFactoryInterface $config_factory) {
    $this->entityTypeManager = $entity_type_manager;
    $this->messenger = $messenger;
    $this->api = $api;
    $this->nodeMeeting = $node_meeting;
    $this->config = $config_factory
      ->get('bbb_node.settings');
    $this->nodeStorage = $this->entityTypeManager
      ->getStorage('node');
  }

  /**
   * Redirect to big blue button instance; Menu callback
   *
   * @param \Drupal\node\NodeInterface|int $node
   *   A Drupal node Interface
   *
   * @return \Symfony\Component\HttpFoundation\Response|array
   *   Render array.
   */
  public function attend(NodeInterface $node) {
    if (is_numeric($node)) {
      $node = $this->nodeStorage
        ->load($node);
    }
    $node_type = $node
      ->getType();
    $meeting_settings = $this->entityTypeManager
      ->getStorage('bbb_node_type')
      ->load($node_type);
    $mode = 'attend';
    $meeting = $this->nodeMeeting
      ->get($node);
    $params = [
      'meetingID' => $meeting->meetingID,
      'password' => $meeting->attendeePW,
    ];
    $status = $this->api
      ->getMeetingInfo($params);
    if ($status && property_exists($status, 'hasBeenForciblyEnded') && $status
      ->hasBeenForciblyEnded() == 'true') {
      $this->messenger
        ->addWarning('The meeting has been terminated and is not available for attending.');
      return new RedirectResponse(Url::fromRoute('entity.node.canonical', [
        'node' => $node
          ->id(),
      ], [
        'absolute' => TRUE,
      ]));
    }

    //    drupal_set_title($node->getTitle());
    if ($meeting->running) {
      if ($this
        ->getDisplayMode() === 'blank') {
        $this
          ->redirect($node, $mode);
      }
    }
    else {
      if ($meeting_settings
        ->get('moderatorRequired')) {
        $this->messenger
          ->addStatus($this
          ->t('You signed up for this meeting. Please stay on this page, you will be redirected immediately after the meeting has started.'));
        $render = $this->entityTypeManager
          ->getViewBuilder('node')
          ->view($node);
        $render['#attached']['libraries'][] = 'bbb/check_status';
        $render['#attached']['drupalSettings']['bbb']['check_status']['check_status_url'] = Url::fromRoute('bbb_node.meeting.end_status', [
          'node' => $node
            ->id(),
        ]);
        return $render;
      }
      else {
        if (empty($meeting->initialized)) {
          if ($data = $this->nodeMeeting
            ->create($node, $params)) {

            // Update local data.
            $this->nodeMeeting
              ->update($node, array_merge((array) $meeting, (array) $data));
          }
        }
        if ($this
          ->getDisplayMode() == 'blank') {
          $this
            ->redirect($node, $mode);
        }
      }
    }
    return [
      '#theme' => 'bbb_meeting',
      '#meeting' => $meeting,
      '#mode' => $mode,
      '#height' => $this
        ->getDisplayHeight(),
      '#width' => $this
        ->getDisplayWidth(),
    ];
  }

  /**
   * Redirect to big blue button instance.
   *
   * @param \Drupal\Core\Entity\EntityInterface $node
   *   A Drupal node Interface.
   *
   * @return \Symfony\Component\HttpFoundation\Response|array
   *   Drupal render array.
   */
  public function moderate(NodeInterface $node) {
    if (is_numeric($node)) {

      /** @var \Drupal\node\NodeInterface $node */
      $node = $this->nodeStorage
        ->load($node);
    }
    $mode = 'moderate';
    $meeting = $this->nodeMeeting
      ->get($node);
    $meeting_info = $meeting['info'];
    $params = [
      'meetingID' => $meeting->meetingID,
      'password' => $meeting->moderatorPW,
    ];
    $status = $this->api
      ->getMeetingInfo($params);
    if ($status && property_exists($status, 'hasBeenForciblyEnded') && $status
      ->hasBeenForciblyEnded() == 'true') {
      $this->messenger
        ->addStatus('The meeting has been terminated and is not available for reopening.');
      return new RedirectResponse(Url::fromRoute('entity.node.canonical', [
        'node' => $node
          ->id(),
      ], [
        'absolute' => TRUE,
      ]));
    }

    //    drupal_set_title($node->getTitle());
    // Implicitly create meeting.
    if (empty($meeting->initialized)) {
      if ($data = $this->nodeMeeting
        ->create($node, (array) $params)) {

        // Update local data.
        $this->nodeMeeting
          ->update($node, array_merge((array) $meeting, (array) $data));
      }
    }
    if ($this
      ->getDisplayMode() === 'blank') {
      $this
        ->attendRedirect($node, $mode);
    }
    return [
      '#theme' => 'bbb_meeting',
      '#meeting' => $meeting,
      '#mode' => $mode,
      '#height' => $this
        ->getDisplayHeight(),
      '#width' => $this
        ->getDisplayWidth(),
    ];
  }

  /**
   * Redirect to meeting.
   */
  public function attendRedirect(NodeInterface $node, $mode = 'attend') {
    if (is_numeric($node)) {

      /** @var \Drupal\node\NodeInterface $node */
      $node = $this->nodeStorage
        ->load($node);
    }
    $meeting = $this->nodeMeeting
      ->get($node, NULL, FALSE);
    if (empty($meeting->url[$mode])) {

      // Redirect not found.
      throw new NotFoundHttpException();
    }

    // Get redirect URL.
    $url = parse_url($meeting->url[$mode]);
    $fullurl = $url['scheme'] . '://' . $url['host'] . (isset($url['port']) ? ':' . $url['port'] : '') . $url['path'] . '?' . $url['query'];
    return new RedirectResponse($fullurl, 301);
  }

  /**
   * Return meeting status; Menu callback
   *
   * @param $node
   *   EntityInterface node
   *
   * @return JsonResponse with boolean 'running'
   */
  public function status($node) {
    if (is_numeric($node)) {

      /** @var \Drupal\node\NodeInterface $node */
      $node = $this->nodeStorage
        ->load($node);
    }
    $meeting = $this->nodeMeeting
      ->get($node);
    return new JsonResponse([
      'running' => $meeting->running,
    ]);
  }
  public function getTitle(NodeInterface $node) {
    return $node
      ->getTitle();
  }
  public function getDisplayMode() {
    return $this->config
      ->get('display_mode');
  }
  public function getDisplayHeight() {
    return $this->config
      ->get('display_height');
  }
  public function getDisplayWidth() {
    return $this->config
      ->get('display_width');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BBBMeetingTypeController::$api protected property Api wrapper.
BBBMeetingTypeController::$config protected property Module settings.
BBBMeetingTypeController::$nodeMeeting protected property Node based Meeting api.
BBBMeetingTypeController::$nodeStorage protected property Node storage.
BBBMeetingTypeController::attend public function Redirect to big blue button instance; Menu callback
BBBMeetingTypeController::attendRedirect public function Redirect to meeting.
BBBMeetingTypeController::create public static function Instantiates a new instance of this class. Overrides ControllerBase::create
BBBMeetingTypeController::getDisplayHeight public function
BBBMeetingTypeController::getDisplayMode public function
BBBMeetingTypeController::getDisplayWidth public function
BBBMeetingTypeController::getTitle public function
BBBMeetingTypeController::moderate public function Redirect to big blue button instance.
BBBMeetingTypeController::status public function Return meeting status; Menu callback
BBBMeetingTypeController::__construct public function BBBMeetingTypeController constructor.
ControllerBase::$configFactory protected property The configuration factory.
ControllerBase::$currentUser protected property The current user service. 1
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityManager protected property The entity manager.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$formBuilder protected property The form builder. 2
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityManager Deprecated protected function Retrieves the entity manager service.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
ControllerBase::state protected function Returns the state storage service.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
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.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.