You are here

protected function UserController::getActivityMaxScore in Opigno statistics 3.x

Same name and namespace in other branches
  1. 8 src/Controller/UserController.php \Drupal\opigno_statistics\Controller\UserController::getActivityMaxScore()

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

Parameters

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

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

Return value

int Score.

1 call to UserController::getActivityMaxScore()
UserController::buildModuleDetails in src/Controller/UserController.php
Build render array for a user module details.

File

src/Controller/UserController.php, line 359

Class

UserController
Statistics user controller.

Namespace

Drupal\opigno_statistics\Controller

Code

protected function getActivityMaxScore(OpignoModule $module, OpignoActivity $activity) {
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('opigno_skills_system') && $module
    ->getSkillsActive()) {
    $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;
}