|
|
|
@ -5,8 +5,8 @@ |
|
|
|
|
namespace Chamilo\PluginBundle\XApi\Lrs; |
|
|
|
|
|
|
|
|
|
use Chamilo\PluginBundle\XApi\Lrs\Util\InternalLogUtil; |
|
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
use Xabbuh\XApi\Model\Statement; |
|
|
|
|
use Xabbuh\XApi\Serializer\Symfony\ActorSerializer; |
|
|
|
|
use Xabbuh\XApi\Serializer\Symfony\Serializer; |
|
|
|
|
use Xabbuh\XApi\Serializer\Symfony\SerializerFactory; |
|
|
|
@ -26,21 +26,40 @@ use XApiPlugin; |
|
|
|
|
*/ |
|
|
|
|
class StatementsController extends BaseController |
|
|
|
|
{ |
|
|
|
|
public function get(): Response |
|
|
|
|
/** |
|
|
|
|
* @var StatementRepository |
|
|
|
|
*/ |
|
|
|
|
private $statementRepository; |
|
|
|
|
/** |
|
|
|
|
* @var \Symfony\Component\Serializer\Serializer|\Symfony\Component\Serializer\SerializerInterface |
|
|
|
|
*/ |
|
|
|
|
private $serializer; |
|
|
|
|
/** |
|
|
|
|
* @var SerializerFactory |
|
|
|
|
*/ |
|
|
|
|
private $serializerFactory; |
|
|
|
|
|
|
|
|
|
public function __construct(Request $httpRequest) |
|
|
|
|
{ |
|
|
|
|
parent::__construct($httpRequest); |
|
|
|
|
|
|
|
|
|
$pluginEm = XApiPlugin::getEntityManager(); |
|
|
|
|
|
|
|
|
|
$serializer = Serializer::createSerializer(); |
|
|
|
|
$factory = new SerializerFactory($serializer); |
|
|
|
|
$this->statementRepository = new StatementRepository( |
|
|
|
|
$pluginEm->getRepository(StatementEntity::class) |
|
|
|
|
); |
|
|
|
|
$this->serializer = Serializer::createSerializer(); |
|
|
|
|
$this->serializerFactory = new SerializerFactory($this->serializer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function get(): Response |
|
|
|
|
{ |
|
|
|
|
$getStatementController = new StatementGetController( |
|
|
|
|
new StatementRepository( |
|
|
|
|
$pluginEm->getRepository(StatementEntity::class) |
|
|
|
|
), |
|
|
|
|
$factory->createStatementSerializer(), |
|
|
|
|
$factory->createStatementResultSerializer(), |
|
|
|
|
$this->statementRepository, |
|
|
|
|
$this->serializerFactory->createStatementSerializer(), |
|
|
|
|
$this->serializerFactory->createStatementResultSerializer(), |
|
|
|
|
new StatementsFilterFactory( |
|
|
|
|
new ActorSerializer($serializer) |
|
|
|
|
new ActorSerializer($this->serializer) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
@ -49,83 +68,53 @@ class StatementsController extends BaseController |
|
|
|
|
|
|
|
|
|
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(), |
|
|
|
|
$this->statementRepository, |
|
|
|
|
$this->serializerFactory->createStatementSerializer(), |
|
|
|
|
$this->serializerFactory->createStatementResultSerializer(), |
|
|
|
|
new StatementsFilterFactory( |
|
|
|
|
new ActorSerializer($serializer) |
|
|
|
|
new ActorSerializer($this->serializer) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return $headStatementController->getStatement($this->httpRequest); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
|
|
|
*/ |
|
|
|
|
public function put() |
|
|
|
|
public function put(): Response |
|
|
|
|
{ |
|
|
|
|
$pluginEm = XApiPlugin::getEntityManager(); |
|
|
|
|
|
|
|
|
|
$putStatementController = new StatementPutController( |
|
|
|
|
new StatementRepository( |
|
|
|
|
$pluginEm->getRepository(StatementEntity::class) |
|
|
|
|
$statement = $this->serializerFactory |
|
|
|
|
->createStatementSerializer() |
|
|
|
|
->deserializeStatement( |
|
|
|
|
$this->httpRequest->getContent() |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$statement = $this->deserializeStatement( |
|
|
|
|
$this->httpRequest->getContent() |
|
|
|
|
); |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
InternalLogUtil::saveStatementForInternalLog($statement); |
|
|
|
|
|
|
|
|
|
$putStatementController = new StatementPutController($this->statementRepository); |
|
|
|
|
|
|
|
|
|
return $putStatementController->putStatement($this->httpRequest, $statement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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->deserializeStatements($content); |
|
|
|
|
$statements = $this->serializerFactory |
|
|
|
|
->createStatementSerializer() |
|
|
|
|
->deserializeStatements($content) |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
foreach ($statements as $statement) { |
|
|
|
|
InternalLogUtil::saveStatementForInternalLog($statement); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $postStatementController->postStatements($this->httpRequest, $statements); |
|
|
|
|
} |
|
|
|
|
$postStatementController = new StatementPostController($this->statementRepository); |
|
|
|
|
|
|
|
|
|
private function deserializeStatement(string $content = ''): Statement |
|
|
|
|
{ |
|
|
|
|
$factory = new SerializerFactory(Serializer::createSerializer()); |
|
|
|
|
|
|
|
|
|
return $factory->createStatementSerializer()->deserializeStatement($content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function deserializeStatements(string $content = ''): array |
|
|
|
|
{ |
|
|
|
|
$factory = new SerializerFactory(Serializer::createSerializer()); |
|
|
|
|
|
|
|
|
|
return $factory->createStatementSerializer()->deserializeStatements($content); |
|
|
|
|
return $postStatementController->postStatements($this->httpRequest, $statements); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|