You are here

protected function ModuleResultForm::getAnswerMaxScore in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Form/ModuleResultForm.php \Drupal\opigno_module\Form\ModuleResultForm::getAnswerMaxScore()

Returns answer max score.

2 calls to ModuleResultForm::getAnswerMaxScore()
ModuleResultForm::buildForm in src/Form/ModuleResultForm.php
Form constructor.
ModuleResultForm::validateForm in src/Form/ModuleResultForm.php
Form validation handler.

File

src/Form/ModuleResultForm.php, line 258

Class

ModuleResultForm
Class ModuleResultForm.

Namespace

Drupal\opigno_module\Form

Code

protected function getAnswerMaxScore(OpignoAnswerInterface $answer) {

  /* @var $db_connection \Drupal\Core\Database\Connection */
  $db_connection = \Drupal::service('database');
  $max_score = 0;
  $activity = $answer
    ->getActivity();
  $score_query = $db_connection
    ->select('opigno_module_relationship', 'omr')
    ->fields('omr', [
    'max_score',
  ])
    ->condition('omr.parent_id', $answer
    ->getModule()
    ->id())
    ->condition('omr.parent_vid', $answer
    ->getModule()
    ->getRevisionId())
    ->condition('omr.child_id', $activity
    ->id())
    ->condition('omr.child_vid', $activity
    ->getRevisionId());
  $score_result = $score_query
    ->execute()
    ->fetchObject();
  if ($score_result) {
    $max_score = $score_result->max_score;
  }
  return $max_score;
}