You are here

protected static function LearningPathValidator::courseValidate in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/LearningPathValidator.php \Drupal\opigno_learning_path\LearningPathValidator::courseValidate()

Checks if course has at least one module, and all modules are valid.

1 call to LearningPathValidator::courseValidate()
LearningPathValidator::stepsValidate in src/LearningPathValidator.php
Redirect user if one of learning path steps aren't completed.

File

src/LearningPathValidator.php, line 83

Class

LearningPathValidator
Class LearningPathValidator.

Namespace

Drupal\opigno_learning_path

Code

protected static function courseValidate($course_id, &$redirect_step) {
  $contents = OpignoGroupManagedContent::loadByGroupId($course_id);
  $is_valid = !empty($contents);
  if (!$is_valid && ($redirect_step === NULL || $redirect_step >= 3)) {
    $redirect_step = 3;

    // Show message only if user click on "next" button from current route.
    $current_route = \Drupal::service('current_route_match');
    $current_step = (int) $current_route
      ->getParameter('current');
    if ($current_step === $redirect_step) {
      $messenger = \Drupal::messenger();
      $messenger
        ->addError(t('Please make sure that every course contains at least one module.'));
    }
  }
  else {
    foreach ($contents as $course_content) {

      // Check if all modules in course has at least one activity.
      $module_id = $course_content
        ->getEntityId();
      $module = OpignoModule::load($module_id);
      if (!static::moduleValidate($module, $redirect_step)) {
        $is_valid = FALSE;
      }
    }
  }
  return $is_valid;
}