Passed
Push — master ( 65060b...2b54a2 )
by Julito
10:15
created

ImsLtiTool::getPrivacy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\PluginBundle\Entity\ImsLti;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\CoreBundle\Entity\GradebookEvaluation;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\ORM\Mapping as ORM;
10
11
/**
12
 * Class ImsLtiTool
13
 *
14
 * @ORM\Table(name="plugin_ims_lti_tool")
15
 * @ORM\Entity()
16
 */
17
class ImsLtiTool
18
{
19
    /**
20
     * @var integer
21
     *
22
     * @ORM\Column(name="id", type="integer")
23
     * @ORM\Id
24
     * @ORM\GeneratedValue
25
     */
26
    protected $id;
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(name="name", type="string")
31
     */
32
    private $name = '';
33
    /**
34
     * @var string|null
35
     *
36
     * @ORM\Column(name="description", type="text", nullable=true)
37
     */
38
    private $description = null;
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(name="launch_url", type="string")
43
     */
44
    private $launchUrl = '';
45
    /**
46
     * @var string
47
     *
48
     * @ORM\Column(name="consumer_key", type="string")
49
     */
50
    private $consumerKey = '';
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(name="shared_secret", type="string")
55
     */
56
    private $sharedSecret = '';
57
    /**
58
     * @var string|null
59
     *
60
     * @ORM\Column(name="custom_params", type="text", nullable=true)
61
     */
62
    private $customParams = null;
63
    /**
64
     * @var bool
65
     *
66
     * @ORM\Column(name="active_deep_linking", type="boolean", nullable=false, options={"default": false})
67
     */
68
    private $activeDeepLinking = false;
69
70
    /**
71
     * @var null|string
72
     *
73
     * @ORM\Column(name="privacy", type="text", nullable=true, options={"default": null})
74
     */
75
    private $privacy = null;
76
77
    /**
78
     * @var Course|null
79
     *
80
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
81
     * @ORM\JoinColumn(name="c_id", referencedColumnName="id")
82
     */
83
    private $course = null;
84
85
    /**
86
     * @var GradebookEvaluation|null
87
     *
88
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\GradebookEvaluation")
89
     * @ORM\JoinColumn(name="gradebook_eval_id", referencedColumnName="id", onDelete="SET NULL")
90
     */
91
    private $gradebookEval = null;
92
93
    /**
94
     * @var ImsLtiTool|null
95
     *
96
     * @ORM\ManyToOne(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", inversedBy="children")
97
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
98
     */
99
    private $parent;
100
101
    /**
102
     * @var ArrayCollection
103
     *
104
     * @ORM\OneToMany(targetEntity="Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool", mappedBy="parent")
105
     */
106
    private $children;
107
108
    /**
109
     * ImsLtiTool constructor.
110
     */
111
    public function __construct()
112
    {
113
        $this->description = null;
114
        $this->customParams = null;
115
        $this->activeDeepLinking = false;
116
        $this->course = null;
117
        $this->gradebookEval =null;
118
        $this->privacy = null;
119
        $this->children = new ArrayCollection();
120
    }
121
122
    /**
123
     * @return int
124
     */
125
    public function getId()
126
    {
127
        return $this->id;
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function getName()
134
    {
135
        return $this->name;
136
    }
137
138
    /**
139
     * @param string $name
140
     * @return ImsLtiTool
141
     */
142
    public function setName($name)
143
    {
144
        $this->name = $name;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @return null|string
151
     */
152
    public function getDescription()
153
    {
154
        return $this->description;
155
    }
156
157
    /**
158
     * @param null|string $description
159
     * @return ImsLtiTool
160
     */
161
    public function setDescription($description)
162
    {
163
        $this->description = $description;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @return string
170
     */
171
    public function getLaunchUrl()
172
    {
173
        return $this->launchUrl;
174
    }
175
176
    /**
177
     * @param string $launchUrl
178
     * @return ImsLtiTool
179
     */
180
    public function setLaunchUrl($launchUrl)
181
    {
182
        $this->launchUrl = $launchUrl;
183
184
        return $this;
185
    }
186
187
    /**
188
     * @return string
189
     */
190
    public function getConsumerKey()
191
    {
192
        return $this->consumerKey;
193
    }
194
195
    /**
196
     * @param string $consumerKey
197
     * @return ImsLtiTool
198
     */
199
    public function setConsumerKey($consumerKey)
200
    {
201
        $this->consumerKey = $consumerKey;
202
203
        return $this;
204
    }
205
206
    /**
207
     * @return string
208
     */
209
    public function getSharedSecret()
210
    {
211
        return $this->sharedSecret;
212
    }
213
214
    /**
215
     * @param string $sharedSecret
216
     * @return ImsLtiTool
217
     */
218
    public function setSharedSecret($sharedSecret)
219
    {
220
        $this->sharedSecret = $sharedSecret;
221
222
        return $this;
223
    }
224
225
    /**
226
     * @return null|string
227
     */
228
    public function getCustomParams()
229
    {
230
        return $this->customParams;
231
    }
232
233
    /**
234
     * @param null|string $customParams
235
     * @return ImsLtiTool
236
     */
237
    public function setCustomParams($customParams)
238
    {
239
        $this->customParams = $customParams;
240
241
        return $this;
242
    }
243
244
    /**
245
     * @return bool
246
     */
247
    public function isGlobal()
248
    {
249
        return $this->course === null;
250
    }
251
252
    /**
253
     * @return array
254
     */
255
    public function parseCustomParams()
256
    {
257
        $params = [];
258
        $strings = explode("\n", $this->customParams);
259
260
        foreach ($strings as $string) {
261
            $pairs = explode('=', $string);
262
263
            $params['custom_'.$pairs[0]] = $pairs[1];
264
        }
265
266
        return $params;
267
    }
268
269
    /**
270
     * Set activeDeepLinking.
271
     *
272
     * @param bool $activeDeepLinking
273
     *
274
     * @return ImsLtiTool
275
     */
276
    public function setActiveDeepLinking($activeDeepLinking)
277
    {
278
        $this->activeDeepLinking = $activeDeepLinking;
279
280
        return $this;
281
    }
282
283
    /**
284
     * Get activeDeepLinking.
285
     *
286
     * @return bool
287
     */
288
    public function isActiveDeepLinking()
289
    {
290
        return $this->activeDeepLinking;
291
    }
292
293
    /**
294
     * Get course.
295
     *
296
     * @return Course|null
297
     */
298
    public function getCourse()
299
    {
300
        return $this->course;
301
    }
302
303
    /**
304
     * Set course.
305
     *
306
     * @param Course|null $course
307
     *
308
     * @return ImsLtiTool
309
     */
310
    public function setCourse(Course $course = null)
311
    {
312
        $this->course = $course;
313
314
        return $this;
315
    }
316
317
    /**
318
     * Get gradebookEval.
319
     *
320
     * @return GradebookEvaluation|null
321
     */
322
    public function getGradebookEval()
323
    {
324
        return $this->gradebookEval;
325
    }
326
327
    /**
328
     * Set gradebookEval.
329
     *
330
     * @param GradebookEvaluation|null $gradebookEval
331
     *
332
     * @return ImsLtiTool
333
     */
334
    public function setGradebookEval($gradebookEval)
335
    {
336
        $this->gradebookEval = $gradebookEval;
337
338
        return $this;
339
    }
340
341
    /**
342
     * Get privacy.
343
     *
344
     * @return null|string
345
     */
346
    public function getPrivacy()
347
    {
348
        return $this->privacy;
349
    }
350
351
    /**
352
     * Set privacy.
353
     *
354
     * @param bool $shareName
355
     * @param bool $shareEmail
356
     * @param bool $sharePicture
357
     *
358
     * @return ImsLtiTool
359
     */
360
    public function setPrivacy($shareName = false, $shareEmail = false, $sharePicture = false)
361
    {
362
        $this->privacy = serialize(
363
            [
364
                'share_name' => $shareName,
365
                'share_email' => $shareEmail,
366
                'share_picture' => $sharePicture,
367
            ]
368
        );
369
370
        return $this;
371
    }
372
373
    /**
374
     * @return bool
375
     */
376
    public function isSharingName()
377
    {
378
        $unserialize = $this->unserializePrivacy();
379
380
        return (bool) $unserialize['share_name'];
381
    }
382
383
    /**
384
     * @return bool
385
     */
386
    public function isSharingEmail()
387
    {
388
        $unserialize = $this->unserializePrivacy();
389
390
        return (bool) $unserialize['share_email'];
391
    }
392
393
    /**
394
     * @return bool
395
     */
396
    public function isSharingPicture()
397
    {
398
        $unserialize = $this->unserializePrivacy();
399
400
        return (bool) $unserialize['share_picture'];
401
    }
402
403
    /**
404
     * @return mixed
405
     */
406
    public function unserializePrivacy()
407
    {
408
        return unserialize($this->privacy);
409
    }
410
411
    /**
412
     * @return ImsLtiTool|null
413
     */
414
    public function getParent()
415
    {
416
        return $this->parent;
417
    }
418
419
    /**
420
     * @param ImsLtiTool $parent
421
     *
422
     * @return ImsLtiTool
423
     */
424
    public function setParent(ImsLtiTool $parent)
425
    {
426
        $this->parent = $parent;
427
428
        $this->sharedSecret = $parent->getSharedSecret();
429
        $this->consumerKey = $parent->getConsumerKey();
430
        $this->privacy = $parent->getPrivacy();
431
432
        return $this;
433
    }
434
}
435