Locker\Repository\Statement\EloquentStorer::constructValidStatements PHP Method

constructValidStatements() private method

Constructs valid statements.
private constructValidStatements ( array $statements, StoreOptions $opts ) : [String
$statements array
$opts StoreOptions
return [String
    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;
    }