You are here

class OpignoModule in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule

Defines the Module entity.

Plugin annotation


@ContentEntityType(
  id = "opigno_module",
  label = @Translation("Module"),
  handlers = {
    "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
    "list_builder" = "Drupal\opigno_module\OpignoModuleListBuilder",
    "views_data" = "Drupal\opigno_module\Entity\OpignoModuleViewsData",

    "form" = {
      "default" = "Drupal\opigno_module\Form\OpignoModuleForm",
      "add" = "Drupal\opigno_module\Form\OpignoModuleForm",
      "edit" = "Drupal\opigno_module\Form\OpignoModuleForm",
      "delete" = "Drupal\opigno_module\Form\OpignoModuleDeleteForm",
    },
    "access" = "Drupal\opigno_module\OpignoModuleAccessControlHandler",
    "route_provider" = {
      "html" = "Drupal\opigno_module\OpignoModuleHtmlRouteProvider",
    },
  },
  base_table = "opigno_module",
  data_table = "opigno_module_field_data",
  revision_table = "opigno_module_revision",
  revision_data_table = "opigno_module_field_revision",
  translatable = TRUE,
  show_revision_ui = TRUE,
  admin_permission = "administer module entities",
  entity_keys = {
    "id" = "id",
    "revision" = "vid",
    "label" = "name",
    "uuid" = "uuid",
    "uid" = "uid",
    "langcode" = "langcode",
    "status" = "status",
  },
  links = {
    "canonical" = "/module/{opigno_module}",
    "add-form" = "/admin/structure/opigno_module/add",
    "edit-form" = "/admin/structure/opigno_module/{opigno_module}/edit",
    "delete-form" = "/admin/structure/opigno_module/{opigno_module}/delete",
    "collection" = "/admin/structure/opigno_module",
  },
  field_ui_base_route = "opigno_module.settings"
)

Hierarchy

Expanded class hierarchy of OpignoModule

11 files declare their use of OpignoModule
ContentTypeModule.php in src/Plugin/OpignoGroupManagerContentType/ContentTypeModule.php
ImportCourseForm.php in src/Form/ImportCourseForm.php
ImportModuleForm.php in src/Form/ImportModuleForm.php
ImportTrainingForm.php in src/Form/ImportTrainingForm.php
LearningPathController.php in src/Controller/LearningPathController.php

... See full list

File

src/Entity/OpignoModule.php, line 70

Namespace

Drupal\opigno_module\Entity
View source
class OpignoModule extends RevisionableContentEntityBase implements OpignoModuleInterface {
  use EntityChangedTrait;

  /**
   * Static cache of user attempts.
   */
  protected $userAttempts = [];

  /**
   * Static cache of user active attempt.
   */
  protected $userActiveAttempt = [];

  /**
   * Static cache of user training active attempt.
   *
   * @var mixed
   */
  protected $userTrainingActiveAttempt = [];

  /**
   * Static cache of activities.
   */
  protected $activities = [];

  /**
   * {@inheritdoc}
   */
  public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
    parent::preCreate($storage_controller, $values);
    $values += [
      'uid' => \Drupal::currentUser()
        ->id(),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return $this
      ->get('name')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setName($name) {
    $this
      ->set('name', $name);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getCreatedTime() {
    return $this
      ->get('created')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setCreatedTime($timestamp) {
    $this
      ->set('created', $timestamp);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwner() {
    return $this
      ->get('uid')->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwnerId() {
    return $this
      ->get('uid')->target_id;
  }

  /**
   * {@inheritdoc}
   */
  public function setOwnerId($uid) {
    $this
      ->set('uid', $uid);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setOwner(UserInterface $account) {
    $this
      ->set('uid', $account
      ->id());
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function isPublished() {
    return (bool) $this
      ->getEntityKey('status');
  }

  /**
   * {@inheritdoc}
   */
  public function setPublished($published) {
    $this
      ->set('status', $published ? TRUE : FALSE);
    return $this;
  }

  /**
   * Get Module Randomization setting.
   */
  public function getRandomization() {
    return $this
      ->get('randomization')->value;
  }

  /**
   * Get Module Backwards navigation setting.
   */
  public function getBackwardsNavigation() {
    return (bool) $this
      ->get('backwards_navigation')->value;
  }

  /**
   * Get Allow resume setting.
   */
  public function getAllowResume() {
    return (bool) $this
      ->get('allow_resume')->value;
  }

  /**
   * Get random activities count.
   */
  public function getRandomActivitiesCount() {
    return $this
      ->get('random_activities')->value;
  }

  /**
   * Set random activities count.
   */
  public function setRandomActivitiesCount($value) {
    $this
      ->set('random_activities', $value);
    return $this;
  }

  /**
   * Get random activity score.
   */
  public function getRandomActivityScore() {
    return $this
      ->get('random_activity_score')->value;
  }

  /**
   * Get skills activity of module.
   */
  public function getSkillsActive() {
    return $this
      ->get('skills_active')->value;
  }

  /**
   * Get skills activity of module.
   */
  public function getModuleSkillsGlobal() {
    return $this
      ->get('module_global')->value;
  }

  /**
   * Get target skill of module.
   */
  public function getTargetSkill() {
    return $this
      ->get('skill_target')->value;
  }

  /**
   * Set random activities count.
   */
  public function setRandomActivityScore($value) {
    $this
      ->set('random_activity_score', $value);
    return $this;
  }

  /**
   * Get image entity.
   */
  public function getModuleImage() {
    $media = $this
      ->get('module_media_image')->entity;
    if ($media) {
      return $media
        ->get('field_media_image')->entity;
    }
    else {
      return NULL;
    }
  }

  /**
   * Get hide results setting.
   */
  public function getHideResults($answer = NULL) : bool {

    // Show results for admins.
    $account = \Drupal::currentUser();
    if ($account
      ->hasPermission('view module results')) {
      return FALSE;
    }
    $result = (bool) $this
      ->get('hide_results')->value;
    if (!$answer instanceof OpignoAnswer) {
      return $result;
    }

    // Load group.
    // Check if user has role 'student manager' in a learning_path.
    $user_module_status = $answer
      ->getUserModuleStatus();
    if ($user_module_status instanceof UserModuleStatus && $user_module_status
      ->hasField('learning_path') && !empty($group = $user_module_status
      ->get('learning_path')->target_id) && LearningPathAccess::memberHasRole('user_manager', $account, $group)) {
      return FALSE;
    }

    // Return selected value for others.
    return $result;
  }

  /**
   * Get feedback results options.
   */
  public function getResultsOptions() {

    /* @var $connection \Drupal\Core\Database\Connection */
    $connection = \Drupal::service('database');
    $select_query = $connection
      ->select('opigno_module_result_options', 'omro')
      ->fields('omro')
      ->condition('module_id', $this
      ->id())
      ->condition('module_vid', $this
      ->getRevisionId());
    $options = $select_query
      ->execute()
      ->fetchAll();
    return $options;
  }

  /**
   * Insert feedback results options.
   */
  public function insertResultsOptions(FormStateInterface $form_state) {

    /* @var $connection \Drupal\Core\Database\Connection */
    $connection = \Drupal::service('database');
    $insert_query = $connection
      ->insert('opigno_module_result_options')
      ->fields([
      'module_id',
      'module_vid',
      'option_name',
      'option_summary',
      'option_summary_format',
      'option_start',
      'option_end',
    ]);
    $form_values = $form_state
      ->getValues();
    foreach ($form_values['results_options'] as $option) {
      if (!empty($option['option_name'])) {
        if (is_array($option['option_summary'])) {
          $option['option_summary_format'] = $option['option_summary']['format'];
          $option['option_summary'] = $option['option_summary']['value'];
        }
        $insert_query
          ->values([
          'module_id' => $this
            ->id(),
          'module_vid' => $this
            ->getRevisionId(),
          'option_name' => $option['option_name'],
          'option_summary' => $option['option_summary'],
          'option_summary_format' => $option['option_summary_format'],
          'option_start' => $option['option_start'],
          'option_end' => $option['option_end'],
        ]);
      }
    }
    $insert_query
      ->execute();
  }

  /**
   * Update feedback results options.
   */
  public function updateResultsOptions(FormStateInterface $form_state) {

    /* @var $connection \Drupal\Core\Database\Connection */
    $connection = \Drupal::service('database');

    // Remove existing options.
    $connection
      ->delete('opigno_module_result_options')
      ->condition('module_id', $this
      ->id())
      ->condition('module_vid', $this
      ->getRevisionId())
      ->execute();

    // Insert options.
    $this
      ->insertResultsOptions($form_state);
  }

  /**
   * Checks module availability.
   */
  public function checkModuleAvailability() {
    $availability = [
      'open' => TRUE,
      'message' => '',
    ];
    $module_availability = 0;
    $group_id = OpignoGroupContext::getCurrentGroupId();
    $lp_module_availability = LPModuleAvailability::loadByProperties([
      'group_id' => $group_id,
      'entity_id' => $this
        ->id(),
    ]);
    if ($lp_module_availability) {
      $lp_module_availability = current($lp_module_availability);
      $module_availability = $lp_module_availability
        ->getAvailability();
    }
    if ($module_availability) {
      $open_date = $lp_module_availability
        ->getOpenDate();
      $close_date = $lp_module_availability
        ->getCloseDate();
      if ($open_date && $close_date) {
        $quiz_open = \Drupal::time()
          ->getRequestTime() >= $open_date;
        $quiz_closed = \Drupal::time()
          ->getRequestTime() >= $close_date;
      }
      if (isset($quiz_open) && isset($quiz_closed)) {
        if (!$quiz_open || $quiz_closed) {
          $message = '';

          // Load Config.
          $config = \Drupal::config('opigno_module.settings');
          if ($quiz_closed) {
            $message = $config
              ->get('availability_closed_message');
          }
          elseif (!$quiz_open) {
            $message = $config
              ->get('availability_unavailable_message');
          }
          if (\Drupal::moduleHandler()
            ->moduleExists('token')) {
            $message = \Drupal::token()
              ->replace($message, [
              'opigno_module' => $this,
            ]);
          }
          $availability = [
            'open' => FALSE,
            'message' => $message,
          ];
        }
      }
    }
    return $availability;
  }

  /**
   * Get loaded statuses for specified user.
   */
  public function getModuleAttempts(AccountInterface $user, $range = NULL, $latest_cert_date = NULL, $finished = FALSE) {
    $key = $this
      ->id() . '_' . $user
      ->id();
    $key_base = $key;
    if (isset($range)) {
      $key .= '_' . $range;
    }
    if (array_key_exists($key, $this->userAttempts)) {
      return $this->userAttempts[$key];
    }
    $status_storage = static::entityTypeManager()
      ->getStorage('user_module_status');
    $query = $status_storage
      ->getQuery();
    $query
      ->condition('module', $this
      ->id())
      ->condition('user_id', $user
      ->id());
    if ($finished) {
      $query
        ->condition('finished', 0, '>');
    }
    if ($latest_cert_date) {
      $query
        ->condition('started', $latest_cert_date, '>=');
    }
    $status_ids = $query
      ->execute();
    if ($status_ids) {
      $status_entities = $status_storage
        ->loadMultiple($status_ids);
      $this->userAttempts[$key_base] = $status_entities;

      // Figure out the 'last' and 'best' scores in PHP to avoid running three
      // queries for potentially the same entity.
      $max_id = max(array_keys($status_ids));
      $this->userAttempts[$key_base . '_last'] = [
        $max_id => $status_entities[$max_id],
      ];
      $max_score = 0;
      $best_entity = FALSE;
      foreach ($status_entities as $entity) {
        if ($entity
          ->getScore() >= $max_score) {
          $max_score = $entity
            ->getScore();
          $best_entity = $entity;
        }
      }
      if (!$best_entity) {
        $this->userAttempts[$key_base . '_best'] = [];
      }
      else {
        $this->userAttempts[$key_base . '_best'] = [
          $best_entity
            ->id() => $best_entity,
        ];
      }
    }
    else {
      $this->userAttempts[$key_base . '_best'] = [];
      $this->userAttempts[$key_base . '_last'] = [];
    }
    return isset($this->userAttempts[$key]) ? $this->userAttempts[$key] : [];
  }

  /**
   * Get entity if user didn't finish module.
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   User entity object.
   *
   * @return \Drupal\Core\Entity\EntityInterface|null
   *   Entity interface.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function getModuleActiveAttempt(AccountInterface $user, $activity_link_type = NULL) {
    $key = $this
      ->id() . '_' . $user
      ->id();
    if ($activity_link_type == 'flow') {

      // Used Opigno flow type of activity answer link.
      if (array_key_exists($key, $this->userActiveAttempt)) {
        return $this->userActiveAttempt[$key];
      }
      OpignoGroupContext::removeActivityLinkType();
    }
    else {

      // Used activity answer manual/direct link.
      if (array_key_exists($key, $this->userActiveAttempt) && !empty($this->userActiveAttempt[$key])) {
        return $this->userActiveAttempt[$key];
      }
      elseif (!empty($this->userAttempts[$key . '_last'])) {
        $last_attempt = reset($this->userAttempts[$key . '_last']);
        $this->userActiveAttempt[$key] = $last_attempt;
        return $last_attempt;
      }
    }
    $status_storage = static::entityTypeManager()
      ->getStorage('user_module_status');
    $query = $status_storage
      ->getQuery();
    $module_statuses = $query
      ->condition('module', $this
      ->id())
      ->condition('user_id', $user
      ->id())
      ->condition('finished', 0)
      ->range(0, 1)
      ->execute();
    $this->userActiveAttempt[$key] = !empty($module_statuses) ? $status_storage
      ->load(key($module_statuses)) : NULL;
    return $this->userActiveAttempt[$key];
  }

  /**
   * Get module attempt if user didn't finish training.
   *
   * @param \Drupal\user\Entity\User $user
   *   User entity.
   * @return numeric
   *   Best score result.
   */
  public function getBestScore(User $user) {

    // For each attempt, check the score and save the best one.
    $user_attempts = $this
      ->getModuleAttempts($user, 'best');
    $best_score = 0;

    /* @var \Drupal\opigno_module\Entity\UserModuleStatus $user_attempt */
    foreach ($user_attempts as $user_attempt) {

      // Get the scores.
      $actual_score = $user_attempt
        ->getAttemptScore();

      // Save the best score.
      if ($actual_score > $best_score) {
        $best_score = $actual_score;
      }
    }
    return $best_score;
  }

  /**
   * Implements opigno_module_get_user_module_score().
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   User account object.
   * @param int $latest_cert_date
   *   The last date when was attempt.
   *
   * @return int
   *   Score in percents depends of OpignoModule keep_results option.
   */
  function getUserScore(AccountInterface $account, $latest_cert_date = NULL) {
    $which_score_keep = $this
      ->getKeepResultsOption();
    $attempts = $this
      ->getModuleAttempts($account, 'last', $latest_cert_date);
    if (!$attempts) {
      return 0;
    }

    /* @var \Drupal\opigno_module\Entity\UserModuleStatus $last_attempt */
    $last_attempt = end($attempts);
    $score = 0;
    switch ($which_score_keep) {

      // The newest score always saved in last attempt.
      case 'newest':
        $score = (int) $last_attempt
          ->getScore();
        break;

      // For these options get best score.
      case 'best':
      case 'all':
        $score = (int) $last_attempt
          ->calculateBestScore($latest_cert_date);
        break;
    }

    // Clamp score.
    $score = max(0, $score);
    $score = min(100, $score);
    return $score;
  }

  /**
   * Get training attempt if user didn't finish training.
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   User entity object.
   * @param \Drupal\group\Entity\Group $group
   *   Group object.
   *
   * @return \Drupal\Core\Entity\EntityInterface|null
   *   Entity interface.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function getTrainingActiveAttempt(AccountInterface $user, Group $group) {
    $key = $group
      ->id() . '_' . $user
      ->id();
    if (array_key_exists($key, $this->userTrainingActiveAttempt)) {
      return $this->userTrainingActiveAttempt[$key];
    }
    $status_storage = static::entityTypeManager()
      ->getStorage('user_lp_status');
    $query = $status_storage
      ->getQuery();
    $training_statuses = $query
      ->condition('gid', $group
      ->id())
      ->condition('uid', $user
      ->id())
      ->condition('finished', 0)
      ->range(0, 1)
      ->execute();
    $this->userTrainingActiveAttempt[$key] = !empty($training_statuses) ? $status_storage
      ->load(key($training_statuses)) : NULL;
    return $this->userTrainingActiveAttempt[$key];
  }

  /**
   * Get activities related to specific module.
   */
  public function getModuleActivities($full = FALSE) {
    if (empty($this->activities)) {

      /* @todo join table with activity revisions */

      /* @var $db_connection \Drupal\Core\Database\Connection */
      $db_connection = \Drupal::service('database');
      $query = $db_connection
        ->select('opigno_activity', 'oa');
      $query
        ->fields('oafd', [
        'id',
        'vid',
        'type',
        'name',
        'usage_activity',
        'skills_list',
        'skill_level',
      ]);
      $query
        ->fields('omr', [
        'activity_status',
        'weight',
        'max_score',
        'auto_update_max_score',
        'omr_id',
        'omr_pid',
        'child_id',
        'child_vid',
      ]);
      $query
        ->addJoin('inner', 'opigno_activity_field_data', 'oafd', 'oa.id = oafd.id');
      $query
        ->addJoin('inner', 'opigno_module_relationship', 'omr', 'oa.id = omr.child_id');
      $query
        ->condition('oafd.status', 1);
      $query
        ->condition('omr.parent_id', $this
        ->id());
      if ($this
        ->getRevisionId()) {
        $query
          ->condition('omr.parent_vid', $this
          ->getRevisionId());
      }
      $query
        ->condition('omr_pid', NULL, 'IS');
      $query
        ->orderBy('omr.weight');
      $query
        ->orderBy('omr.omr_id');
      $result = $query
        ->execute();
      foreach ($result as $activity) {
        $this->activities[$activity->id] = $activity;
      }
    }

    // Load entities if full was requested.
    if ($full && !empty($this->activities)) {
      $activity_ids = [];
      foreach ($this->activities as $activity) {
        $activity_ids[$activity->id] = $activity->id;
      }
      return OpignoActivity::loadMultiple($activity_ids);
    }
    return $this->activities;
  }

  /**
   * Get activities related to specific skills.
   */
  public function getSuitableActivities($current_skills) {
    if (empty($current_skills)) {
      return [
        0 => 0,
      ];
    }
    $activities = [];

    /* @var $db_connection \Drupal\Core\Database\Connection */
    $db_connection = \Drupal::service('database');
    $query = $db_connection
      ->select('opigno_activity', 'oa');
    $query
      ->fields('oafd', [
      'id',
      'vid',
      'type',
      'name',
      'usage_activity',
      'skills_list',
      'skill_level',
    ]);
    $query
      ->addJoin('inner', 'opigno_activity_field_data', 'oafd', 'oa.id = oafd.id');
    $query
      ->condition('oafd.status', 1);
    $query
      ->condition('oafd.skills_list', $current_skills, 'IN');
    $query
      ->condition('oafd.usage_activity', 'global');
    $result = $query
      ->execute();
    foreach ($result as $activity) {
      $activities[$activity->id] = $activity;
    }
    return $activities;
  }

  /**
   * Get answers of the specific user within specified attempt.
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   User account.
   * @param \Drupal\opigno_module\Entity\UserModuleStatusInterface $attempt
   *   User module attempt object.
   *
   * @return array|\Drupal\Core\Entity\EntityInterface|null
   *   User answers objects.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function userAnswers(AccountInterface $user, UserModuleStatusInterface $attempt) {
    $answers_storage = static::entityTypeManager()
      ->getStorage('opigno_answer');
    $query = $answers_storage
      ->getQuery();
    $answers = $query
      ->condition('module', $this
      ->id())
      ->condition('user_id', $user
      ->id())
      ->condition('user_module_status', $attempt
      ->id())
      ->execute();
    return !empty($answers) ? $answers_storage
      ->loadMultiple($answers) : [];
  }

  /**
   * Returns random activity.
   */
  public function getRandomActivity(UserModuleStatusInterface $attempt) {

    // Need to get activity that was not answered yet in this attempt.
    // Take all the activities.
    $activities = $this
      ->getModuleActivities();
    $activities_storage = static::entityTypeManager()
      ->getStorage('opigno_activity');
    $randomization = $this
      ->getRandomization();
    $random_count = $this
      ->getRandomActivitiesCount();
    $answered_random = 0;

    // Take answers within attempt.
    $user_answers = $this
      ->userAnswers(\Drupal::currentUser(), $attempt);
    if (!empty($user_answers)) {
      foreach ($user_answers as $answer) {
        $answer_activity = $answer
          ->getActivity();

        // Unset answered activity if answer already exist.
        if (isset($activities[$answer_activity
          ->id()])) {
          if ($randomization == 2) {
            $answered_random++;
          }
          unset($activities[$answer_activity
            ->id()]);
        }
      }
    }
    if ($randomization == 2) {
      $assigned_random = $activities;
      $activities = [];
      if (!empty($assigned_random) && $random_count > $answered_random) {
        $required_random = $random_count - $answered_random;
        $random_activities = array_rand($assigned_random, $required_random);
        if (is_array($random_activities)) {
          foreach ($random_activities as $random_activity) {
            $activities[$random_activity] = $assigned_random[$random_activity];
          }
        }
        else {
          $activities[$random_activities] = $assigned_random[$random_activities];
        }
      }
    }
    return !empty($activities) ? $activities_storage
      ->load(array_rand($activities, 1)) : FALSE;
  }

  /**
   * Get option to know which result need to be saved on Database.
   *
   * @return string
   *   Return string "best", "newest" or "all"
   */
  public function getKeepResultsOption() {
    $keep_results_options = [
      0 => 'best',
      1 => 'newest',
      2 => 'all',
    ];
    $option = $this
      ->get('keep_results')->value;
    return $keep_results_options[$option];
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields['uid'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Authored by'))
      ->setDescription(t('The user ID of author of the Module entity.'))
      ->setRevisionable(TRUE)
      ->setSetting('target_type', 'user')
      ->setSetting('handler', 'default')
      ->setTranslatable(TRUE)
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'author',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'entity_reference_autocomplete',
      'weight' => 5,
      'settings' => [
        'match_operator' => 'CONTAINS',
        'size' => '60',
        'autocomplete_type' => 'tags',
        'placeholder' => '',
      ],
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setDescription(t('The name of the Module entity.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setRequired(TRUE)
      ->setSettings([
      'max_length' => 50,
      'text_processing' => 0,
    ])
      ->setDefaultValue(NULL)
      ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'string',
      'weight' => -4,
    ])
      ->setDisplayOptions('form', [
      'type' => 'string_textfield',
      'weight' => -4,
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['module_media_image'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Image'))
      ->setDescription(t('Set here a module image'))
      ->setRevisionable(TRUE)
      ->setTranslatable(FALSE)
      ->setRequired(FALSE)
      ->setSetting('target_type', 'media')
      ->setSetting('handler', 'default')
      ->setSetting('handler_settings', [
      'target_bundles' => [
        'image',
      ],
    ])
      ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'media_thumbnail',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'entity_browser_entity_reference',
      'weight' => 26,
      'settings' => [
        'entity_browser' => 'media_entity_browser_groups',
        'field_widget_display' => 'rendered_entity',
        'field_widget_remove' => TRUE,
        'open' => TRUE,
        'selection_mode' => 'selection_append',
        'field_widget_display_settings' => [
          'view_mode' => 'image_only',
        ],
        'field_widget_edit' => FALSE,
        'field_widget_replace' => FALSE,
        'third_party_settings' => [
          'type' => 'entity_browser_entity_reference',
        ],
      ],
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['description'] = BaseFieldDefinition::create('text_long')
      ->setLabel(t('Description'))
      ->setDefaultValue('')
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setRequired(FALSE)
      ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'string',
      'weight' => -4,
    ])
      ->setDisplayOptions('form', [
      'type' => 'text_long',
      'weight' => 3,
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['status'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Publishing status'))
      ->setDescription(t('A boolean indicating whether the Module is published.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(TRUE);
    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Authored on'))
      ->setDescription(t('The time that the Module was created.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'timestamp',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'datetime_timestamp',
      'weight' => 10,
    ])
      ->setDisplayConfigurable('form', TRUE);
    $fields['changed'] = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time that the Module was last edited.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE);
    $fields['random_activity_score'] = BaseFieldDefinition::create('integer')
      ->setLabel(t('Random activity score'))
      ->setDescription(t('Score per each random activity.'))
      ->setRevisionable(TRUE)
      ->setDefaultValue(1);
    $fields['allow_resume'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Allow resume'))
      ->setDescription(t('Allow users to leave this Module incomplete and then resume it from where they left off.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 1,
    ]);
    $fields['backwards_navigation'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Backwards navigation'))
      ->setDescription(t('Allow users to go back and revisit activities already answered.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 2,
    ]);
    $randomization_options = [
      0 => t('No randomization'),
      1 => t('Random order'),
      2 => t('Random activities'),
    ];
    $randomization_description = t("<strong>Random order</strong> - all questions display in random order") . '<br/>' . t("<strong>Random activities</strong> - specific number of activities are drawn randomly from this module's pool of questions");
    $fields['randomization'] = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Randomize activities'))
      ->setDescription($randomization_description)
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setSetting('allowed_values', $randomization_options)
      ->setDefaultValue(0)
      ->setRequired(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 3,
    ]);
    $fields['random_activities'] = BaseFieldDefinition::create('integer')
      ->setLabel(t('Number of random activities'))
      ->setDescription(t('The number of activities to be randomly selected each time someone takes this module.'))
      ->setRevisionable(TRUE)
      ->setDefaultValue(1)
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 4,
    ]);
    $takes_options = [
      t('Unlimited'),
    ];
    for ($i = 1; $i < 10; $i++) {
      $takes_options[$i] = $i;
    }
    $fields['takes'] = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Allowed number of attempts'))
      ->setDescription(t('The number of times a user is allowed to take this Module. <strong>Anonymous users are only allowed to take Module that allow an unlimited number of attempts.</strong>'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setSetting('allowed_values', $takes_options)
      ->setDefaultValue(0)
      ->setRequired(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 4,
    ]);
    $fields['show_attempt_stats'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Display allowed number of attempts'))
      ->setDescription(t('Display the allowed number of attempts on the starting page for this Module.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 5,
    ]);
    $keep_results_options = [
      0 => t('The best'),
      1 => t('The newest'),
      2 => t('All'),
    ];
    $fields['keep_results'] = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Store results'))
      ->setDescription(t('These results should be stored for each user.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setSetting('allowed_values', $keep_results_options)
      ->setDefaultValue(2)
      ->setRequired(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 6,
    ]);
    $fields['hide_results'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Do not display results at the end of the module'))
      ->setDescription(t('If you check this option, the correct answers won’t be displayed to the users at the end of the module.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(FALSE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 2,
    ]);
    $fields['badge_active'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Activate badge system for this module'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(FALSE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 1,
    ]);
    $fields['badge_name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDisplayOptions('form', [
      'type' => 'string_textfield',
      'weight' => 1,
    ]);
    $fields['badge_description'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Badge description'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setRequired(FALSE)
      ->setDefaultValue('')
      ->setDisplayOptions('form', [
      'type' => 'string_textarea',
      'weight' => 2,
      'settings' => [
        'rows' => 3,
      ],
    ]);
    $options = [
      'finished' => 'Finished',
      'success' => 'Success',
    ];
    $fields['badge_criteria'] = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Badge criteria'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue('finished')
      ->setSetting('allowed_values', $options)
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 3,
    ]);
    $fields['badge_media_image'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Badge image'))
      ->setRevisionable(TRUE)
      ->setTranslatable(FALSE)
      ->setSetting('target_type', 'media')
      ->setSetting('handler', 'default')
      ->setSetting('handler_settings', [
      'target_bundles' => [
        'image_png',
      ],
    ])
      ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'media_thumbnail',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'entity_browser_entity_reference',
      'weight' => 4,
      'settings' => [
        'entity_browser' => 'media_entity_browser_badge_images',
        'field_widget_display' => 'rendered_entity',
        'field_widget_remove' => TRUE,
        'open' => TRUE,
        'selection_mode' => 'selection_append',
        'field_widget_display_settings' => [
          'view_mode' => 'image_only',
        ],
        'field_widget_edit' => FALSE,
        'field_widget_replace' => FALSE,
        'third_party_settings' => [
          'type' => 'entity_browser_entity_reference',
        ],
      ],
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['skills_active'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Activate skills system for this module'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(FALSE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 1,
    ]);
    $term_storage = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term');
    $target_skills = $term_storage
      ->loadTree('skills', 0, 1);
    $options = [];
    foreach ($target_skills as $row) {
      $options[$row->tid] = $row->name;
    }
    $fields['skill_target'] = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Target skill'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setSetting('allowed_values', $options)
      ->setDisplayOptions('form', [
      'type' => 'options_select',
      'weight' => 3,
    ]);
    $fields['module_global'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Use all suitable activities from Opigno system'))
      ->setDescription(t('If checked then Opigno system will load all suitable activities from other trainings and not assigned activities.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDefaultValue(FALSE)
      ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'weight' => 4,
    ]);
    return $fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ContentEntityBase::$activeLangcode protected property Language code identifying the entity active language.
ContentEntityBase::$defaultLangcode protected property Local cache for the default language code.
ContentEntityBase::$defaultLangcodeKey protected property The default langcode entity key.
ContentEntityBase::$enforceRevisionTranslationAffected protected property Whether the revision translation affected flag has been enforced.
ContentEntityBase::$entityKeys protected property Holds untranslatable entity keys such as the ID, bundle, and revision ID.
ContentEntityBase::$fieldDefinitions protected property Local cache for field definitions.
ContentEntityBase::$fields protected property The array of fields, each being an instance of FieldItemListInterface.
ContentEntityBase::$fieldsToSkipFromTranslationChangesCheck protected static property Local cache for fields to skip from the checking for translation changes.
ContentEntityBase::$isDefaultRevision protected property Indicates whether this is the default revision.
ContentEntityBase::$langcodeKey protected property The language entity key.
ContentEntityBase::$languages protected property Local cache for the available language objects.
ContentEntityBase::$loadedRevisionId protected property The loaded revision ID before the new revision was set.
ContentEntityBase::$newRevision protected property Boolean indicating whether a new revision should be created on save.
ContentEntityBase::$revisionTranslationAffectedKey protected property The revision translation affected entity key.
ContentEntityBase::$translatableEntityKeys protected property Holds translatable entity keys such as the label.
ContentEntityBase::$translationInitialize protected property A flag indicating whether a translation object is being initialized.
ContentEntityBase::$translations protected property An array of entity translation metadata.
ContentEntityBase::$validated protected property Whether entity validation was performed.
ContentEntityBase::$validationRequired protected property Whether entity validation is required before saving the entity.
ContentEntityBase::$values protected property The plain data values of the contained fields.
ContentEntityBase::access public function Checks data value access. Overrides EntityBase::access 1
ContentEntityBase::addTranslation public function Adds a new translation to the translatable object. Overrides TranslatableInterface::addTranslation
ContentEntityBase::bundle public function Gets the bundle of the entity. Overrides EntityBase::bundle
ContentEntityBase::bundleFieldDefinitions public static function Provides field definitions for a specific bundle. Overrides FieldableEntityInterface::bundleFieldDefinitions 4
ContentEntityBase::clearTranslationCache protected function Clear entity translation object cache to remove stale references.
ContentEntityBase::createDuplicate public function Creates a duplicate of the entity. Overrides EntityBase::createDuplicate 1
ContentEntityBase::get public function Gets a field item list. Overrides FieldableEntityInterface::get
ContentEntityBase::getEntityKey protected function Gets the value of the given entity key, if defined. 1
ContentEntityBase::getFieldDefinition public function Gets the definition of a contained field. Overrides FieldableEntityInterface::getFieldDefinition
ContentEntityBase::getFieldDefinitions public function Gets an array of field definitions of all contained fields. Overrides FieldableEntityInterface::getFieldDefinitions
ContentEntityBase::getFields public function Gets an array of all field item lists. Overrides FieldableEntityInterface::getFields
ContentEntityBase::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip in ::hasTranslationChanges. 1
ContentEntityBase::getIterator public function
ContentEntityBase::getLanguages protected function
ContentEntityBase::getLoadedRevisionId public function Gets the loaded Revision ID of the entity. Overrides RevisionableInterface::getLoadedRevisionId
ContentEntityBase::getRevisionId public function Gets the revision identifier of the entity. Overrides RevisionableInterface::getRevisionId
ContentEntityBase::getTranslatableFields public function Gets an array of field item lists for translatable fields. Overrides FieldableEntityInterface::getTranslatableFields
ContentEntityBase::getTranslatedField protected function Gets a translated field.
ContentEntityBase::getTranslation public function Gets a translation of the data. Overrides TranslatableInterface::getTranslation
ContentEntityBase::getTranslationLanguages public function Returns the languages the data is translated to. Overrides TranslatableInterface::getTranslationLanguages
ContentEntityBase::getTranslationStatus public function Returns the translation status. Overrides TranslationStatusInterface::getTranslationStatus
ContentEntityBase::getUntranslated public function Returns the translatable object referring to the original language. Overrides TranslatableInterface::getUntranslated
ContentEntityBase::hasField public function Determines whether the entity has a field with the given name. Overrides FieldableEntityInterface::hasField
ContentEntityBase::hasTranslation public function Checks there is a translation for the given language code. Overrides TranslatableInterface::hasTranslation
ContentEntityBase::hasTranslationChanges public function Determines if the current translation of the entity has unsaved changes. Overrides TranslatableInterface::hasTranslationChanges
ContentEntityBase::id public function Gets the identifier. Overrides EntityBase::id
ContentEntityBase::initializeTranslation protected function Instantiates a translation object for an existing translation.
ContentEntityBase::isDefaultRevision public function Checks if this entity is the default revision. Overrides RevisionableInterface::isDefaultRevision
ContentEntityBase::isDefaultTranslation public function Checks whether the translation is the default one. Overrides TranslatableInterface::isDefaultTranslation
ContentEntityBase::isDefaultTranslationAffectedOnly public function Checks if untranslatable fields should affect only the default translation. Overrides TranslatableRevisionableInterface::isDefaultTranslationAffectedOnly
ContentEntityBase::isLatestRevision public function Checks if this entity is the latest revision. Overrides RevisionableInterface::isLatestRevision
ContentEntityBase::isLatestTranslationAffectedRevision public function Checks whether this is the latest revision affecting this translation. Overrides TranslatableRevisionableInterface::isLatestTranslationAffectedRevision
ContentEntityBase::isNewRevision public function Determines whether a new revision should be created on save. Overrides RevisionableInterface::isNewRevision
ContentEntityBase::isNewTranslation public function Checks whether the translation is new. Overrides TranslatableInterface::isNewTranslation
ContentEntityBase::isRevisionTranslationAffected public function Checks whether the current translation is affected by the current revision. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffected
ContentEntityBase::isRevisionTranslationAffectedEnforced public function Checks if the revision translation affected flag value has been enforced. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffectedEnforced
ContentEntityBase::isTranslatable public function Returns the translation support status. Overrides TranslatableInterface::isTranslatable
ContentEntityBase::isValidationRequired public function Checks whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::isValidationRequired
ContentEntityBase::label public function Gets the label of the entity. Overrides EntityBase::label 2
ContentEntityBase::language public function Gets the language of the entity. Overrides EntityBase::language
ContentEntityBase::onChange public function Reacts to changes to a field. Overrides FieldableEntityInterface::onChange
ContentEntityBase::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityBase::postCreate
ContentEntityBase::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave 5
ContentEntityBase::preSave public function Acts on an entity before the presave hook is invoked. Overrides EntityBase::preSave 5
ContentEntityBase::preSaveRevision public function Acts on a revision before it gets saved. Overrides RevisionableInterface::preSaveRevision 2
ContentEntityBase::referencedEntities public function Gets a list of entities referenced by this entity. Overrides EntityBase::referencedEntities 1
ContentEntityBase::removeTranslation public function Removes the translation identified by the given language code. Overrides TranslatableInterface::removeTranslation
ContentEntityBase::set public function Sets a field value. Overrides FieldableEntityInterface::set
ContentEntityBase::setDefaultLangcode protected function Populates the local cache for the default language code.
ContentEntityBase::setNewRevision public function Enforces an entity to be saved as a new revision. Overrides RevisionableInterface::setNewRevision
ContentEntityBase::setRevisionTranslationAffected public function Marks the current revision translation as affected. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffected
ContentEntityBase::setRevisionTranslationAffectedEnforced public function Enforces the revision translation affected flag value. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffectedEnforced
ContentEntityBase::setValidationRequired public function Sets whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::setValidationRequired
ContentEntityBase::toArray public function Gets an array of all property values. Overrides EntityBase::toArray
ContentEntityBase::updateFieldLangcodes protected function Updates language for already instantiated fields.
ContentEntityBase::updateLoadedRevisionId public function Updates the loaded Revision ID with the revision ID. Overrides RevisionableInterface::updateLoadedRevisionId
ContentEntityBase::updateOriginalValues public function Updates the original values with the interim changes.
ContentEntityBase::uuid public function Gets the entity UUID (Universally Unique Identifier). Overrides EntityBase::uuid
ContentEntityBase::validate public function Validates the currently set values. Overrides FieldableEntityInterface::validate
ContentEntityBase::wasDefaultRevision public function Checks whether the entity object was a default revision when it was saved. Overrides RevisionableInterface::wasDefaultRevision
ContentEntityBase::__clone public function Magic method: Implements a deep clone.
ContentEntityBase::__construct public function Constructs an Entity object. Overrides EntityBase::__construct
ContentEntityBase::__get public function Implements the magic method for getting object properties.
ContentEntityBase::__isset public function Implements the magic method for isset().
ContentEntityBase::__set public function Implements the magic method for setting object properties.
ContentEntityBase::__sleep public function Overrides EntityBase::__sleep
ContentEntityBase::__unset public function Implements the magic method for unset().
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 Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::create public static function Constructs a new entity object, without permanently saving it. Overrides EntityInterface::create
EntityBase::delete public function Deletes an entity permanently. Overrides EntityInterface::delete 2
EntityBase::enforceIsNew public function Enforces an entity to be new. Overrides EntityInterface::enforceIsNew
EntityBase::entityManager Deprecated protected function Gets the entity manager.
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyTrait::getCacheTags
EntityBase::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. Overrides EntityInterface::getCacheTagsToInvalidate 2
EntityBase::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. Overrides EntityInterface::getConfigDependencyKey
EntityBase::getConfigDependencyName public function Gets the configuration dependency name. Overrides EntityInterface::getConfigDependencyName 1
EntityBase::getConfigTarget public function Gets the configuration target identifier for the entity. Overrides EntityInterface::getConfigTarget 1
EntityBase::getEntityType public function Gets the entity type definition. Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Gets the ID of the type of the entity. Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getOriginalId public function Gets the original ID. Overrides EntityInterface::getOriginalId 1
EntityBase::getTypedData public function Gets a typed data object for this entity object. Overrides EntityInterface::getTypedData
EntityBase::hasLinkTemplate public function Indicates if a link template exists for a given key. Overrides EntityInterface::hasLinkTemplate
EntityBase::invalidateTagsOnDelete protected static function Invalidates an entity's cache tags upon delete. 1
EntityBase::invalidateTagsOnSave protected function Invalidates an entity's cache tags upon save. 1
EntityBase::isNew public function Determines whether the entity is new. Overrides EntityInterface::isNew 2
EntityBase::languageManager protected function Gets the language manager.
EntityBase::link public function Deprecated way of generating a link to the entity. See toLink(). Overrides EntityInterface::link 1
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Loads an entity. Overrides EntityInterface::load
EntityBase::loadMultiple public static function Loads one or more entities. Overrides EntityInterface::loadMultiple
EntityBase::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface::postDelete 16
EntityBase::postLoad public static function Acts on loaded entities. Overrides EntityInterface::postLoad 2
EntityBase::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface::preDelete 4
EntityBase::save public function Saves an entity permanently. Overrides EntityInterface::save 3
EntityBase::setOriginalId public function Sets the original ID. Overrides EntityInterface::setOriginalId 1
EntityBase::toLink public function Generates the HTML for a link to this entity. Overrides EntityInterface::toLink
EntityBase::toUrl public function Gets the URL object for the entity. Overrides EntityInterface::toUrl 2
EntityBase::uriRelationships public function Gets a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityBase::url public function Gets the public URL for this entity. Overrides EntityInterface::url 2
EntityBase::urlInfo public function Gets the URL object for the entity. Overrides EntityInterface::urlInfo 1
EntityBase::urlRouteParameters protected function Gets an array of placeholders for this entity. 2
EntityBase::uuidGenerator protected function Gets the UUID generator.
EntityChangedTrait::getChangedTime public function Gets the timestamp of the last entity change for the current translation.
EntityChangedTrait::getChangedTimeAcrossTranslations public function Returns the timestamp of the last entity change across all translations.
EntityChangedTrait::setChangedTime public function Sets the timestamp of the last entity change for the current translation.
EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip when checking for changes. Aliased as: traitGetFieldsToSkipFromTranslationChangesCheck
OpignoModule::$activities protected property Static cache of activities.
OpignoModule::$userActiveAttempt protected property Static cache of user active attempt.
OpignoModule::$userAttempts protected property Static cache of user attempts.
OpignoModule::$userTrainingActiveAttempt protected property Static cache of user training active attempt.
OpignoModule::baseFieldDefinitions public static function Provides base field definitions for an entity type. Overrides RevisionableContentEntityBase::baseFieldDefinitions
OpignoModule::checkModuleAvailability public function Checks module availability.
OpignoModule::getAllowResume public function Get Allow resume setting.
OpignoModule::getBackwardsNavigation public function Get Module Backwards navigation setting.
OpignoModule::getBestScore public function Get module attempt if user didn't finish training.
OpignoModule::getCreatedTime public function Gets the Module creation timestamp. Overrides OpignoModuleInterface::getCreatedTime
OpignoModule::getHideResults public function Get hide results setting.
OpignoModule::getKeepResultsOption public function Get option to know which result need to be saved on Database.
OpignoModule::getModuleActiveAttempt public function Get entity if user didn't finish module.
OpignoModule::getModuleActivities public function Get activities related to specific module.
OpignoModule::getModuleAttempts public function Get loaded statuses for specified user.
OpignoModule::getModuleImage public function Get image entity.
OpignoModule::getModuleSkillsGlobal public function Get skills activity of module.
OpignoModule::getName public function Gets the Module name. Overrides OpignoModuleInterface::getName
OpignoModule::getOwner public function Returns the entity owner's user entity. Overrides EntityOwnerInterface::getOwner
OpignoModule::getOwnerId public function Returns the entity owner's user ID. Overrides EntityOwnerInterface::getOwnerId
OpignoModule::getRandomActivitiesCount public function Get random activities count.
OpignoModule::getRandomActivity public function Returns random activity.
OpignoModule::getRandomActivityScore public function Get random activity score.
OpignoModule::getRandomization public function Get Module Randomization setting.
OpignoModule::getResultsOptions public function Get feedback results options.
OpignoModule::getSkillsActive public function Get skills activity of module.
OpignoModule::getSuitableActivities public function Get activities related to specific skills.
OpignoModule::getTargetSkill public function Get target skill of module.
OpignoModule::getTrainingActiveAttempt public function Get training attempt if user didn't finish training.
OpignoModule::getUserScore function Implements opigno_module_get_user_module_score().
OpignoModule::insertResultsOptions public function Insert feedback results options.
OpignoModule::isPublished public function Returns the Module published status indicator. Overrides OpignoModuleInterface::isPublished
OpignoModule::preCreate public static function Changes the values of an entity before it is created. Overrides EntityBase::preCreate
OpignoModule::setCreatedTime public function Sets the Module creation timestamp. Overrides OpignoModuleInterface::setCreatedTime
OpignoModule::setName public function Sets the Module name. Overrides OpignoModuleInterface::setName
OpignoModule::setOwner public function Sets the entity owner's user entity. Overrides EntityOwnerInterface::setOwner
OpignoModule::setOwnerId public function Sets the entity owner's user ID. Overrides EntityOwnerInterface::setOwnerId
OpignoModule::setPublished public function Sets the published status of a Module. Overrides OpignoModuleInterface::setPublished
OpignoModule::setRandomActivitiesCount public function Set random activities count.
OpignoModule::setRandomActivityScore public function Set random activities count.
OpignoModule::updateResultsOptions public function Update feedback results options.
OpignoModule::userAnswers public function Get answers of the specific user within specified attempt.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
RevisionLogEntityTrait::getRevisionCreationTime public function Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionCreationTime(). 1
RevisionLogEntityTrait::getRevisionLogMessage public function Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage(). 1
RevisionLogEntityTrait::getRevisionMetadataKey protected static function Gets the name of a revision metadata field.
RevisionLogEntityTrait::getRevisionUser public function Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser(). 1
RevisionLogEntityTrait::getRevisionUserId public function Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUserId(). 1
RevisionLogEntityTrait::revisionLogBaseFieldDefinitions public static function Provides revision-related base field definitions for an entity type.
RevisionLogEntityTrait::setRevisionCreationTime public function Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionCreationTime(). 1
RevisionLogEntityTrait::setRevisionLogMessage public function Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage(). 1
RevisionLogEntityTrait::setRevisionUser public function Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUser(). 1
RevisionLogEntityTrait::setRevisionUserId public function Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId(). 1
SynchronizableEntityTrait::$isSyncing protected property Whether this entity is being created, updated or deleted through a synchronization process.
SynchronizableEntityTrait::isSyncing public function
SynchronizableEntityTrait::setSyncing public function
TranslationStatusInterface::TRANSLATION_CREATED constant Status code identifying a newly created translation.
TranslationStatusInterface::TRANSLATION_EXISTING constant Status code identifying an existing translation.
TranslationStatusInterface::TRANSLATION_REMOVED constant Status code identifying a removed translation.