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 Chamilo\CourseBundle\Repository\CShortcutRepository; |
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
14
|
|
|
use Stringable; |
15
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
16
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
17
|
|
|
|
18
|
|
|
#[ORM\Table(name: 'c_shortcut')] |
19
|
|
|
#[ORM\Entity(repositoryClass: CShortcutRepository::class)] |
20
|
|
|
class CShortcut extends AbstractResource implements ResourceInterface, Stringable |
21
|
|
|
{ |
22
|
|
|
#[ORM\Column(name: 'id', type: 'integer')] |
23
|
|
|
#[ORM\Id] |
24
|
|
|
#[ORM\GeneratedValue] |
25
|
|
|
protected ?int $id = null; |
26
|
|
|
|
27
|
|
|
#[Assert\NotBlank] |
28
|
|
|
#[Groups(['cshortcut:read'])] |
29
|
|
|
#[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
30
|
|
|
protected string $title; |
31
|
|
|
|
32
|
|
|
#[ORM\OneToOne(targetEntity: ResourceNode::class, inversedBy: 'shortCut')] |
33
|
|
|
#[ORM\JoinColumn(name: 'shortcut_node_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
34
|
|
|
protected ResourceNode $shortCutNode; |
35
|
|
|
|
36
|
|
|
#[Groups(['cshortcut:read'])] |
37
|
|
|
protected string $url; |
38
|
|
|
|
39
|
|
|
#[Groups(['cshortcut:read'])] |
40
|
|
|
protected string $tool; |
41
|
|
|
|
42
|
|
|
#[Groups(['cshortcut:read'])] |
43
|
|
|
protected string $type; |
44
|
|
|
|
45
|
|
|
#[Groups(['cshortcut:read'])] |
46
|
|
|
private ?string $customImageUrl = null; |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function __toString(): string |
50
|
|
|
{ |
51
|
|
|
return $this->getTitle(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getTitle(): string |
55
|
|
|
{ |
56
|
|
|
return $this->title; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getUrl(): string |
60
|
|
|
{ |
61
|
|
|
return '/r/'.$this->getShortCutNode()->getResourceType()->getTool()->getTitle(). |
62
|
|
|
'/'.$this->getShortCutNode()->getResourceType()->getTitle(). |
63
|
|
|
'/'.$this->getShortCutNode()->getId(). |
64
|
|
|
'/link'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getTool(): string |
68
|
|
|
{ |
69
|
|
|
return $this->getShortCutNode()->getResourceType()->getTool()->getTitle(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getType(): string |
73
|
|
|
{ |
74
|
|
|
return $this->getShortCutNode()->getResourceType()->getTitle(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setTitle(string $title): self |
78
|
|
|
{ |
79
|
|
|
$this->title = $title; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getResourceIdentifier(): int |
85
|
|
|
{ |
86
|
|
|
return $this->id; |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getShortCutNode(): ResourceNode |
90
|
|
|
{ |
91
|
|
|
return $this->shortCutNode; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setShortCutNode(ResourceNode $shortCutNode): self |
95
|
|
|
{ |
96
|
|
|
$this->shortCutNode = $shortCutNode; |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getCustomImageUrl(): ?string |
102
|
|
|
{ |
103
|
|
|
return $this->customImageUrl; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setCustomImageUrl(?string $customImageUrl): self |
107
|
|
|
{ |
108
|
|
|
$this->customImageUrl = $customImageUrl; |
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getId(): int |
114
|
|
|
{ |
115
|
|
|
return $this->id; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getResourceName(): string |
119
|
|
|
{ |
120
|
|
|
return $this->getTitle(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setResourceName(string $name): self |
124
|
|
|
{ |
125
|
|
|
return $this->setTitle($name); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|