Passed
Pull Request — 1.11.x (#4368)
by Angel Fernando Quiroz
08:24
created

PortfolioItem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement;
6
7
use Chamilo\CoreBundle\Entity\Portfolio;
8
use Chamilo\CoreBundle\Entity\PortfolioAttachment;
9
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\PortfolioCategory;
10
use Chamilo\UserBundle\Entity\User;
11
use Xabbuh\XApi\Model\Context;
12
13
abstract class PortfolioItem extends BaseStatement
14
{
15
    protected $item;
16
17
    public function __construct(Portfolio $item)
18
    {
19
        $this->item = $item;
20
    }
21
22
    protected function generateContext(): Context
23
    {
24
        $context = parent::generateContext();
25
26
        $category = $this->item->getCategory();
27
28
        if ($category) {
0 ignored issues
show
introduced by
$category is of type Chamilo\CoreBundle\Entity\PortfolioCategory, thus it always evaluated to true.
Loading history...
29
            $categoryActivity = new PortfolioCategory($category);
30
31
            $contextActivities = $context
32
                ->getContextActivities()
33
                ->withAddedCategoryActivity(
34
                    $categoryActivity->generate()
35
                )
36
            ;
37
38
            $context  = $context->withContextActivities($contextActivities);
39
        }
40
41
        return $context;
42
    }
43
}