/** * 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 = Helpers::mixedMultipartContentType(); $body = function () use($statements, $count, $opts) { return $this->makeAttachmentsResult($statements, $count, $opts); }; } else { $content_type = 'application/json;'; $body = function () use($statements, $count, $opts) { return $this->makeStatementsResult($statements, $count, $opts); }; } // Creates the response. return \Response::stream($body, 200, ['Content-Type' => $content_type, 'X-Experience-API-Consistent-Through' => Helpers::getCurrentDate()]); }
private function storeAttachments() { $attachment_location = __DIR__ . '/../fixtures/attachment.jpg'; $attachment = $this->getAttachment($attachment_location); $statement = $this->generateStatementWithAttachment($attachment); $request_content = $this->generateContent(json_encode($statement), $attachment); $content_type = Helpers::mixedMultipartContentType(); // Sends request. $response = $this->requestStatements('POST', [], ['CONTENT_TYPE' => $content_type], $request_content); // Checks that the response is correct. $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(true, method_exists($response, 'getContent')); // Checks that the content is correct. $content = json_decode($response->getContent()); $this->assertEquals(true, is_array($content)); $this->assertEquals(true, isset($content[0])); $this->assertEquals(true, is_string($content[0])); $this->assertEquals($this->statement_id, $content[0]); return $attachment; }