Gets the current date and time in ISO format using the current timezone.
static public getCurrentDate ( ) : String | ||
return | String | Current ISO date and time. |
/** * Constructs valid statements. * @param [\stdClass] $statements * @param StoreOptions $opts * @return [String => \stdClass] Array of statements mapped to their UUIDs. */ private function constructValidStatements(array $statements, StoreOptions $opts) { $generated_ids = []; $constructed = []; $this->hashes = []; foreach ($statements as $statement) { $statement->authority = $opts->getOpt('authority'); $statement->stored = Helpers::getCurrentDate(); if (!isset($statement->timestamp)) { $statement->timestamp = $statement->stored; } if (!isset($statement->id)) { $statement->id = $this->getUUID($generated_ids); $generated_ids[] = $statement->id; } // Validates statement. $constructed_statement = new XAPIStatement($statement); Helpers::validateAtom($constructed_statement, 'statement'); $statement = $constructed_statement->getValue(); // Gets attachment hashes. $attachments = !isset($statement->attachments) ? [] : $statement->attachments; foreach ($attachments as $attachment) { $this->hashes[] = $attachment->sha2; } // Adds $statement to $constructed. if (isset($constructed[$statement->id])) { $this->inserter->compareForConflict($statement, $constructed[$statement->id]); } else { $constructed[$statement->id] = $statement; } } return $constructed; }
/** * Gets an array of statements. * https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#723-getstatements * @param [String => mixed] $options * @return Response */ public function index($options) { // Gets the acceptable languages. $langs = LockerRequest::header('Accept-Language', []); $langs = is_array($langs) ? $langs : explode(',', $langs); $langs = array_map(function ($lang) { return explode(';', $lang)[0]; }, $langs); // Gets the params. $params = LockerRequest::all(); if (isset($params['agent'])) { $decoded_agent = json_decode($params['agent']); if ($decoded_agent !== null) { $params['agent'] = $decoded_agent; } } // Gets an index of the statements with the given options. list($statements, $count, $opts) = $this->statements->index(array_merge(['langs' => $langs], $params, $options)); // Defines the content type and body of the response. if ($opts['attachments'] === true) { $content_type = 'multipart/mixed; boundary=' . static::BOUNDARY; $body = $this->makeAttachmentsResult($statements, $count, $opts); } else { $content_type = 'application/json;'; $body = $this->makeStatementsResult($statements, $count, $opts); } // Creates the response. return \Response::make($body, 200, ['Content-Type' => $content_type, 'X-Experience-API-Consistent-Through' => Helpers::getCurrentDate()]); }
/** * Gets the CORS headers. * @return [String => Mixed] CORS headers. */ private function getCORSHeaders() { return ['Access-Control-Allow-Origin' => \Request::root(), 'Access-Control-Allow-Methods' => 'GET, PUT, POST, DELETE, OPTIONS', 'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, X-Requested-With, X-Experience-API-Version, X-Experience-API-Consistent-Through, Updated', 'Access-Control-Allow-Credentials' => 'true', 'X-Experience-API-Consistent-Through' => Helpers::getCurrentDate(), 'X-Experience-API-Version' => '1.0.1']; }
protected function generateStatement($statement = []) { $timestamp = Helpers::getCurrentDate(); return array_merge(['id' => $this->statement_id, 'actor' => ['mbox' => 'mailto:test@example.com', 'objectType' => 'Agent'], 'verb' => ['id' => 'http://www.example.com/verbs/test'], 'object' => ['id' => 'http://www.example.com/objects/test', 'objectType' => 'Activity'], 'timestamp' => $timestamp, 'stored' => $timestamp, 'authority' => ['mbox' => 'mailto:test@example.com', 'objectType' => 'Agent'], 'version' => '1.0.1'], $statement); }