/** * 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; }
/** * Constructs a model from the given statement and options. * @param \stdClass $statement * @param StoreOptions $opts * @return [String => Mixed] $model */ private function constructModel(\stdClass $statement, StoreOptions $opts) { return ['lrs' => ['_id' => $opts->getOpt('lrs_id')], 'client_id' => $opts->getOpt('client')->_id, 'statement' => Helpers::replaceFullStop(json_decode(json_encode($statement), true)), 'active' => false, 'voided' => false, 'timestamp' => new \MongoDate(strtotime($statement->timestamp))]; }
/** * Constructs a model from the given statement and options. * @param \stdClass $statement * @param StoreOptions $opts * @return [String => Mixed] $model */ private function constructModel(\stdClass $statement, StoreOptions $opts) { $timestamp = new \Carbon\Carbon($statement->timestamp); $stored = new \Carbon\Carbon($statement->stored); return ['lrs' => ['_id' => $opts->getOpt('lrs_id')], 'lrs_id' => $opts->getOpt('lrs_id'), 'client_id' => $opts->getOpt('client')->_id, 'statement' => Helpers::replaceFullStop(json_decode(json_encode($statement), true)), 'active' => false, 'voided' => false, 'timestamp' => new \MongoDate($timestamp->timestamp, $timestamp->micro), 'stored' => new \MongoDate($stored->timestamp, $stored->micro)]; }