You are here

public static function OpignoTincanQuestionTypeResponse::getRegistration in Opigno TinCan Question Type 7

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

int $result_id: The result ID.

Return value

bool|string The registration UUID if success, FALSE if not found.

2 calls to OpignoTincanQuestionTypeResponse::getRegistration()
OpignoTincanQuestionTypeQuestion::getAnsweringForm in includes/opigno_tincan_question_type.question.inc
Get the form through which the user will answer the question.
OpignoTincanQuestionTypeResponse::__construct in includes/opigno_tincan_question_type.response.inc
This constructor will init the $registration property.

File

includes/opigno_tincan_question_type.response.inc, line 106
This file contains the class OpignoTincanQuestionTypeResponse.

Class

OpignoTincanQuestionTypeResponse
This class goal is to manage the user's answer(s).

Code

public static function getRegistration($result_id) {

  // If we have the RID, try to get the registration from the DB.
  if (!empty($result_id)) {
    $result = db_select(OpignoTincanQuestionTypeAnswersDatabase::NAME, 't')
      ->condition('rid', $result_id)
      ->fields('t')
      ->execute()
      ->fetchAssoc();

    // If we have a result, we can return the registration.
    if ($result) {
      return $result['registration'];
    }

    // If we didn't already saved the registration, save it now and return the
    // registration UUID.
    return self::saveRegistrationFromSession($result_id);
  }

  // If we don't have the RID, try to get the registration from PHPSESSION.
  if (isset($_SESSION[OpignoTincanQuestionTypeQuestion::SESSIONKEY_REGISTRATION])) {
    return $_SESSION[OpignoTincanQuestionTypeQuestion::SESSIONKEY_REGISTRATION];
  }

  // If we don't find the registration, return FALSE.
  return FALSE;
}