You are here

protected function LearningPathAchievementController::get_activity_max_score in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/Controller/LearningPathAchievementController.php \Drupal\opigno_learning_path\Controller\LearningPathAchievementController::get_activity_max_score()

Returns max score that user can have in this module & activity.

Parameters

\Drupal\opigno_module\Entity\OpignoModule $module: Module object.

\Drupal\opigno_module\Entity\OpignoActivity $activity: Activity object.

Return value

int Max score.

2 calls to LearningPathAchievementController::get_activity_max_score()
LearningPathAchievementController::build_module_panel in src/Controller/LearningPathAchievementController.php
Returns module panel renderable array.
LearningPathAchievementController::module_approved_activities in src/Controller/LearningPathAchievementController.php
Returns module approved activities.

File

src/Controller/LearningPathAchievementController.php, line 70

Class

LearningPathAchievementController
Class LearningPathAchievementController.

Namespace

Drupal\opigno_learning_path\Controller

Code

protected function get_activity_max_score($module, $activity) {
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('opigno_skills_system') && $module
    ->getSkillsActive() && $module
    ->getModuleSkillsGlobal()) {
    $query = $this->database
      ->select('opigno_module_relationship', 'omr')
      ->fields('omr', [
      'max_score',
    ])
      ->condition('omr.child_id', $activity
      ->id())
      ->condition('omr.child_vid', $activity
      ->getRevisionId())
      ->condition('omr.activity_status', 1);
    $results = $query
      ->execute()
      ->fetchAll();
  }
  else {
    $query = $this->database
      ->select('opigno_module_relationship', 'omr')
      ->fields('omr', [
      'max_score',
    ])
      ->condition('omr.parent_id', $module
      ->id())
      ->condition('omr.parent_vid', $module
      ->getRevisionId())
      ->condition('omr.child_id', $activity
      ->id())
      ->condition('omr.child_vid', $activity
      ->getRevisionId())
      ->condition('omr.activity_status', 1);
    $results = $query
      ->execute()
      ->fetchAll();
  }
  if (empty($results)) {
    return 0;
  }
  $result = reset($results);
  return $result->max_score;
}