parent
b0145600e8
commit
2d8720a9ad
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
class HookPortfolioCommentScored extends HookEvent implements HookPortfolioCommentScoredEventInterface |
||||
{ |
||||
protected function __construct() |
||||
{ |
||||
parent::__construct('HookPortfolioCommentScored'); |
||||
} |
||||
|
||||
public function notifyCommentScored() |
||||
{ |
||||
/** @var HookPortfolioCommentScoredObserverInterface $observer */ |
||||
foreach ($this->observers as $observer) { |
||||
$observer->hookCommentScored($this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
class HookPortfolioItemScored extends HookEvent implements HookPortfolioItemScoredEventInterface |
||||
{ |
||||
protected function __construct() |
||||
{ |
||||
parent::__construct('HookPortfolioItemScored'); |
||||
} |
||||
|
||||
public function notifyItemScored(): void |
||||
{ |
||||
/** @var HookPortfolioItemScoredObserverInterface $observer */ |
||||
foreach ($this->observers as $observer) { |
||||
$observer->hookItemScored($this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
interface HookPortfolioCommentScoredEventInterface extends HookEventInterface |
||||
{ |
||||
public function notifyCommentScored(); |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
interface HookPortfolioCommentScoredObserverInterface extends HookObserverInterface |
||||
{ |
||||
public function hookCommentScored(HookPortfolioCommentScoredEventInterface $hookEvent); |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
interface HookPortfolioItemScoredEventInterface extends HookEventInterface |
||||
{ |
||||
public function notifyItemScored(); |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
interface HookPortfolioItemScoredObserverInterface extends HookObserverInterface |
||||
{ |
||||
public function hookItemScored(HookPortfolioItemScoredEventInterface $hookEvent); |
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\PortfolioComment; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\PortfolioCommentScored; |
||||
|
||||
class XApiPortfolioCommentScoredHookObserver extends XApiActivityHookObserver implements HookPortfolioCommentScoredObserverInterface |
||||
{ |
||||
public function hookCommentScored(HookPortfolioCommentScoredEventInterface $hookEvent) |
||||
{ |
||||
/** @var PortfolioComment $comment */ |
||||
$comment = $hookEvent->getEventData()['comment']; |
||||
|
||||
$statement = (new PortfolioCommentScored($comment))->generate(); |
||||
|
||||
$this->saveSharedStatement($statement); |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\Portfolio; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Statement\PortfolioItemScored; |
||||
|
||||
class XApiPortfolioItemScoredHookObserver extends XApiActivityHookObserver implements HookPortfolioItemScoredObserverInterface |
||||
{ |
||||
public function hookItemScored(HookPortfolioItemScoredEventInterface $hookEvent) |
||||
{ |
||||
/** @var Portfolio $item */ |
||||
$item = $hookEvent->getEventData()['item']; |
||||
|
||||
$statement = (new PortfolioItemScored($item))->generate(); |
||||
|
||||
$this->saveSharedStatement($statement); |
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CoreBundle\Entity\PortfolioAttachment; |
||||
use Chamilo\CoreBundle\Entity\PortfolioComment; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioComment as PortfolioCommentActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Scored; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Score; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
class PortfolioCommentScored extends BaseStatement |
||||
{ |
||||
use PortfolioAttachmentsTrait; |
||||
|
||||
/** @var PortfolioComment */ |
||||
private $comment; |
||||
|
||||
public function __construct(PortfolioComment $comment) |
||||
{ |
||||
$this->comment = $comment; |
||||
} |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$user = api_get_user_entity(api_get_user_id()); |
||||
|
||||
$commentAttachments = \Database::getManager() |
||||
->getRepository(PortfolioAttachment::class) |
||||
->findFromComment($this->comment) |
||||
; |
||||
|
||||
$maxScore = (float) api_get_course_setting('portfolio_max_score'); |
||||
$rawScore = $this->comment->getScore(); |
||||
$scaled = $maxScore ? ($rawScore / $maxScore) : 0; |
||||
|
||||
$actor = new User($user); |
||||
$verb = new Scored(); |
||||
$object = new PortfolioCommentActivity($this->comment); |
||||
$context = $this->generateContext(); |
||||
$attachments = $this->generateAttachments($commentAttachments, $this->comment->getAuthor()); |
||||
$score = new Score($scaled, $rawScore, 0, $maxScore); |
||||
$result = new Result($score); |
||||
|
||||
return new Statement( |
||||
$this->generateStatementId('portfolio-comment'), |
||||
$actor->generate(), |
||||
$verb->generate(), |
||||
$object->generate(), |
||||
$result, |
||||
null, |
||||
api_get_utc_datetime(null, false, true), |
||||
null, |
||||
$context, |
||||
$attachments |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
||||
|
||||
use Chamilo\CoreBundle\Entity\PortfolioAttachment; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem as PortfolioItemActivity; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User; |
||||
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Scored; |
||||
use Xabbuh\XApi\Model\Result; |
||||
use Xabbuh\XApi\Model\Score; |
||||
use Xabbuh\XApi\Model\Statement; |
||||
|
||||
class PortfolioItemScored extends PortfolioItem |
||||
{ |
||||
use PortfolioAttachmentsTrait; |
||||
|
||||
public function generate(): Statement |
||||
{ |
||||
$user = api_get_user_entity(api_get_user_id()); |
||||
|
||||
$itemAttachments = \Database::getManager() |
||||
->getRepository(PortfolioAttachment::class) |
||||
->findFromItem($this->item) |
||||
; |
||||
|
||||
$maxScore = (float) api_get_course_setting('portfolio_max_score'); |
||||
$rawScore = $this->item->getScore(); |
||||
$scaled = $maxScore ? ($rawScore / $maxScore) : 0; |
||||
|
||||
$actor = new User($user); |
||||
$verb = new Scored(); |
||||
$object = new PortfolioItemActivity($this->item); |
||||
$context = $this->generateContext(); |
||||
$attachments = $this->generateAttachments($itemAttachments, $this->item->getUser()); |
||||
$score = new Score($scaled, $rawScore, 0, $maxScore); |
||||
$result = new Result($score); |
||||
|
||||
return new Statement( |
||||
$this->generateStatementId('portfolio-item'), |
||||
$actor->generate(), |
||||
$verb->generate(), |
||||
$object->generate(), |
||||
$result, |
||||
null, |
||||
api_get_utc_datetime(null, false, true), |
||||
null, |
||||
$context, |
||||
$attachments |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\ToolExperience\Verb; |
||||
|
||||
class Scored extends BaseVerb |
||||
{ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct( |
||||
'http://adlnet.gov/expapi/verbs/scored', |
||||
'Scored' |
||||
); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue