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

PortfolioItemScored   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 32 2
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
6
7
use Chamilo\CoreBundle\Entity\PortfolioAttachment;
8
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioItem as PortfolioItemActivity;
9
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User;
10
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Scored;
11
use Xabbuh\XApi\Model\Result;
12
use Xabbuh\XApi\Model\Score;
13
use Xabbuh\XApi\Model\Statement;
14
15
class PortfolioItemScored extends PortfolioItem
16
{
17
    use PortfolioAttachmentsTrait;
18
19
    public function generate(): Statement
20
    {
21
        $user = api_get_user_entity(api_get_user_id());
22
23
        $itemAttachments = \Database::getManager()
24
            ->getRepository(PortfolioAttachment::class)
25
            ->findFromItem($this->item)
26
        ;
27
28
        $maxScore = (float) api_get_course_setting('portfolio_max_score');
29
        $rawScore = $this->item->getScore();
30
        $scaled = $maxScore ? ($rawScore / $maxScore) : 0;
31
32
        $actor = new User($user);
33
        $verb = new Scored();
34
        $object = new PortfolioItemActivity($this->item);
35
        $context = $this->generateContext();
36
        $attachments = $this->generateAttachments($itemAttachments, $this->item->getUser());
37
        $score = new Score($scaled, $rawScore, 0, $maxScore);
38
        $result = new Result($score);
39
40
        return new Statement(
41
            $this->generateStatementId('portfolio-item'),
42
            $actor->generate(),
43
            $verb->generate(),
44
            $object->generate(),
45
            $result,
46
            null,
47
            api_get_utc_datetime(null, false, true),
48
            null,
49
            $context,
50
            $attachments
51
        );
52
    }
53
}
54