XAPI: Allow request to statement head, about, activities profile - refs BT#19078

pull/3973/head
Angel Fernando Quiroz Campos 5 years ago
parent 833cf593b3
commit 56cdc0e70a
  1. 27
      plugin/xapi/php-xapi/lrs-bundle/src/Controller/StatementHeadController.php
  2. 30
      plugin/xapi/src/Lrs/AboutController.php
  3. 78
      plugin/xapi/src/Lrs/ActivitiesProfileController.php

@ -0,0 +1,27 @@
<?php
/*
* This file is part of the xAPI package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace XApi\LrsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class StatementHeadController extends StatementGetController
{
/**
* @throws BadRequestHttpException if the query parameters does not comply with xAPI specification
*
* @return Response
*/
public function getStatement(Request $request)
{
return parent::getStatement($request)->setContent('');
}
}

@ -0,0 +1,30 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\XApi\Lrs;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
/**
* Class AboutController.
*
* @package Chamilo\PluginBundle\XApi\Lrs
*/
class AboutController extends BaseController
{
public function get(): Response
{
$json = [
'version' => [
'1.0.3',
'1.0.2',
'1.0.1',
'1.0.0',
],
];
return JsonResponse::create($json);
}
}

@ -0,0 +1,78 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\XApi\Lrs;
use Chamilo\PluginBundle\Entity\XApi\ActivityProfile;
use Symfony\Component\HttpFoundation\Response;
/**
* Class ActivitiesProfileController.
*
* @package Chamilo\PluginBundle\XApi\Lrs
*/
class ActivitiesProfileController extends BaseController
{
public function get(): Response
{
$profileId = $this->httpRequest->query->get('profileId');
$activityId = $this->httpRequest->query->get('activityId');
$em = \Database::getManager();
$profileRepo = $em->getRepository(ActivityProfile::class);
/** @var ActivityProfile $activityProfile */
$activityProfile = $profileRepo->findOneBy(
[
'profileId' => $profileId,
'activityId' => $activityId,
]
);
if (empty($activityProfile)) {
return Response::create(null, Response::HTTP_NO_CONTENT);
}
return Response::create(
json_encode($activityProfile->getDocumentData())
);
}
public function head(): Response
{
return $this->get()->setContent('');
}
public function put(): Response
{
$profileId = $this->httpRequest->query->get('profileId');
$activityId = $this->httpRequest->query->get('activityId');
$documentData = $this->httpRequest->getContent();
$em = \Database::getManager();
$profileRepo = $em->getRepository(ActivityProfile::class);
/** @var ActivityProfile $activityProfile */
$activityProfile = $profileRepo->findOneBy(
[
'profileId' => $profileId,
'activityId' => $activityId,
]
);
if (empty($activityProfile)) {
$activityProfile = new ActivityProfile();
$activityProfile
->setProfileId($profileId)
->setActivityId($activityId);
}
$activityProfile->setDocumentData(json_decode($documentData, true));
$em->persist($activityProfile);
$em->flush();
return Response::create(null, Response::HTTP_NO_CONTENT);
}
}
Loading…
Cancel
Save