public function UserModuleStatus::calculateMaxScore in Opigno module 8
Same name and namespace in other branches
- 3.x src/Entity/UserModuleStatus.php \Drupal\opigno_module\Entity\UserModuleStatus::calculateMaxScore()
2 calls to UserModuleStatus::calculateMaxScore()
- UserModuleStatus::finishAttempt in src/
Entity/ UserModuleStatus.php - Finish user attempt.
- UserModuleStatus::getAttemptScore in src/
Entity/ UserModuleStatus.php - Get Attempt Score.
File
- src/
Entity/ UserModuleStatus.php, line 276
Class
- UserModuleStatus
- Defines the User module status entity.
Namespace
Drupal\opigno_module\EntityCode
public function calculateMaxScore() {
$max_score = 0;
/* @var $db_connection \Drupal\Core\Database\Connection */
$db_connection = \Drupal::service('database');
/* @var $module \Drupal\opigno_module\Entity\OpignoModule */
$module = $this
->getModule();
$score_query = $db_connection
->select('opigno_module_relationship', 'omr')
->fields('omr', [
'max_score',
'activity_status',
])
->condition('omr.parent_id', $module
->id())
->condition('omr.parent_vid', $module
->getRevisionId());
$score_results = $score_query
->execute()
->fetchAll();
if (!empty($score_results)) {
if ($module
->getRandomization() == 2) {
// Get max score only for answered random activities.
$max_score += $this
->getRandomActivitiesMaxScore();
}
else {
foreach ($score_results as $score_result) {
$max_score += $score_result->max_score;
}
}
}
return $max_score;
}