You are here

public function LearningPathController::trainingContent in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/Controller/LearningPathController.php \Drupal\opigno_learning_path\Controller\LearningPathController::trainingContent()

Training content.

File

src/Controller/LearningPathController.php, line 142

Class

LearningPathController
Class LearningPathController.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function trainingContent() {
  $build = [
    '#attached' => [
      'library' => [
        'core/drupal.dialog.ajax',
      ],
    ],
    '#theme' => 'opigno_learning_path_training_content',
  ];

  /** @var \Drupal\group\Entity\Group $group */
  $group = \Drupal::routeMatch()
    ->getParameter('group');
  if (!$group instanceof GroupInterface) {

    // On of  case an anonymous user hasn't an access to the group.
    return $build;
  }
  $user = \Drupal::currentUser();

  // Get training certificate expiration flag.
  $latest_cert_date = LPStatus::getTrainingStartDate($group, $user
    ->id());

  // If not a member.
  if (!$group
    ->getMember($user) || !$user
    ->isAuthenticated() && $group->field_learning_path_visibility->value === 'semiprivate') {
    return $build;
  }

  // Check if membership has status 'pending'.
  if (!LearningPathAccess::statusGroupValidation($group, $user)) {
    return $build;
  }
  $steps = $this
    ->trainingContentSteps($build, $group, $user, $latest_cert_date);
  $this
    ->trainingContentMain($build, $steps);
  $this
    ->trainingContentDocuments($build, $group);
  $this
    ->trainingContentForum($build, $group, $user);
  return $build;
}