Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to LRS #3943

Open
wants to merge 28 commits into
base: 1.11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
48d008f
xAPI: Add activity table to create when installing - refs BT#16742
AngelFQC Feb 11, 2021
7fdbd24
xAPI: Fix State API resource - refs BT#16742
AngelFQC Feb 12, 2021
434370f
Minor - Format code - refs BT#16742
AngelFQC Feb 12, 2021
1e4a0a5
xAPI: Add activities profile API - refs BT#16742
AngelFQC Feb 12, 2021
012936f
xAPI: Add post method in activities state api - refs BT#16742
AngelFQC Feb 12, 2021
f134303
xAPI: Fix authorization requirementes - refs BT#16742
AngelFQC Feb 17, 2021
ce6f41f
xAPI: Add about resource - refs BT#16742
AngelFQC Feb 17, 2021
b060235
xAPI: Fix POST request for /statements - refs BT#16742
AngelFQC Feb 17, 2021
ce20798
Minor - Format code - refs BT#16742
AngelFQC Feb 19, 2021
9c31e49
xAPI: Fix post request in Statement resource - refs BT#16742
AngelFQC Feb 19, 2021
d355d0a
xAPI: Allow filter statements by verb - refs BT#16742
AngelFQC Feb 19, 2021
12568f5
xAPI: Fix GET request for statement resource - refs BT#16742
AngelFQC Feb 20, 2021
6634119
xAPI: Simplify catch exceptions in requests - refs BT#16742
AngelFQC Feb 21, 2021
ab2fe20
xAPI: Set alternate request syntax - refs BT#16742
AngelFQC Feb 22, 2021
2f0ef7d
xAPI: Add "more" property in result for statement resource - refs BT#…
AngelFQC Feb 22, 2021
5442375
xAPI: Set id to statment in PUT statement resource - refs BT#16742
AngelFQC Feb 23, 2021
daf5c36
xAPI: Don't show "more" when statement result is empty - refs BT#16742
AngelFQC Feb 23, 2021
7e097cd
xAPI: Use serialize factory for statements - refs BT#16742
AngelFQC Feb 24, 2021
b86fe5f
xAPI: Accept HEAD requests in statements resource - refs BT#16742
AngelFQC Feb 26, 2021
765ea69
xAPI: Allow verb without display
AngelFQC Feb 26, 2021
01f354a
xAPI: Fi head request in statements resource - refs BT#16742
AngelFQC Mar 1, 2021
9315b6d
xAPI: HEAD request to activities profile and state - refs BT#16742
AngelFQC Mar 1, 2021
9e66ff5
xAPI: Fix response when statement is not found - refs BT#16742
AngelFQC Mar 31, 2021
82a71bf
xAPI: Fix members relationship with statement object for groups - ref…
AngelFQC Apr 1, 2021
d434a4a
xAPI: Return 204 when statement is not found - refs BT#16742
AngelFQC Apr 5, 2021
5bcab08
Minor - Flint fixes
AngelFQC Aug 12, 2021
0800327
Vendor: Update XAPI dependencies - refs BT#16742
AngelFQC Aug 12, 2021
1b92c74
Merge branch '1.11.x' into lrs
AngelFQC Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
"patchwork/utf8": "~1.2",
"php-ffmpeg/php-ffmpeg": "0.5.1",
"php-http/guzzle6-adapter": "^2.0",
"php-xapi/client": "0.7.x-dev",
"php-xapi/client": "dev-master",
"php-xapi/model": "dev-master as 1.2",
"php-xapi/repository-api": "dev-master as 0.3.1",
"php-xapi/repository-doctrine": "dev-master",
"php-xapi/symfony-serializer": "2.1.0 as 2.0",
"php-xapi/symfony-serializer": "dev-master",
"phpmailer/phpmailer": "~6.1",
"phpoffice/phpexcel": "~1.8",
"phpoffice/phpword": "~0.14",
Expand Down
2 changes: 1 addition & 1 deletion plugin/xapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The endpoint for the statements API is "https://CHAMILO_DOMAIN/plugin/xapi/lrs.p
CREATE TABLE xapi_attachment (identifier INT AUTO_INCREMENT NOT NULL, statement_id VARCHAR(255) DEFAULT NULL, usageType VARCHAR(255) NOT NULL, contentType VARCHAR(255) NOT NULL, length INT NOT NULL, sha2 VARCHAR(255) NOT NULL, display LONGTEXT NOT NULL COMMENT '(DC2Type:json)', hasDescription TINYINT(1) NOT NULL, description LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)', fileUrl VARCHAR(255) DEFAULT NULL, content LONGTEXT DEFAULT NULL, INDEX IDX_7148C9A1849CB65B (statement_id), PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_object (identifier INT AUTO_INCREMENT NOT NULL, group_id INT DEFAULT NULL, actor_id INT DEFAULT NULL, verb_id INT DEFAULT NULL, object_id INT DEFAULT NULL, type VARCHAR(255) DEFAULT NULL, activityId VARCHAR(255) DEFAULT NULL, hasActivityDefinition TINYINT(1) DEFAULT NULL, hasActivityName TINYINT(1) DEFAULT NULL, activityName LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)', hasActivityDescription TINYINT(1) DEFAULT NULL, activityDescription LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)', activityType VARCHAR(255) DEFAULT NULL, activityMoreInfo VARCHAR(255) DEFAULT NULL, mbox VARCHAR(255) DEFAULT NULL, mboxSha1Sum VARCHAR(255) DEFAULT NULL, openId VARCHAR(255) DEFAULT NULL, accountName VARCHAR(255) DEFAULT NULL, accountHomePage VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, referenced_statement_id VARCHAR(255) DEFAULT NULL, activityExtensions_id INT DEFAULT NULL, parentContext_id INT DEFAULT NULL, groupingContext_id INT DEFAULT NULL, categoryContext_id INT DEFAULT NULL, otherContext_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_E2B68640303C7F1D (activityExtensions_id), INDEX IDX_E2B68640FE54D947 (group_id), UNIQUE INDEX UNIQ_E2B6864010DAF24A (actor_id), UNIQUE INDEX UNIQ_E2B68640C1D03483 (verb_id), UNIQUE INDEX UNIQ_E2B68640232D562B (object_id), INDEX IDX_E2B68640988A4CEC (parentContext_id), INDEX IDX_E2B686404F542860 (groupingContext_id), INDEX IDX_E2B68640AEA1B132 (categoryContext_id), INDEX IDX_E2B68640B73EEAB7 (otherContext_id), PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_result (identifier INT AUTO_INCREMENT NOT NULL, extensions_id INT DEFAULT NULL, hasScore TINYINT(1) NOT NULL, scaled DOUBLE PRECISION DEFAULT NULL, raw DOUBLE PRECISION DEFAULT NULL, min DOUBLE PRECISION DEFAULT NULL, max DOUBLE PRECISION DEFAULT NULL, success TINYINT(1) DEFAULT NULL, completion TINYINT(1) DEFAULT NULL, response VARCHAR(255) DEFAULT NULL, duration VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_5971ECBFD0A19400 (extensions_id), PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_verb (identifier INT AUTO_INCREMENT NOT NULL, id VARCHAR(255) NOT NULL, display LONGTEXT NOT NULL COMMENT '(DC2Type:json)', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_verb (identifier INT AUTO_INCREMENT NOT NULL, id VARCHAR(255) NOT NULL, display LONGTEXT NULL COMMENT '(DC2Type:json)', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_extensions (identifier INT AUTO_INCREMENT NOT NULL, extensions LONGTEXT NOT NULL COMMENT '(DC2Type:json)', PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_context (identifier INT AUTO_INCREMENT NOT NULL, instructor_id INT DEFAULT NULL, team_id INT DEFAULT NULL, extensions_id INT DEFAULT NULL, registration VARCHAR(255) DEFAULT NULL, hasContextActivities TINYINT(1) DEFAULT NULL, revision VARCHAR(255) DEFAULT NULL, platform VARCHAR(255) DEFAULT NULL, language VARCHAR(255) DEFAULT NULL, statement VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_3D7771908C4FC193 (instructor_id), UNIQUE INDEX UNIQ_3D777190296CD8AE (team_id), UNIQUE INDEX UNIQ_3D777190D0A19400 (extensions_id), PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
CREATE TABLE xapi_actor (identifier INT AUTO_INCREMENT NOT NULL, type VARCHAR(255) DEFAULT NULL, mbox VARCHAR(255) DEFAULT NULL, mboxSha1Sum VARCHAR(255) DEFAULT NULL, openId VARCHAR(255) DEFAULT NULL, accountName VARCHAR(255) DEFAULT NULL, accountHomePage VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, members VARCHAR(255) NOT NULL, PRIMARY KEY(identifier)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ public function getStatement(Request $request)
}
} catch (NotFoundException $e) {
$response = $this->buildMultiStatementsResponse([], $query)
->setStatusCode(Response::HTTP_NOT_FOUND)
->setContent('');
->setStatusCode(Response::HTTP_NOT_FOUND)
->setContent('')
;
} catch (\Exception $exception) {
$response = Response::create('', Response::HTTP_BAD_REQUEST);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function createFromParameterBag(ParameterBag $parameters)
$filter->descending();
}

$filter->cursor($parameters->getInt('cursor'));
$filter->limit($parameters->getInt('limit'));

return $filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</route>

<route id="xapi_lrs.statement.post" path="/statements" methods="POST">
<default key="_controller">xapi_lrs.controller.statement.post:postStatement</default>
<default key="_controller">xapi_lrs.controller.statement.post:postStatements</default>
<default key="xapi_serializer">statement</default>
<default key="xapi_lrs.route">
<bool>true</bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
</one-to-one>

<!-- group members -->
<one-to-many target-entity="XApi\Repository\Doctrine\Mapping\StatementObject" mapped-by="group" field="members" />
<one-to-many target-entity="XApi\Repository\Doctrine\Mapping\StatementObject" mapped-by="group" field="members">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
<many-to-one target-entity="XApi\Repository\Doctrine\Mapping\StatementObject" field="group" inversed-by="members">
<join-column referenced-column-name="identifier" />
</many-to-one>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</id>

<field name="id" type="string" />
<field name="display" type="json_array" />
<field name="display" type="json_array" nullable="true" />
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,33 @@ public function findStatement(array $criteria)
*/
public function findStatements(array $criteria)
{
if (!empty($criteria['registration'])) {
if (!empty($criteria['registration'])) {
$contexts = $this->_em->getRepository(Context::class)->findBy([
'registration' => $criteria['registration'],
]);

$criteria['context'] = $contexts;
}

if (!empty($criteria['verb'])) {
$verbs = $this->_em->getRepository(Verb::class)->findBy(['id' => $criteria['verb']]);

$criteria['verb'] = $verbs;
}

unset(
$criteria['registration'],
$criteria['related_activities'],
$criteria['related_agents'],
$criteria['ascending'],
$criteria['limit']
);

return parent::findBy($criteria, ['created' => 'ASC']);
return parent::findBy(
$criteria,
['created' => 'ASC'],
$criteria['limit'] ?? null,
$criteria['cursor'] ?? null
);
}

/**
Expand Down
76 changes: 65 additions & 11 deletions plugin/xapi/src/Lrs/StatementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Xabbuh\XApi\Common\Exception\NotFoundException;
use Xabbuh\XApi\Model\Statement;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Serializer\Symfony\ActorSerializer;
use Xabbuh\XApi\Serializer\Symfony\Serializer;
Expand All @@ -28,6 +29,48 @@
*/
class StatementsController extends BaseController
{
public function get(): Response
{
$pluginEm = XApiPlugin::getEntityManager();

$serializer = Serializer::createSerializer();
$factory = new SerializerFactory($serializer);

$getStatementController = new StatementGetController(
new StatementRepository(
$pluginEm->getRepository(StatementEntity::class)
),
$factory->createStatementSerializer(),
$factory->createStatementResultSerializer(),
new StatementsFilterFactory(
new ActorSerializer($serializer)
)
);

return $getStatementController->getStatement($this->httpRequest);
}

public function head(): Response
{
$pluginEm = XApiPlugin::getEntityManager();

$serializer = Serializer::createSerializer();
$factory = new SerializerFactory($serializer);

$headStatementController = new StatementHeadController(
new StatementRepository(
$pluginEm->getRepository(StatementEntity::class)
),
$factory->createStatementSerializer(),
$factory->createStatementResultSerializer(),
new StatementsFilterFactory(
new ActorSerializer($serializer)
)
);

return $headStatementController->getStatement($this->httpRequest);
}

/**
* @var StatementRepository
*/
Expand Down Expand Up @@ -104,28 +147,39 @@ public function put(): Response

public function post(): Response
{
$pluginEm = XApiPlugin::getEntityManager();

$postStatementController = new StatementPostController(
new StatementRepository(
$pluginEm->getRepository(StatementEntity::class)
)
);

$content = $this->httpRequest->getContent();

if (substr($content, 0, 1) !== '[') {
$content = "[$content]";
}

$statements = $this->serializerFactory
->createStatementSerializer()
->deserializeStatements($content)
;

$postStatementController = new StatementPostController($this->statementRepository);
$statements = $this->deserializeStatements($content);

$response = $postStatementController->postStatements($this->httpRequest, $statements);
return $postStatementController->postStatements($this->httpRequest, $statements);
}

$this->saveLog(
json_decode($response->getContent(), false)
);
private function deserializeStatement(string $content = ''): Statement
{
$factory = new SerializerFactory(Serializer::createSerializer());

return $response;
return $factory->createStatementSerializer()->deserializeStatement($content);
}

private function deserializeStatements(string $content = ''): array
{
$factory = new SerializerFactory(Serializer::createSerializer());

return $factory->createStatementSerializer()->deserializeStatements($content);
}

/**
* @param array<string> $statementsId
*
Expand Down
Loading