public function OpignoModule::userAnswers in Opigno module 3.x
Same name and namespace in other branches
- 8 src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule::userAnswers()
Get answers of the specific user within specified attempt.
Parameters
\Drupal\Core\Session\AccountInterface $user: User account.
\Drupal\opigno_module\Entity\UserModuleStatusInterface $attempt: User module attempt object.
Return value
array|\Drupal\Core\Entity\EntityInterface|null User answers objects.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to OpignoModule::userAnswers()
- OpignoModule::getRandomActivity in src/
Entity/ OpignoModule.php - Returns random activity.
File
- src/
Entity/ OpignoModule.php, line 736
Class
- OpignoModule
- Defines the Module entity.
Namespace
Drupal\opigno_module\EntityCode
public function userAnswers(AccountInterface $user, UserModuleStatusInterface $attempt) {
$answers_storage = static::entityTypeManager()
->getStorage('opigno_answer');
$query = $answers_storage
->getQuery();
$answers = $query
->condition('module', $this
->id())
->condition('user_id', $user
->id())
->condition('user_module_status', $attempt
->id())
->execute();
return !empty($answers) ? $answers_storage
->loadMultiple($answers) : [];
}