Passed
Push — master ( ec8fd5...913f34 )
by Julito
21:20 queued 08:00
created

CTool   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 35
dl 0
loc 184
rs 10
c 4
b 2
f 0
wmc 20

20 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A __toString() 0 3 1
A getVisibility() 0 3 1
A __construct() 0 3 1
A setTool() 0 5 1
A setName() 0 5 1
A getIid() 0 3 1
A getSession() 0 3 1
A setCourse() 0 5 1
A setPosition() 0 5 1
A getResourceIdentifier() 0 3 1
A getPosition() 0 3 1
A setResourceName() 0 3 1
A getNameToTranslate() 0 3 1
A getResourceName() 0 3 1
A setSession() 0 5 1
A postPersist() 0 2 1
A getTool() 0 3 1
A setVisibility() 0 5 1
A getCourse() 0 3 1
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\Course;
11
use Chamilo\CoreBundle\Entity\ResourceInterface;
12
use Chamilo\CoreBundle\Entity\Session;
13
use Chamilo\CoreBundle\Entity\Tool;
14
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
15
use Doctrine\ORM\Event\LifecycleEventArgs;
16
use Doctrine\ORM\Mapping as ORM;
17
use Gedmo\Mapping\Annotation as Gedmo;
18
use Symfony\Component\Serializer\Annotation\Groups;
19
use Symfony\Component\Validator\Constraints as Assert;
20
21
/**
22
 * CTool.
23
 *
24
 * @ORM\HasLifecycleCallbacks
25
 * @ORM\Table(
26
 *     name="c_tool",
27
 *     indexes={
28
 *         @ORM\Index(name="course", columns={"c_id"}),
29
 *         @ORM\Index(name="session_id", columns={"session_id"})
30
 *     }
31
 * )
32
 * @ORM\Entity
33
 */
34
class CTool extends AbstractResource implements ResourceInterface
35
{
36
    use ShowCourseResourcesInSessionTrait;
37
38
    /**
39
     * @Groups({"ctool:read"})
40
     *
41
     * @ORM\Column(name="iid", type="integer")
42
     * @ORM\Id
43
     * @ORM\GeneratedValue
44
     */
45
    protected int $iid;
46
47
    /**
48
     * @Assert\NotBlank
49
     *
50
     * @Groups({"ctool:read"})
51
     *
52
     * @ORM\Column(name="name", type="text", nullable=false)
53
     */
54
    protected string $name;
55
56
    /**
57
     * @Groups({"ctool:read"})
58
     *
59
     * @ORM\Column(name="visibility", type="boolean", nullable=true)
60
     */
61
    protected ?bool $visibility = null;
62
63
    /**
64
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools")
65
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
66
     */
67
    protected Course $course;
68
69
    /**
70
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session")
71
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
72
     */
73
    protected ?Session $session = null;
74
75
    /**
76
     * @Groups({"ctool:read"})
77
     *
78
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool")
79
     * @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false)
80
     */
81
    protected Tool $tool;
82
83
    /**
84
     * @Gedmo\SortablePosition
85
     * @ORM\Column(name="position", type="integer")
86
     */
87
    protected int $position;
88
89
    /**
90
     * @Groups({"ctool:read"})
91
     */
92
    protected string $nameToTranslate;
93
94
    public function __construct()
95
    {
96
        $this->position = 0;
97
    }
98
99
    public function __toString(): string
100
    {
101
        return $this->getName();
102
    }
103
104
    public function getNameToTranslate(): string
105
    {
106
        return ucfirst(str_replace('_', ' ', $this->name));
107
    }
108
109
    public function getName(): string
110
    {
111
        return $this->name;
112
    }
113
114
    public function setName(string $name): self
115
    {
116
        $this->name = $name;
117
118
        return $this;
119
    }
120
121
    /**
122
     * @return int
123
     */
124
    public function getIid()
125
    {
126
        return $this->iid;
127
    }
128
129
    public function setCourse(Course $course): self
130
    {
131
        $this->course = $course;
132
133
        return $this;
134
    }
135
136
    public function getCourse(): Course
137
    {
138
        return $this->course;
139
    }
140
141
    public function getSession(): ?Session
142
    {
143
        return $this->session;
144
    }
145
146
    public function setSession(Session $session = null): self
147
    {
148
        $this->session = $session;
149
150
        return $this;
151
    }
152
153
    public function setVisibility(bool $visibility): self
154
    {
155
        $this->visibility = $visibility;
156
157
        return $this;
158
    }
159
160
    /**
161
     * Get visibility.
162
     *
163
     * @return bool
164
     */
165
    public function getVisibility()
166
    {
167
        return $this->visibility;
168
    }
169
170
    public function getTool(): Tool
171
    {
172
        return $this->tool;
173
    }
174
175
    public function setTool(Tool $tool): self
176
    {
177
        $this->tool = $tool;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @ORM\PostPersist()
184
     */
185
    public function postPersist(LifecycleEventArgs $args): void
186
    {
187
        // Update id with iid value
188
        /*$em = $args->getEntityManager();
189
        $em->persist($this);
190
        $em->flush();*/
191
    }
192
193
    public function getPosition(): int
194
    {
195
        return $this->position;
196
    }
197
198
    public function setPosition(int $position): self
199
    {
200
        $this->position = $position;
201
202
        return $this;
203
    }
204
205
    public function getResourceIdentifier(): int
206
    {
207
        return $this->iid;
208
    }
209
210
    public function getResourceName(): string
211
    {
212
        return $this->getName();
213
    }
214
215
    public function setResourceName(string $name): self
216
    {
217
        return $this->setName($name);
218
    }
219
}
220