Passed
Pull Request — 1.11.x (#4501)
by Angel Fernando Quiroz
09:49
created

PortfolioCommentScored::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 27
rs 9.568
cc 2
nc 2
nop 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
6
7
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioComment as PortfolioCommentActivity;
8
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User;
9
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Scored;
10
use Xabbuh\XApi\Model\Result;
11
use Xabbuh\XApi\Model\Score;
12
use Xabbuh\XApi\Model\Statement;
13
14
class PortfolioCommentScored extends PortfolioComment
15
{
16
    use PortfolioAttachmentsTrait;
17
18
    public function generate(): Statement
19
    {
20
        $user = api_get_user_entity(api_get_user_id());
21
22
        $maxScore = (float) api_get_course_setting('portfolio_max_score');
23
        $rawScore = $this->comment->getScore();
24
        $scaled = $maxScore ? ($rawScore / $maxScore) : 0;
25
26
        $actor = new User($user);
27
        $verb = new Scored();
28
        $object = new PortfolioCommentActivity($this->comment);
29
        $context = $this->generateContext();
30
        $attachments = $this->generateAttachmentsForComment($this->comment);
31
        $score = new Score($scaled, $rawScore, 0, $maxScore);
32
        $result = new Result($score);
33
34
        return new Statement(
35
            $this->generateStatementId('portfolio-comment'),
36
            $actor->generate(),
37
            $verb->generate(),
38
            $object->generate(),
39
            $result,
40
            null,
41
            api_get_utc_datetime(null, false, true),
42
            null,
43
            $context,
44
            $attachments
45
        );
46
    }
47
}
48