You are here

class ContentTypeMeeting in Opigno Moxtra 8

Same name and namespace in other branches
  1. 3.x src/Plugin/OpignoGroupManagerContentType/ContentTypeMeeting.php \Drupal\opigno_moxtra\Plugin\OpignoGroupManagerContentType\ContentTypeMeeting

Class ContentTypeMeeting.

Plugin annotation


@OpignoGroupManagerContentType(
  id = "ContentTypeMeeting",
  entity_type = "opigno_moxtra_meeting",
  readable_name = "Live Meeting",
  description = "Contains the Live Meetings",
  allowed_group_types = {
    "learning_path"
  },
  group_content_plugin_id = "opigno_moxtra_meeting_group"
)

Hierarchy

Expanded class hierarchy of ContentTypeMeeting

File

src/Plugin/OpignoGroupManagerContentType/ContentTypeMeeting.php, line 26

Namespace

Drupal\opigno_moxtra\Plugin\OpignoGroupManagerContentType
View source
class ContentTypeMeeting extends ContentTypeBase {

  /**
   * {@inheritdoc}
   */
  public function shouldShowNext() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getUserScore($user_id, $entity_id) {

    /** @var \Drupal\opigno_moxtra\MeetingResultInterface[] $results */
    $results = \Drupal::entityTypeManager()
      ->getStorage('opigno_moxtra_meeting_result')
      ->loadByProperties([
      'user_id' => $user_id,
      'meeting' => $entity_id,
    ]);
    $best_score = 0;
    foreach ($results as $result) {
      $score = $result
        ->getScore();
      if ($score > $best_score) {
        $best_score = $score;
      }
    }
    return $best_score / 100;
  }

  /**
   * {@inheritdoc}
   */
  public function getViewContentUrl($entity_id) {
    return Url::fromRoute('entity.opigno_moxtra_meeting.canonical', [
      'opigno_moxtra_meeting' => $entity_id,
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getStartContentUrl($content_id, $group_id = NULL) {
    return Url::fromRoute('opigno_moxtra.meeting', [
      'opigno_moxtra_meeting' => $content_id,
    ]);
  }

  /**
   * {@inheritdoc}
   *
   * @param int|\Drupal\opigno_moxtra\Entity\Meeting $meeting
   *   The entity ID or entity instance.
   */
  public function getContent($meeting) {

    // If the value is the meeting ID, load the meeting.
    if (is_numeric($meeting)) {

      /** @var \Drupal\opigno_moxtra\MeetingInterface $meeting */
      $meeting = Meeting::load($meeting);
    }
    if ($meeting === NULL || $meeting === FALSE) {
      return FALSE;
    }
    return new OpignoGroupContent($this
      ->getPluginId(), $this
      ->getEntityType(), $meeting
      ->id(), $meeting
      ->label(), $this
      ->getDefaultModuleImageUrl(), t('Default image'));
  }

  /**
   * Returns default image url.
   */
  public function getDefaultModuleImageUrl() {
    $request = \Drupal::request();
    $path = \Drupal::service('module_handler')
      ->getModule('opigno_module')
      ->getPath();
    return $request
      ->getBasePath() . '/' . $path . '/img/img_module.svg';
  }

  /**
   * {@inheritdoc}
   */
  public function getContentFromRequest(Request $request) {
    $meeting = $request
      ->get('opigno_moxtra_meeting');
    if ($meeting === NULL || $meeting === FALSE) {
      return FALSE;
    }
    return $this
      ->getContent($meeting);
  }

  /**
   * {@inheritdoc}
   */
  public function getFormObject($entity_id = NULL) {
    if (empty($entity_id)) {
      $form = \Drupal::entityTypeManager()
        ->getFormObject($this
        ->getEntityType(), 'add');
      $entity = Meeting::create();
    }
    else {
      $form = \Drupal::entityTypeManager()
        ->getFormObject($this
        ->getEntityType(), 'edit');
      $entity = Meeting::load($entity_id);
    }
    $form
      ->setEntity($entity);
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function getAllContents() {
    try {

      /** @var \Drupal\opigno_moxtra\Entity\Meeting[] $meetings */
      $meetings = \Drupal::entityTypeManager()
        ->getStorage('opigno_moxtra_meeting')
        ->loadMultiple();
    } catch (InvalidPluginDefinitionException $e) {

      // TODO: Log the error.
      return FALSE;
    }
    $contents = [];
    foreach ($meetings as $meeting) {
      $contents[] = $this
        ->getContent($meeting);
    }
    return $contents;
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContents() {
    return $this
      ->getAllContents();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentTypeBase::getAllowedGroupTypes public function Returns allowed group types.
ContentTypeBase::getDescription public function Returns description.
ContentTypeBase::getEntityType public function Returns entity type.
ContentTypeBase::getGroupContentPluginId public function Returns plugin id.
ContentTypeBase::getId public function Returns ID.
ContentTypeBase::getReadableName public function Returns readable name.
ContentTypeBase::shouldShowFinish public function Answer if the current page should show the "finish" button.
ContentTypeMeeting::getAllContents public function Get all the entities in an array of LearningPathContent. Overrides ContentTypeInterface::getAllContents
ContentTypeMeeting::getAvailableContents public function Get all the published entities in an array of LearningPathContent. Overrides ContentTypeInterface::getAvailableContents
ContentTypeMeeting::getContent public function Overrides ContentTypeInterface::getContent
ContentTypeMeeting::getContentFromRequest public function Try to get the content from a Request object. Overrides ContentTypeInterface::getContentFromRequest
ContentTypeMeeting::getDefaultModuleImageUrl public function Returns default image url.
ContentTypeMeeting::getFormObject public function Get the form object based on the entity ID. Overrides ContentTypeInterface::getFormObject
ContentTypeMeeting::getStartContentUrl public function Get the URL object for starting the quiz. Overrides ContentTypeBase::getStartContentUrl
ContentTypeMeeting::getUserScore public function Get the score of the user for a specific entity. Overrides ContentTypeInterface::getUserScore
ContentTypeMeeting::getViewContentUrl public function Get the URL object of the main view page of a specific entity. Overrides ContentTypeInterface::getViewContentUrl
ContentTypeMeeting::shouldShowNext public function Return TRUE if the page should show the "next" action button. Overrides ContentTypeInterface::shouldShowNext
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
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.