public function OpignoModule::getTrainingActiveAttempt in Opigno module 3.x
Same name and namespace in other branches
- 8 src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule::getTrainingActiveAttempt()
Get training attempt if user didn't finish training.
Parameters
\Drupal\Core\Session\AccountInterface $user: User entity object.
\Drupal\group\Entity\Group $group: Group object.
Return value
\Drupal\Core\Entity\EntityInterface|null Entity interface.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- src/
Entity/ OpignoModule.php, line 609
Class
- OpignoModule
- Defines the Module entity.
Namespace
Drupal\opigno_module\EntityCode
public function getTrainingActiveAttempt(AccountInterface $user, Group $group) {
$key = $group
->id() . '_' . $user
->id();
if (array_key_exists($key, $this->userTrainingActiveAttempt)) {
return $this->userTrainingActiveAttempt[$key];
}
$status_storage = static::entityTypeManager()
->getStorage('user_lp_status');
$query = $status_storage
->getQuery();
$training_statuses = $query
->condition('gid', $group
->id())
->condition('uid', $user
->id())
->condition('finished', 0)
->range(0, 1)
->execute();
$this->userTrainingActiveAttempt[$key] = !empty($training_statuses) ? $status_storage
->load(key($training_statuses)) : NULL;
return $this->userTrainingActiveAttempt[$key];
}