Completed
Push — master ( aa1e6e...0c8670 )
by Julito
13:30
created

CTool   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 270
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 41
c 1
b 1
f 0
dl 0
loc 270
rs 10
wmc 22

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A getVisibility() 0 3 1
A getCustomIcon() 0 3 1
A setCustomIcon() 0 5 1
A setId() 0 5 1
A getCategory() 0 3 1
A setCategory() 0 5 1
A loadValidatorMetadata() 0 2 1
A setSession() 0 5 1
A setVisibility() 0 5 1
A __toString() 0 3 1
A __construct() 0 4 1
A setTool() 0 5 1
A getIid() 0 3 1
A getSession() 0 3 1
A setCourse() 0 5 1
A getResourceIdentifier() 0 3 1
A getResourceName() 0 3 1
A postPersist() 0 7 1
A getTool() 0 3 1
A setIid() 0 5 1
A getCourse() 0 3 1
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CourseBundle\Entity;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
8
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
9
use Chamilo\CoreBundle\Entity\Session;
10
use Chamilo\CoreBundle\Entity\Tool;
11
use Doctrine\ORM\Event\LifecycleEventArgs;
12
use Doctrine\ORM\Mapping as ORM;
13
14
/**
15
 * CTool.
16
 *
17
 * @ORM\HasLifecycleCallbacks
18
 * @ORM\Table(
19
 *  name="c_tool",
20
 *  indexes={
21
 *      @ORM\Index(name="course", columns={"c_id"}),
22
 *      @ORM\Index(name="session_id", columns={"session_id"})
23
 *  }
24
 * )
25
 * @ORM\Entity
26
 */
27
class CTool extends AbstractResource implements ResourceInterface
28
{
29
    /**
30
     * @var int
31
     *
32
     * @ORM\Column(name="iid", type="integer")
33
     * @ORM\Id
34
     * @ORM\GeneratedValue
35
     */
36
    protected $iid;
37
38
    /**
39
     * @var int
40
     *
41
     * @ORM\Column(name="id", type="integer", nullable=true)
42
     */
43
    protected $id;
44
45
    /**
46
     * @var bool
47
     *
48
     * @ORM\Column(name="visibility", type="boolean", nullable=true)
49
     */
50
    protected $visibility;
51
52
    /**
53
     * @var string
54
     *
55
     * @ORM\Column(name="category", type="string", length=20, nullable=false, options={"default" = "authoring"})
56
     */
57
    protected $category;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(name="custom_icon", type="string", length=255, nullable=true)
63
     */
64
    protected $customIcon;
65
66
    /**
67
     * @var Course
68
     *
69
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools")
70
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
71
     */
72
    protected $course;
73
74
    /**
75
     * @var Session
76
     *
77
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session")
78
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
79
     */
80
    protected $session;
81
82
    /**
83
     * @var Tool
84
     *
85
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool")
86
     * @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false)
87
     */
88
    protected $tool;
89
90
    /**
91
     * Constructor.
92
     */
93
    public function __construct()
94
    {
95
        // Default values
96
        $this->id = 0;
97
    }
98
99
    /**
100
     * @return int
101
     */
102
    public function getIid()
103
    {
104
        return $this->iid;
105
    }
106
107
    /**
108
     * @param int $iid
109
     *
110
     * @return CTool
111
     */
112
    public function setIid($iid)
113
    {
114
        $this->iid = $iid;
115
116
        return $this;
117
    }
118
119
    /**
120
     * @return $this
121
     */
122
    public function setCourse(Course $course)
123
    {
124
        $this->course = $course;
125
126
        return $this;
127
    }
128
129
    public function getCourse(): Course
130
    {
131
        return $this->course;
132
    }
133
134
    /**
135
     * @return Session
136
     */
137
    public function getSession(): ?Session
138
    {
139
        return $this->session;
140
    }
141
142
    /**
143
     * @param Session $session
144
     */
145
    public function setSession(Session $session = null): CTool
146
    {
147
        $this->session = $session;
148
149
        return $this;
150
    }
151
152
    public static function loadValidatorMetadata(ClassMetadata $metadata)
0 ignored issues
show
Unused Code introduced by
The parameter $metadata is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

152
    public static function loadValidatorMetadata(/** @scrutinizer ignore-unused */ ClassMetadata $metadata)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
153
    {
154
        /*$metadata->addPropertyConstraint(
155
            'customIcon',
156
            new Assert\File(['mimeTypes' => ['image/png']])
157
        );
158
        $metadata->addPropertyConstraint(
159
            'customIcon',
160
            new Assert\Image(['maxWidth' => 64, 'minHeight' => 64])
161
        );
162
        $metadata->addPropertyConstraint('cId', new Assert\NotBlank());*/
163
    }
164
165
    /**
166
     * Set visibility.
167
     *
168
     * @param bool $visibility
169
     *
170
     * @return CTool
171
     */
172
    public function setVisibility($visibility)
173
    {
174
        $this->visibility = $visibility;
175
176
        return $this;
177
    }
178
179
    /**
180
     * Get visibility.
181
     *
182
     * @return bool
183
     */
184
    public function getVisibility()
185
    {
186
        return $this->visibility;
187
    }
188
189
    /**
190
     * Set category.
191
     *
192
     * @param string $category
193
     *
194
     * @return CTool
195
     */
196
    public function setCategory($category)
197
    {
198
        $this->category = $category;
199
200
        return $this;
201
    }
202
203
    /**
204
     * Get category.
205
     *
206
     * @return string
207
     */
208
    public function getCategory()
209
    {
210
        return $this->category;
211
    }
212
213
    /**
214
     * Set id.
215
     *
216
     * @param int $id
217
     *
218
     * @return CTool
219
     */
220
    public function setId($id)
221
    {
222
        $this->id = $id;
223
224
        return $this;
225
    }
226
227
    /**
228
     * Get id.
229
     *
230
     * @return int
231
     */
232
    public function getId()
233
    {
234
        return $this->id;
235
    }
236
237
    /**
238
     * @return string
239
     */
240
    public function getCustomIcon()
241
    {
242
        return $this->customIcon;
243
    }
244
245
    /**
246
     * @param string $customIcon
247
     *
248
     * @return CTool
249
     */
250
    public function setCustomIcon($customIcon)
251
    {
252
        $this->customIcon = $customIcon;
253
254
        return $this;
255
    }
256
257
    public function getTool(): Tool
258
    {
259
        return $this->tool;
260
    }
261
262
    public function setTool(Tool $tool): CTool
263
    {
264
        $this->tool = $tool;
265
266
        return $this;
267
    }
268
269
    /**
270
     * @ORM\PostPersist()
271
     */
272
    public function postPersist(LifecycleEventArgs $args)
273
    {
274
        // Update id with iid value
275
        $em = $args->getEntityManager();
276
        $this->setId($this->iid);
277
        $em->persist($this);
278
        $em->flush($this);
279
    }
280
281
    /**
282
     * Resource identifier.
283
     */
284
    public function getResourceIdentifier(): int
285
    {
286
        return $this->iid;
287
    }
288
289
    public function getResourceName(): string
290
    {
291
        return (string) $this->getTool()->getName();
292
    }
293
294
    public function __toString(): string
295
    {
296
        return (string) $this->getTool()->getName();
297
    }
298
}
299