public function TincanContentAnswerAssistant::getRegistration in Opigno module 8
Same name and namespace in other branches
- 3.x ActivityTypes/opigno_tincan_activity/src/TincanContentAnswerAssistant.php \Drupal\opigno_tincan_activity\TincanContentAnswerAssistant::getRegistration()
This method get the registration UUID.
It gets it from the database or from the PHPSESSION variable. If it is from the PHPSESSION, the method will save this registration to the database.
Parameters
\Drupal\opigno_module\Entity\OpignoActivityInterface $activity: Activity.
\Drupal\Core\Session\AccountProxyInterface $user: Account proxy interface.
Return value
bool|string The registration UUID if success, FALSE if not found.
File
- ActivityTypes/
opigno_tincan_activity/ src/ TincanContentAnswerAssistant.php, line 49
Class
- TincanContentAnswerAssistant
- Class TincanContentAnswerAssistant.
Namespace
Drupal\opigno_tincan_activityCode
public function getRegistration(OpignoActivityInterface $activity, AccountProxyInterface $user) {
// If we have the RID, try to get the registration from the DB.
if (!empty($activity) && !empty($user)) {
$connection = $this->connection;
$result = $connection
->select('opigno_tincan_activity_answers', 't')
->fields('t', [])
->condition('opigno_activity_id', $activity
->id())
->condition('uid', $user
->id())
->execute()
->fetchObject();
// If we have a result, we can return the registration.
if ($result) {
return $result->registration;
}
else {
// Create new registration uuid.
$registration = Util::getUUID();
$this
->saveRegistration($registration, $activity, $user);
return $registration;
}
}
// If we don't find the registration, return FALSE.
return FALSE;
}