public function TrainingContentTrait::createAnswer in Opigno Learning path 8
Same name and namespace in other branches
- 3.x tests/src/Functional/TrainingContentTrait.php \Drupal\Tests\opigno_learning_path\Functional\TrainingContentTrait::createAnswer()
 
Create an Answer.
Parameters
OpignoActivity $activity: Opigno Activity entity.
OpignoModule $module: Opigno Module entity.
UserModuleStatus $attempt: Opigno user module status.
int $uid: User ID.
int $score: Score.
Return value
\Drupal\opigno_module\Entity\OpignoAnswer Opigno Answer entity.
Throws
\Drupal\Core\Entity\EntityStorageException
1 call to TrainingContentTrait::createAnswer()
- TrainingCompleteTest::createAnswersAndAttempt in tests/
src/ Functional/ TrainingCompleteTest.php  - Creates and answers and attempt and finish these.
 
File
- tests/
src/ Functional/ TrainingContentTrait.php, line 167  
Class
- TrainingContentTrait
 - Trait TrainingContentTrait.
 
Namespace
Drupal\Tests\opigno_learning_path\FunctionalCode
public function createAnswer($activity, $module, $attempt, $uid, $score) {
  $answer = \Drupal::entityTypeManager()
    ->getStorage('opigno_answer')
    ->create([
    'type' => 'opigno_long_answer',
    'activity' => $activity
      ->id(),
    'evaluated' => 1,
    'user_module_status' => $attempt
      ->id(),
    'score' => $score,
    'module' => $module
      ->id(),
    'user_id' => $uid,
  ]);
  $answer
    ->save();
  return $answer;
}