Passed
Push — master ( f23aa1...456a08 )
by Julito
11:24 queued 01:42
created

CShortcut::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\ResourceNode;
12
use Doctrine\ORM\Mapping as ORM;
13
use Symfony\Component\Serializer\Annotation\Groups;
14
use Symfony\Component\Validator\Constraints as Assert;
15
16
/**
17
 * @ORM\Table(name="c_shortcut")
18
 * @ORM\Entity
19
 */
20
class CShortcut extends AbstractResource implements ResourceInterface
21
{
22
    /**
23
     * @ORM\Column(name="id", type="integer")
24
     * @ORM\Id
25
     * @ORM\GeneratedValue
26
     */
27
    protected int $id;
28
29
    /**
30
     * @Groups({"cshortcut:read"})
31
     *
32
     * @Assert\NotBlank
33
     *
34
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
35
     */
36
    protected string $name;
37
38
    /**
39
     * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode")
40
     * @ORM\JoinColumn(name="shortcut_node_id", referencedColumnName="id" )
41
     */
42
    protected ResourceNode $shortCutNode;
43
44
    /**
45
    * @Groups({"cshortcut:read"})
46
    */
47
    protected string $url;
48
49
    /**
50
     * @Groups({"cshortcut:read"})
51
     */
52
    protected string $tool;
53
54
    /**
55
     * @Groups({"cshortcut:read"})
56
     */
57
    protected string $type;
58
59
    public function __toString(): string
60
    {
61
        return $this->getName();
62
    }
63
64
    public function getName(): string
65
    {
66
        return $this->name;
67
    }
68
69
    public function getUrl()
70
    {
71
        return
72
            '/r/'.$this->getShortCutNode()->getResourceType()->getTool()->getName().
73
            '/'.$this->getShortCutNode()->getResourceType()->getName().
74
            '/'.$this->getShortCutNode()->getId().
75
            '/link';
76
    }
77
78
    public function getTool()
79
    {
80
        return $this->getShortCutNode()->getResourceType()->getTool()->getName();
81
    }
82
83
    public function getType()
84
    {
85
        return $this->getShortCutNode()->getResourceType()->getName();
86
    }
87
88
    public function setName(string $name): self
89
    {
90
        $this->name = $name;
91
92
        return $this;
93
    }
94
95
    public function getResourceIdentifier(): int
96
    {
97
        return $this->id;
98
    }
99
100
    public function getShortCutNode(): ResourceNode
101
    {
102
        return $this->shortCutNode;
103
    }
104
105
    public function setShortCutNode(ResourceNode $shortCutNode): self
106
    {
107
        $this->shortCutNode = $shortCutNode;
108
109
        return $this;
110
    }
111
112
    public function getId(): int
113
    {
114
        return $this->id;
115
    }
116
117
    public function getResourceName(): string
118
    {
119
        return $this->getName();
120
    }
121
122
    public function setResourceName(string $name): self
123
    {
124
        return $this->setName($name);
125
    }
126
}
127