Completed
Push — master ( db9c88...be5baf )
by Julito
14:58
created

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