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

PortfolioItemScored   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 24
c 1
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 27 2
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\PortfolioItem as PortfolioItemActivity;
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 PortfolioItemScored extends PortfolioItem
15
{
16
    use PortfolioAttachmentsTrait;
0 ignored issues
show
Bug introduced by
The trait Chamilo\PluginBundle\XAp...rtfolioAttachmentsTrait requires the property $comment which is not provided by Chamilo\PluginBundle\XAp...ent\PortfolioItemScored.
Loading history...
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->item->getScore();
24
        $scaled = $maxScore ? ($rawScore / $maxScore) : 0;
25
26
        $actor = new User($user);
27
        $verb = new Scored();
28
        $object = new PortfolioItemActivity($this->item);
29
        $context = $this->generateContext();
30
        $attachments = $this->generateAttachmentsForItem($this->item);
31
        $score = new Score($scaled, $rawScore, 0, $maxScore);
32
        $result = new Result($score);
33
34
        return new Statement(
35
            $this->generateStatementId('portfolio-item'),
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