parent
58837fcd33
commit
5f92f00d9f
@ -0,0 +1,49 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Xabbuh\XApi\Model\Activity; |
||||
|
||||
/** |
||||
* Class BaseActivity. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
abstract class BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\UserBundle\Entity\User |
||||
*/ |
||||
protected $user; |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Course|null |
||||
*/ |
||||
protected $course; |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Session|null |
||||
*/ |
||||
protected $session; |
||||
|
||||
public abstract function generate(): Activity; |
||||
|
||||
protected function generateIri(string $path, string $resource, array $params = []): string |
||||
{ |
||||
$cidReq = api_get_cidreq(); |
||||
|
||||
$url = api_get_path($path).$resource; |
||||
|
||||
if ($params) { |
||||
$url .= '?'.http_build_query($params).'&'; |
||||
} elseif (empty($params) && $cidReq) { |
||||
$url .= '?'; |
||||
} |
||||
|
||||
if ($cidReq) { |
||||
$url .= $cidReq; |
||||
} |
||||
|
||||
return $url; |
||||
} |
||||
} |
||||
@ -0,0 +1,40 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class Course. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class Course extends BaseActivity |
||||
{ |
||||
public function generate(): Activity |
||||
{ |
||||
$course = api_get_course_entity(); |
||||
$session = api_get_session_entity(); |
||||
|
||||
$languageIso = api_get_language_isocode($course->getCourseLanguage()); |
||||
|
||||
$courseUrl = api_get_course_url( |
||||
$course->getCode(), |
||||
$session ? $session->getId() : 0 |
||||
); |
||||
|
||||
return new Activity( |
||||
IRI::fromString($courseUrl), |
||||
new Definition( |
||||
LanguageMap::create([$languageIso => $course->getTitle()]), |
||||
null, |
||||
IRI::fromString('http://id.tincanapi.com/activitytype/lms/course') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CLp; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class LearningPath. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class LearningPath extends BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLp |
||||
*/ |
||||
private $lp; |
||||
|
||||
public function __construct(CLp $lp) |
||||
{ |
||||
$this->lp = $lp; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$lanIso = api_get_language_isocode(); |
||||
|
||||
$iri = $this->generateIri( |
||||
WEB_CODE_PATH, |
||||
'lp/lp_controller.php', |
||||
[ |
||||
'action' => 'view', |
||||
'lp_id' => $this->lp->getId(), |
||||
'isStudentView' => 'true', |
||||
] |
||||
); |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
new Definition( |
||||
LanguageMap::create([$lanIso => $this->lp->getName()]), |
||||
null, |
||||
IRI::fromString('http://adlnet.gov/expapi/activities/lesson') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CLpItem; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class LearningPathItem. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class LearningPathItem extends BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLpItem |
||||
*/ |
||||
private $lpItem; |
||||
|
||||
public function __construct(CLpItem $lpItem) |
||||
{ |
||||
$this->lpItem = $lpItem; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
$iri = $this->generateIri( |
||||
WEB_CODE_PATH, |
||||
'lp/lp_controller.php', |
||||
[ |
||||
'action' => 'view', |
||||
'lp_id' => $this->lpItem->getLpId(), |
||||
'isStudentView' => 'true', |
||||
'lp_item' => $this->lpItem->getId(), |
||||
] |
||||
); |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
new Definition( |
||||
LanguageMap::create([$langIso => $this->lpItem->getTitle()]), |
||||
null, |
||||
IRI::fromString('http://id.tincanapi.com/activitytype/resource') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Chamilo\CoreBundle\Entity\PortfolioCategory as PortfolioCategoryEntity; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class PortfolioCategory. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class PortfolioCategory extends BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\PortfolioCategory |
||||
*/ |
||||
private $category; |
||||
|
||||
public function __construct(PortfolioCategoryEntity $category) |
||||
{ |
||||
$this->category = $category; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$iri = $this->generateIri( |
||||
WEB_PATH, |
||||
'xapi/portfolio/', |
||||
[ |
||||
'user' => $this->category->getUser()->getId(), |
||||
'category' => $this->category->getId(), |
||||
] |
||||
); |
||||
|
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
$categoryDescription = $this->category->getDescription(); |
||||
|
||||
$definitionDescription = $categoryDescription |
||||
? LanguageMap::create([$langIso => $categoryDescription]) |
||||
: null; |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
new Definition( |
||||
LanguageMap::create([$langIso => $this->category->getTitle()]), |
||||
$definitionDescription, |
||||
IRI::fromString('http://id.tincanapi.com/activitytype/category') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Chamilo\CoreBundle\Entity\PortfolioComment as PortfolioCommentEntity; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
|
||||
/** |
||||
* Class PortfolioComment. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class PortfolioComment extends BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\PortfolioComment |
||||
*/ |
||||
private $comment; |
||||
|
||||
public function __construct(PortfolioCommentEntity $comment) |
||||
{ |
||||
$this->comment = $comment; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$iri = $this->generateIri( |
||||
WEB_CODE_PATH, |
||||
'portfolio/index.php', |
||||
[ |
||||
'action' => 'view', |
||||
'id' => $this->comment->getItem()->getId(), |
||||
'comment' => $this->comment->getId(), |
||||
] |
||||
); |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
new Definition( |
||||
null, |
||||
null, |
||||
IRI::fromString('http://activitystrea.ms/schema/1.0/comment') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,49 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Portfolio; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class PortfolioItem. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class PortfolioItem extends BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Portfolio |
||||
*/ |
||||
private $item; |
||||
|
||||
public function __construct(Portfolio $item) |
||||
{ |
||||
$this->item = $item; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
$iri = $this->generateIri( |
||||
WEB_CODE_PATH, |
||||
'portfolio/index.php', |
||||
['action' => 'view', 'id' => $this->item->getId()] |
||||
); |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
new Definition( |
||||
LanguageMap::create([$langIso => $this->item->getTitle()]), |
||||
null, |
||||
IRI::fromString('http://activitystrea.ms/schema/1.0/article') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CQuiz; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class Quiz. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class Quiz extends BaseActivity |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CQuiz |
||||
*/ |
||||
private $quiz; |
||||
|
||||
public function __construct(CQuiz $quiz) |
||||
{ |
||||
$this->quiz = $quiz; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
$iri = $this->generateIri( |
||||
WEB_CODE_PATH, |
||||
'exercise/overview.php', |
||||
['exerciseId' => $this->quiz->getId()] |
||||
); |
||||
|
||||
$definitionDescription = null; |
||||
|
||||
if ($this->quiz->getDescription()) { |
||||
$definitionDescription = LanguageMap::create( |
||||
[$langIso => $this->quiz->getDescription()] |
||||
); |
||||
} |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
new Definition( |
||||
LanguageMap::create([$langIso => $this->quiz->getTitle()]), |
||||
$definitionDescription, |
||||
IRI::fromString('http://adlnet.gov/expapi/activities/assessment') |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,170 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Answer; |
||||
use Chamilo\CourseBundle\Entity\CQuizQuestion; |
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Interaction\ChoiceInteractionDefinition; |
||||
use Xabbuh\XApi\Model\Interaction\InteractionComponent; |
||||
use Xabbuh\XApi\Model\Interaction\LongFillInInteractionDefinition; |
||||
use Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition; |
||||
use Xabbuh\XApi\Model\Interaction\OtherInteractionDefinition; |
||||
use Xabbuh\XApi\Model\Interaction\SequencingInteractionDefinition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class QuizQuestion. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class QuizQuestion extends BaseActivity |
||||
{ |
||||
private $question; |
||||
|
||||
public function __construct(CQuizQuestion $question) |
||||
{ |
||||
$this->question = $question; |
||||
} |
||||
|
||||
public function generate(): Activity |
||||
{ |
||||
$iri = $this->generateIri( |
||||
WEB_CODE_PATH, |
||||
'xapi/quiz/', |
||||
['question' => $this->question->getId()] |
||||
); |
||||
|
||||
return new Activity( |
||||
IRI::fromString($iri), |
||||
$this->generateActivityDefinitionFromQuestionType() |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @return \Xabbuh\XApi\Model\Interaction\InteractionDefinition |
||||
*/ |
||||
private function generateActivityDefinitionFromQuestionType() |
||||
{ |
||||
$languageIso = api_get_language_isocode(); |
||||
$courseId = api_get_course_int_id(); |
||||
|
||||
$questionTitle = strip_tags($this->question->getQuestion()); |
||||
$questionTitle = trim($questionTitle); |
||||
$questionDescription = strip_tags($this->question->getDescription()); |
||||
$questionDescription = trim($questionDescription); |
||||
|
||||
$titleMap = LanguageMap::create([$languageIso => $questionTitle]); |
||||
$descriptionMap = $questionDescription ? LanguageMap::create([$languageIso => $questionDescription]) : null; |
||||
|
||||
$objAnswer = new Answer($this->question->getId(), $courseId); |
||||
$objAnswer->read(); |
||||
|
||||
$type = IRI::fromString('http://adlnet.gov/expapi/activities/question'); |
||||
|
||||
switch ($this->question->getType()) { |
||||
case MULTIPLE_ANSWER: |
||||
case UNIQUE_ANSWER: |
||||
case UNIQUE_ANSWER_IMAGE: |
||||
case READING_COMPREHENSION: |
||||
$choices = []; |
||||
$correctResponsesPattern = []; |
||||
|
||||
for ($i = 1; $i <= $objAnswer->nbrAnswers; $i++) { |
||||
$choices[] = new InteractionComponent( |
||||
$objAnswer->iid[$i], |
||||
LanguageMap::create([$languageIso => $objAnswer->selectAnswer($i)]) |
||||
); |
||||
|
||||
if ($objAnswer->isCorrect($i)) { |
||||
$correctResponsesPattern[] = $objAnswer->iid[$i]; |
||||
} |
||||
} |
||||
|
||||
return new ChoiceInteractionDefinition( |
||||
$titleMap, |
||||
$descriptionMap, |
||||
$type, |
||||
null, |
||||
null, |
||||
[implode('[,]', $correctResponsesPattern)], |
||||
$choices |
||||
); |
||||
case DRAGGABLE: |
||||
$choices = []; |
||||
|
||||
for ($i = 1; $i <= $objAnswer->nbrAnswers; $i++) { |
||||
if ((int)$objAnswer->correct[$i] > 0) { |
||||
$choices[] = new InteractionComponent( |
||||
$objAnswer->correct[$i], |
||||
LanguageMap::create([$languageIso => $objAnswer->answer[$i]]) |
||||
); |
||||
} |
||||
} |
||||
|
||||
$correctResponsesPattern = array_slice($objAnswer->autoId, 0, $objAnswer->nbrAnswers / 2); |
||||
|
||||
return new SequencingInteractionDefinition( |
||||
$titleMap, |
||||
$descriptionMap, |
||||
$type, |
||||
null, |
||||
null, |
||||
[implode('[,]', $correctResponsesPattern)], |
||||
$choices |
||||
); |
||||
case MATCHING: |
||||
case MATCHING_DRAGGABLE: |
||||
/** @var array|InteractionComponent[] $source */ |
||||
$source = []; |
||||
/** @var array|InteractionComponent[] $source */ |
||||
$target = []; |
||||
$correctResponsesPattern = []; |
||||
|
||||
for ($i = 1; $i <= $objAnswer->nbrAnswers; $i++) { |
||||
$interactionComponent = new InteractionComponent( |
||||
$objAnswer->selectAutoId($i), |
||||
LanguageMap::create([$languageIso => $objAnswer->selectAnswer($i)]) |
||||
); |
||||
|
||||
if ((int)$objAnswer->correct[$i] > 0) { |
||||
$source[] = $interactionComponent; |
||||
|
||||
$correctResponsesPattern[] = $objAnswer->selectAutoId($i).'[.]'.$objAnswer->correct[$i]; |
||||
} else { |
||||
$target[] = $interactionComponent; |
||||
} |
||||
} |
||||
|
||||
return new MatchingInteractionDefinition( |
||||
$titleMap, |
||||
$descriptionMap, |
||||
$type, |
||||
null, |
||||
null, |
||||
[implode('[,]', $correctResponsesPattern)], |
||||
$source, |
||||
$target |
||||
); |
||||
case FREE_ANSWER: |
||||
return new LongFillInInteractionDefinition($titleMap, $descriptionMap, $type); |
||||
case FILL_IN_BLANKS: |
||||
case HOT_SPOT: |
||||
case HOT_SPOT_DELINEATION: |
||||
case MULTIPLE_ANSWER_COMBINATION: |
||||
case UNIQUE_ANSWER_NO_OPTION: |
||||
case MULTIPLE_ANSWER_TRUE_FALSE: |
||||
case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY: |
||||
case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
||||
case GLOBAL_MULTIPLE_ANSWER: |
||||
case CALCULATED_ANSWER: |
||||
case ANNOTATION: |
||||
case ORAL_EXPRESSION: |
||||
default: |
||||
return new OtherInteractionDefinition($titleMap, $descriptionMap, $type); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Activity; |
||||
|
||||
use Xabbuh\XApi\Model\Activity; |
||||
use Xabbuh\XApi\Model\Definition; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
|
||||
/** |
||||
* Class Site. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Activity |
||||
*/ |
||||
class Site extends BaseActivity |
||||
{ |
||||
public function generate(): Activity |
||||
{ |
||||
$platformLanguageIso = api_get_language_isocode( |
||||
api_get_setting('platformLanguage') |
||||
); |
||||
$platform = api_get_setting('Institution').' - '.api_get_setting('siteName'); |
||||
|
||||
return new Activity( |
||||
IRI::fromString('http://id.tincanapi.com/activitytype/lms'), |
||||
new Definition( |
||||
LanguageMap::create([$platformLanguageIso => $platform]) |
||||
) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Actor; |
||||
|
||||
use Xabbuh\XApi\Model\Agent; |
||||
|
||||
/** |
||||
* Class BaseActor. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Actor |
||||
*/ |
||||
abstract class BaseActor |
||||
{ |
||||
abstract public function generate(): Agent; |
||||
} |
||||
@ -0,0 +1,35 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Actor; |
||||
|
||||
use Chamilo\UserBundle\Entity\User as UserEntity; |
||||
use Xabbuh\XApi\Model\Agent; |
||||
use Xabbuh\XApi\Model\InverseFunctionalIdentifier; |
||||
use Xabbuh\XApi\Model\IRI; |
||||
|
||||
/** |
||||
* Class User. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Actor |
||||
*/ |
||||
class User extends BaseActor |
||||
{ |
||||
private $user; |
||||
|
||||
public function __construct(UserEntity $user) |
||||
{ |
||||
$this->user = $user; |
||||
} |
||||
|
||||
public function generate(): Agent |
||||
{ |
||||
return new Agent( |
||||
InverseFunctionalIdentifier::withMbox( |
||||
IRI::fromString('mailto:'.$this->user->getEmail()) |
||||
), |
||||
$this->user->getCompleteName() |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\Course as CourseActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\Site as SiteActivity; |
||||
use Xabbuh\XApi\Model\Context; |
||||
use Xabbuh\XApi\Model\ContextActivities; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
use Xabbuh\XApi\Model\StatementId; |
||||
use Xabbuh\XApi\Model\Uuid; |
||||
use XApiPlugin; |
||||
|
||||
/** |
||||
* Class BaseStatement |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Statement |
||||
*/ |
||||
abstract class BaseStatement |
||||
{ |
||||
abstract public function generate(): Statement; |
||||
|
||||
protected function generateStatementId(string $type, string $value): StatementId |
||||
{ |
||||
$uuid = Uuid::uuid5( |
||||
XApiPlugin::create()->get(XApiPlugin::SETTING_UUID_NAMESPACE), |
||||
"$type/$value" |
||||
); |
||||
|
||||
return StatementId::fromUuid($uuid); |
||||
} |
||||
|
||||
protected function generateContext(): Context |
||||
{ |
||||
$platform = api_get_setting('Institution').' - '.api_get_setting('siteName'); |
||||
|
||||
$groupingActivities = []; |
||||
$groupingActivities[] = (new SiteActivity())->generate(); |
||||
|
||||
if (api_get_course_id()) { |
||||
$groupingActivities[] = (new CourseActivity())->generate(); |
||||
} |
||||
|
||||
return (new Context()) |
||||
->withPlatform($platform) |
||||
->withLanguage(api_get_language_isocode()) |
||||
->withContextActivities( |
||||
new ContextActivities(null, $groupingActivities) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,61 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CLp as CLpEntity; |
||||
use Chamilo\CourseBundle\Entity\CLpView as CLpViewEntity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\LearningPath as LearningPathActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Completed; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Score; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
/** |
||||
* Class LearningPathCompleted. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Statement |
||||
*/ |
||||
class LearningPathCompleted extends BaseStatement |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLpView |
||||
*/ |
||||
private $lpView; |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLp |
||||
*/ |
||||
private $lp; |
||||
|
||||
public function __construct(CLpViewEntity $lpView, CLpEntity $lp) |
||||
{ |
||||
$this->lpView = $lpView; |
||||
$this->lp = $lp; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$user = api_get_user_entity($this->lpView->getUserId()); |
||||
$userActor = new UserActor($user); |
||||
$completedVerb = new Completed(); |
||||
$lpActivity = new LearningPathActivity($this->lp); |
||||
|
||||
return new Statement( |
||||
null, |
||||
$userActor->generate(), |
||||
$completedVerb->generate(), |
||||
$lpActivity->generate(), |
||||
new Result( |
||||
new Score(1, 100, 0, 100), |
||||
null, |
||||
true |
||||
), |
||||
null, |
||||
api_get_utc_datetime(null, false, true), |
||||
null, |
||||
$this->generateContext() |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CLp; |
||||
use Chamilo\CourseBundle\Entity\CLpItem; |
||||
use Chamilo\CourseBundle\Entity\CLpItemView; |
||||
use Chamilo\CourseBundle\Entity\CLpView; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\LearningPath; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\LearningPathItem as LearningPathItemActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Viewed as ViewedVerb; |
||||
use Database; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
/** |
||||
* Class LearningPathItemViewed |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Statement |
||||
*/ |
||||
class LearningPathItemViewed extends BaseStatement |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLpItemView |
||||
*/ |
||||
private $lpItemView; |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLpItem |
||||
*/ |
||||
private $lpItem; |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CLpView |
||||
*/ |
||||
private $lpView; |
||||
|
||||
public function __construct(CLpItemView $lpItemView, CLpItem $lpItem, CLpView $lpView) |
||||
{ |
||||
$this->lpItemView = $lpItemView; |
||||
$this->lpItem = $lpItem; |
||||
$this->lpView = $lpView; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$user = api_get_user_entity($this->lpView->getUserId()); |
||||
$lp = Database::getManager()->find(CLp::class, $this->lpView->getLpId()); |
||||
|
||||
$userActor = new UserActor($user); |
||||
$viewedVerb = new ViewedVerb(); |
||||
$lpItemActivity = new LearningPathItemActivity($this->lpItem); |
||||
$lpActivity = new LearningPath($lp); |
||||
|
||||
$context = $this->generateContext(); |
||||
$contextActivities = $context |
||||
->getContextActivities() |
||||
->withAddedGroupingActivity($lpActivity->generate()); |
||||
|
||||
return new Statement( |
||||
null, |
||||
$userActor->generate(), |
||||
$viewedVerb->generate(), |
||||
$lpItemActivity->generate(), |
||||
new Result( |
||||
null, |
||||
null, |
||||
'completed' === $this->lpItemView->getStatus(), |
||||
null, |
||||
'PT'.$this->lpItemView->getTotalTime().'S' |
||||
), |
||||
null, |
||||
api_get_utc_datetime(null, false, true), |
||||
null, |
||||
$context->withContextActivities($contextActivities) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,72 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CoreBundle\Entity\PortfolioComment as PortfolioCommentEntity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioComment as PortfolioCommentActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem as PortfolioItemActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Commented as CommentedVerb; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Replied as RepliedVerb; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
class PortfolioItemCommented extends BaseStatement |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\PortfolioComment |
||||
*/ |
||||
private $comment; |
||||
|
||||
public function __construct(PortfolioCommentEntity $comment) |
||||
{ |
||||
$this->comment = $comment; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$portfolioItem = $this->comment->getItem(); |
||||
$commentParent = $this->comment->getParent(); |
||||
|
||||
$userActor = new UserActor($this->comment->getAuthor()); |
||||
$statementResult = new Result(null, null, null, $this->comment->getContent()); |
||||
|
||||
$context = $this->generateContext(); |
||||
|
||||
if ($commentParent) { |
||||
$repliedVerb = new RepliedVerb(); |
||||
|
||||
$itemActivity = new PortfolioItemActivity($portfolioItem); |
||||
$parentCommentActivity = new PortfolioCommentActivity($commentParent); |
||||
|
||||
$contextActivities = $context |
||||
->getContextActivities() |
||||
->withAddedGroupingActivity($itemActivity->generate()); |
||||
|
||||
return new Statement( |
||||
null, |
||||
$userActor->generate(), |
||||
$repliedVerb->generate(), |
||||
$parentCommentActivity->generate(), |
||||
$statementResult, |
||||
null, |
||||
$this->comment->getDate(), |
||||
null, |
||||
$context->withContextActivities($contextActivities) |
||||
); |
||||
} else { |
||||
$itemShared = new PortfolioItemShared($portfolioItem); |
||||
|
||||
$commentedVerb = new CommentedVerb(); |
||||
|
||||
return $itemShared->generate() |
||||
->withActor($userActor->generate()) |
||||
->withVerb($commentedVerb->generate()) |
||||
->withStored($this->comment->getDate()) |
||||
->withResult($statementResult) |
||||
->withContext($context); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,65 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Portfolio as PortfolioEntity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioCategory as PortfolioCategoryActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem as PortfolioItemActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Shared as SharedVerb; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
/** |
||||
* Class PortfolioItemShared. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Statement |
||||
*/ |
||||
class PortfolioItemShared extends BaseStatement |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Portfolio |
||||
*/ |
||||
private $portfolioItem; |
||||
|
||||
public function __construct(PortfolioEntity $item) |
||||
{ |
||||
$this->portfolioItem = $item; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$userActor = new UserActor( |
||||
$this->portfolioItem->getUser() |
||||
); |
||||
$sharedVerb = new SharedVerb(); |
||||
$itemActivity = new PortfolioItemActivity($this->portfolioItem); |
||||
|
||||
$context = $this->generateContext(); |
||||
|
||||
if ($this->portfolioItem->getCategory()) { |
||||
$categoryActivity = new PortfolioCategoryActivity($this->portfolioItem->getCategory()); |
||||
|
||||
$contextActivities = $context |
||||
->getContextActivities() |
||||
->withAddedCategoryActivity( |
||||
$categoryActivity->generate() |
||||
); |
||||
|
||||
$context = $context->withContextActivities($contextActivities); |
||||
} |
||||
|
||||
return new Statement( |
||||
null, |
||||
$userActor->generate(), |
||||
$sharedVerb->generate(), |
||||
$itemActivity->generate(), |
||||
null, |
||||
null, |
||||
$this->portfolioItem->getCreationDate(), |
||||
null, |
||||
$context |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,70 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CoreBundle\Entity\TrackEExercises; |
||||
use Chamilo\CourseBundle\Entity\CQuiz; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\Quiz as QuizActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Completed as CompletedVerb; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Score; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
/** |
||||
* Class QuizCompleted. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Statement |
||||
*/ |
||||
class QuizCompleted extends BaseStatement |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\TrackEExercises |
||||
*/ |
||||
private $exe; |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CQuiz |
||||
*/ |
||||
private $quiz; |
||||
|
||||
public function __construct(TrackEExercises $exe, CQuiz $quiz) |
||||
{ |
||||
$this->exe = $exe; |
||||
$this->quiz = $quiz; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$user = api_get_user_entity($this->exe->getExeUserId()); |
||||
|
||||
$userActor = new UserActor($user); |
||||
$completedVerb = new CompletedVerb(); |
||||
$quizActivity = new QuizActivity($this->quiz); |
||||
|
||||
$rawResult = $this->exe->getExeResult(); |
||||
$maxResult = $this->exe->getExeWeighting(); |
||||
$scaledResult = $rawResult / $maxResult; |
||||
|
||||
$duration = $this->exe->getExeDuration(); |
||||
|
||||
return new Statement( |
||||
null, |
||||
$userActor->generate(), |
||||
$completedVerb->generate(), |
||||
$quizActivity->generate(), |
||||
new Result( |
||||
new Score($scaledResult, $rawResult, 0, $maxResult), |
||||
null, |
||||
true, |
||||
null, |
||||
$duration ? "PT{$duration}S" : null |
||||
), |
||||
null, |
||||
$this->exe->getExeDate(), |
||||
null, |
||||
$this->generateContext() |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CoreBundle\Entity\TrackEAttempt; |
||||
use Chamilo\CourseBundle\Entity\CQuiz; |
||||
use Chamilo\CourseBundle\Entity\CQuizQuestion; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\Quiz as QuizActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\QuizQuestion as QuizQuestionActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Answered as AnsweredVerb; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Score; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
/** |
||||
* Class QuizQuestionAnswered. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Statement |
||||
*/ |
||||
class QuizQuestionAnswered extends BaseStatement |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\TrackEAttempt |
||||
*/ |
||||
private $attempt; |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CQuizQuestion |
||||
*/ |
||||
private $question; |
||||
/** |
||||
* @var \Chamilo\CourseBundle\Entity\CQuiz |
||||
*/ |
||||
private $quiz; |
||||
|
||||
public function __construct(TrackEAttempt $attempt, CQuizQuestion $question, CQuiz $quiz) |
||||
{ |
||||
$this->attempt = $attempt; |
||||
$this->question = $question; |
||||
$this->quiz = $quiz; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$user = api_get_user_entity($this->attempt->getUserId()); |
||||
|
||||
$userActor = new UserActor($user); |
||||
$answeredVerb = new AnsweredVerb(); |
||||
$questionActivity = new QuizQuestionActivity($this->question); |
||||
$quizActivity = new QuizActivity($this->quiz); |
||||
|
||||
$rawResult = $this->attempt->getMarks(); |
||||
$maxResult = $this->question->getPonderation(); |
||||
$scaledResult = $rawResult / $maxResult; |
||||
|
||||
$context = $this->generateContext(); |
||||
$contextActivities = $context |
||||
->getContextActivities() |
||||
->withAddedGroupingActivity($quizActivity->generate()); |
||||
|
||||
return new Statement( |
||||
null, |
||||
$userActor->generate(), |
||||
$answeredVerb->generate(), |
||||
$questionActivity->generate(), |
||||
new Result( |
||||
new Score($scaledResult, $rawResult, null, $maxResult), |
||||
$rawResult > 0, |
||||
true |
||||
), |
||||
null, |
||||
$this->attempt->getTms(), |
||||
null, |
||||
$context->withContextActivities($contextActivities) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class Answered. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
class Answered extends BaseVerb |
||||
{ |
||||
public function generate(): Verb |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
return new Verb( |
||||
IRI::fromString('http://adlnet.gov/expapi/verbs/answered'), |
||||
LanguageMap::create([$langIso => get_lang('Answered')]) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class BaseVerb |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
abstract class BaseVerb |
||||
{ |
||||
public abstract function generate(): Verb; |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class Commented. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
class Commented extends BaseVerb |
||||
{ |
||||
public function generate(): Verb |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
return new Verb( |
||||
IRI::fromString('http://adlnet.gov/expapi/verbs/commented'), |
||||
LanguageMap::create([$langIso => get_lang('Commented')]) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class Completed. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
class Completed extends BaseVerb |
||||
{ |
||||
public function generate(): Verb |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
return new Verb( |
||||
IRI::fromString('http://activitystrea.ms/schema/1.0/complete'), |
||||
LanguageMap::create([$langIso => get_lang('Completed')]) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class Replied. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
class Replied extends BaseVerb |
||||
{ |
||||
|
||||
public function generate(): Verb |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
return new Verb( |
||||
IRI::fromString('http://id.tincanapi.com/verb/replied'), |
||||
LanguageMap::create([$langIso => get_lang('Replied')]) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class Shared. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
class Shared extends BaseVerb |
||||
{ |
||||
public function generate(): Verb |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
return new Verb( |
||||
IRI::fromString('http://adlnet.gov/expapi/verbs/shared'), |
||||
LanguageMap::create([$langIso => get_lang('Shared')]) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
use Xabbuh\XApi\Model\IRI; |
||||
use Xabbuh\XApi\Model\LanguageMap; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Class Viewed. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\ToolExperience\Verb |
||||
*/ |
||||
class Viewed extends BaseVerb |
||||
{ |
||||
public function generate(): Verb |
||||
{ |
||||
$langIso = api_get_language_isocode(); |
||||
|
||||
return new Verb( |
||||
IRI::fromString('http://id.tincanapi.com/verb/viewed'), |
||||
LanguageMap::create([$langIso => get_lang('Viewed')]) |
||||
); |
||||
} |
||||
} |
||||
@ -1,107 +0,0 @@ |
||||
<?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; |
||||
use Xabbuh\XApi\Model\StatementId; |
||||
use Xabbuh\XApi\Model\Uuid; |
||||
use Xabbuh\XApi\Model\Verb; |
||||
|
||||
/** |
||||
* Trait XApiStatementTrait. |
||||
*/ |
||||
trait XApiStatementTrait |
||||
{ |
||||
/** |
||||
* @return \Xabbuh\XApi\Model\Agent |
||||
*/ |
||||
protected function generateActor(UserEntity $user) |
||||
{ |
||||
$mboxIri = IRI::fromString( |
||||
'mailto:'.$user->getEmail() |
||||
); |
||||
|
||||
return new Agent( |
||||
InverseFunctionalIdentifier::withMbox($mboxIri), |
||||
$user->getCompleteName() |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @param string $word |
||||
* @param string $uri |
||||
* |
||||
* @return \Xabbuh\XApi\Model\Verb |
||||
*/ |
||||
protected function generateVerb($word, $uri) |
||||
{ |
||||
$languageMap = XApiPlugin::create()->getLangMap($word); |
||||
|
||||
return new Verb( |
||||
IRI::fromString($uri), |
||||
LanguageMap::create($languageMap) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @param string $type |
||||
* @param string $value |
||||
* |
||||
* @return \Xabbuh\XApi\Model\StatementId |
||||
*/ |
||||
protected function generateId($type, $value) |
||||
{ |
||||
$uuid = Uuid::uuid5( |
||||
XApiPlugin::create()->get(XApiPlugin::SETTING_UUID_NAMESPACE), |
||||
"$type/$value" |
||||
); |
||||
|
||||
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]) |
||||
) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @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…
Reference in new issue