XAPI: Add grouping activities in context for course statements - refs BT#16742

pull/3680/head
Angel Fernando Quiroz Campos 5 years ago
parent 81bfbd71e2
commit fa882681a8
  1. 4
      main/inc/ajax/exercise.ajax.php
  2. 25
      plugin/xapi/src/Hook/XApiActivityHookObserver.php
  3. 11
      plugin/xapi/src/Hook/XApiLearningPathEndHookObserver.php
  4. 8
      plugin/xapi/src/Hook/XApiLearningPathItemViewedHookObserver.php
  5. 8
      plugin/xapi/src/Hook/XApiQuizEndHookObserver.php
  6. 30
      plugin/xapi/src/Hook/XApiQuizQuestionAnsweredHookObserver.php
  7. 45
      plugin/xapi/src/Traits/XApiStatementTrait.php

@ -756,6 +756,10 @@ switch ($action) {
->setEventData(
[
'exe_id' => (int) $exeId,
'quiz' => [
'id' => (int) $objExercise->id,
'title' => $objExercise->selectTitle(true),
],
'question' => [
'id' => (int) $my_question_id,
'weight' => (float) $result['weight']

@ -6,6 +6,7 @@ use Xabbuh\XApi\Common\Exception\ConflictException;
use Xabbuh\XApi\Common\Exception\StatementIdAlreadyExistsException;
use Xabbuh\XApi\Common\Exception\XApiException;
use Xabbuh\XApi\Model\Context;
use Xabbuh\XApi\Model\ContextActivities;
use Xabbuh\XApi\Model\Statement;
use Xabbuh\XApi\Model\StatementId;
@ -14,6 +15,16 @@ use Xabbuh\XApi\Model\StatementId;
*/
abstract class XApiActivityHookObserver extends HookObserver
{
use XApiStatementTrait;
/**
* @var \Chamilo\CoreBundle\Entity\Course
*/
protected $course;
/**
* @var \Chamilo\CoreBundle\Entity\Session|null
*/
protected $session;
/**
* @var \Chamilo\UserBundle\Entity\User
*/
@ -156,9 +167,21 @@ abstract class XApiActivityHookObserver extends HookObserver
{
$platform = api_get_setting('Institution').' - '.api_get_setting('siteName');
$groupingActivities = [
$this->generateActivityFromSite(),
$this->generateActivityFromCourse($this->course, $this->session),
];
$context = new Context();
return $context->withPlatform($platform);
return $context
->withPlatform($platform)
->withLanguage(
api_get_language_isocode()
)
->withContextActivities(
new ContextActivities(null, $groupingActivities)
);
}
/**

@ -23,17 +23,6 @@ class XApiLearningPathEndHookObserver extends XApiActivityHookObserver implement
* @var \Chamilo\CourseBundle\Entity\CLp
*/
private $lp;
/**
* @var \Chamilo\CoreBundle\Entity\Course
*/
private $course;
/**
* @var \Chamilo\CoreBundle\Entity\Session
*/
private $session;
/**
* @var \Chamilo\CourseBundle\Entity\CLpView|object|null
*/
/**
* @inheritDoc

@ -29,14 +29,6 @@ class XApiLearningPathItemViewedHookObserver
* @var \Chamilo\CourseBundle\Entity\CLpView;
*/
private $lpView;
/**
* @var \Chamilo\CoreBundle\Entity\Course
*/
private $course;
/**
* @var \Chamilo\CoreBundle\Entity\Session
*/
private $session;
/**
* @inheritDoc

@ -23,14 +23,6 @@ class XApiQuizEndHookObserver extends XApiActivityHookObserver implements HookQu
* @var \Chamilo\CourseBundle\Entity\CQuiz
*/
private $quiz;
/**
* @var \Chamilo\CoreBundle\Entity\Course
*/
private $course;
/**
* @var \Chamilo\CoreBundle\Entity\Session|null
*/
private $session;
/**
* @inheritDoc

@ -31,13 +31,9 @@ class XApiQuizQuestionAnsweredHookObserver
*/
private $question;
/**
* @var \Chamilo\CoreBundle\Entity\Course
* @var array
*/
private $course;
/**
* @var \Chamilo\CoreBundle\Entity\Session|null
*/
private $session;
private $quizInfo;
/**
* @inheritDoc
@ -49,6 +45,7 @@ class XApiQuizQuestionAnsweredHookObserver
$em = Database::getManager();
$this->exe = $em->find('ChamiloCoreBundle:TrackEExercises', $data['exe_id']);
$this->quizInfo = $data['quiz'];
$this->question = $em->find('ChamiloCourseBundle:CQuizQuestion', $data['question']['id']);
$this->attempt = $em
->getRepository('ChamiloCoreBundle:TrackEAttempt')
@ -148,20 +145,23 @@ class XApiQuizQuestionAnsweredHookObserver
*/
protected function getContext()
{
$quizIri = $this->plugin->generateIri(
$this->exe->getExeExoId(),
XApiPlugin::TYPE_QUIZ
);
$languageIso = api_get_language_isocode($this->course->getCourseLanguage());
$quizIri = $this->plugin->generateIri($this->quizInfo['id'], XApiPlugin::TYPE_QUIZ);
$quizActivity = new Activity(
IRI::fromString($quizIri)
IRI::fromString($quizIri),
new Definition(
LanguageMap::create([$languageIso => $this->quizInfo['title']]),
null,
IRI::fromString(XApiPlugin::IRI_QUIZ)
)
);
$activities = new ContextActivities(
[$quizActivity]
);
$context = parent::getContext();
$contextActivities = $context->getContextActivities()->withAddedGroupingActivity($quizActivity);
return parent::getContext()->withContextActivities($activities);
return $context->withContextActivities($contextActivities);
}
/**

@ -1,8 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course as CourseEntity;
use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\UserBundle\Entity\User as UserEntity;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\LanguageMap;
@ -63,4 +67,45 @@ trait XApiStatementTrait
return StatementId::fromUuid($uuid);
}
/**
* @return \Xabbuh\XApi\Model\Activity
*/
protected function generateActivityFromSite()
{
$platform = api_get_setting('Institution').' - '.api_get_setting('siteName');
$platformLanguage = api_get_setting('platformLanguage');
$platformLanguageIso = api_get_language_isocode($platformLanguage);
return new Activity(
IRI::fromString('http://id.tincanapi.com/activitytype/lms'),
new Definition(
LanguageMap::create([$platformLanguageIso => $platform])
)
);
}
/**
* @param \Chamilo\CoreBundle\Entity\Course $course
* @param \Chamilo\CoreBundle\Entity\Session|null $session
*
* @return \Xabbuh\XApi\Model\Activity
*/
protected function generateActivityFromCourse(
CourseEntity $course,
SessionEntity $session = null
) {
$languageIso = api_get_language_isocode($course->getCourseLanguage());
return new Activity(
IRI::fromString(
api_get_course_url($course->getCode(), $session ? $session->getId() : null)
),
new Definition(
LanguageMap::create([$languageIso => $course->getTitle()]),
null,
IRI::fromString('http://id.tincanapi.com/activitytype/lms/course')
)
);
}
}

Loading…
Cancel
Save