Total Complexity | 125 |
Total Lines | 1337 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like Course often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Course, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
39 | #[ApiResource( |
||
40 | iri: 'https://schema.org/Course', |
||
41 | attributes: [ |
||
42 | 'security' => "is_granted('ROLE_USER')", |
||
43 | ], |
||
44 | itemOperations: [ |
||
45 | 'get' => [ |
||
46 | 'security' => "is_granted('VIEW', object)", |
||
47 | ], |
||
48 | ], |
||
49 | normalizationContext: [ |
||
50 | 'groups' => ['course:read'], |
||
51 | ], |
||
52 | denormalizationContext: [ |
||
53 | 'groups' => ['course:write'], |
||
54 | ], |
||
55 | )] |
||
56 | |||
57 | #[ApiFilter(SearchFilter::class, properties: [ |
||
58 | 'title' => 'partial', |
||
59 | 'code' => 'partial', |
||
60 | ])] |
||
61 | #[ApiFilter(PropertyFilter::class)] |
||
62 | #[ApiFilter(OrderFilter::class, properties: ['id', 'title'])] |
||
63 | |||
64 | class Course extends AbstractResource implements ResourceInterface, ResourceWithAccessUrlInterface, ResourceIllustrationInterface |
||
65 | { |
||
66 | public const CLOSED = 0; |
||
67 | public const REGISTERED = 1; // Only registered users in the course. |
||
68 | public const OPEN_PLATFORM = 2; // All users registered in the platform (default). |
||
69 | public const OPEN_WORLD = 3; |
||
70 | public const HIDDEN = 4; |
||
71 | |||
72 | /** |
||
73 | * @ORM\Column(name="id", type="integer") |
||
74 | * @ORM\Id |
||
75 | * @ORM\GeneratedValue(strategy="AUTO") |
||
76 | */ |
||
77 | #[Groups([ |
||
78 | 'course:read', |
||
79 | 'course_rel_user:read', |
||
80 | 'session:read', |
||
81 | 'session_rel_course_rel_user:read', |
||
82 | 'session_rel_user:read', |
||
83 | 'session_rel_course:read', |
||
84 | ])] |
||
85 | protected ?int $id = null; |
||
86 | |||
87 | /** |
||
88 | * The course title. |
||
89 | * |
||
90 | * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false) |
||
91 | */ |
||
92 | #[Groups([ |
||
93 | 'course:read', |
||
94 | 'course:write', |
||
95 | 'course_rel_user:read', |
||
96 | 'session:read', |
||
97 | 'session_rel_course_rel_user:read', |
||
98 | 'session_rel_user:read', |
||
99 | 'session_rel_course:read', |
||
100 | ])] |
||
101 | #[Assert\NotBlank(message: 'A Course requires a title')] |
||
102 | protected ?string $title = null; |
||
103 | |||
104 | /** |
||
105 | * The course code. |
||
106 | * |
||
107 | * @Assert\Length( |
||
108 | * max = 40, |
||
109 | * maxMessage = "Code cannot be longer than {{ limit }} characters" |
||
110 | * ) |
||
111 | * @ApiProperty(iri="http://schema.org/courseCode") |
||
112 | * |
||
113 | * @Gedmo\Slug( |
||
114 | * fields={"title"}, |
||
115 | * updatable=false, |
||
116 | * unique=true, |
||
117 | * separator="", |
||
118 | * style="upper" |
||
119 | * ) |
||
120 | * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true) |
||
121 | */ |
||
122 | #[Groups(['course:read', 'user:write', 'course_rel_user:read'])] |
||
123 | #[Assert\NotBlank] |
||
124 | protected string $code; |
||
125 | |||
126 | /** |
||
127 | * @Assert\Length( |
||
128 | * max = 40, |
||
129 | * maxMessage = "Code cannot be longer than {{ limit }} characters" |
||
130 | * ) |
||
131 | * @ORM\Column(name="visual_code", type="string", length=40, nullable=true, unique=false) |
||
132 | */ |
||
133 | protected ?string $visualCode = null; |
||
134 | |||
135 | /** |
||
136 | * @var Collection|CourseRelUser[] |
||
137 | * |
||
138 | * "orphanRemoval" is needed to delete the CourseRelUser relation |
||
139 | * in the CourseAdmin class. The setUsers, getUsers, removeUsers and |
||
140 | * addUsers methods need to be added. |
||
141 | * |
||
142 | * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="course", cascade={"persist"}, orphanRemoval=true) |
||
143 | */ |
||
144 | #[Groups(['course:read', 'user:read'])] |
||
145 | #[ApiSubresource] |
||
146 | protected Collection $users; |
||
147 | |||
148 | /** |
||
149 | * @var AccessUrlRelCourse[]|Collection |
||
150 | * |
||
151 | * @ORM\OneToMany( |
||
152 | * targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourse", |
||
153 | * mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true |
||
154 | * ) |
||
155 | */ |
||
156 | protected Collection $urls; |
||
157 | |||
158 | /** |
||
159 | * @var Collection|SessionRelCourse[] |
||
160 | * |
||
161 | * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist", "remove"}) |
||
162 | */ |
||
163 | protected Collection $sessions; |
||
164 | |||
165 | /** |
||
166 | * @var Collection|SessionRelCourseRelUser[] |
||
167 | * |
||
168 | * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist", "remove"}) |
||
169 | */ |
||
170 | protected Collection $sessionRelCourseRelUsers; |
||
171 | |||
172 | /** |
||
173 | * @var Collection|CTool[] |
||
174 | * |
||
175 | * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist", "remove"}) |
||
176 | */ |
||
177 | #[Groups(['course:read'])] |
||
178 | protected Collection $tools; |
||
179 | |||
180 | protected Session $currentSession; |
||
181 | |||
182 | protected AccessUrl $currentUrl; |
||
183 | |||
184 | /** |
||
185 | * @var Collection|SkillRelCourse[] |
||
186 | * |
||
187 | * @ORM\OneToMany(targetEntity="SkillRelCourse", mappedBy="course", cascade={"persist", "remove"}) |
||
188 | */ |
||
189 | protected Collection $skills; |
||
190 | |||
191 | /** |
||
192 | * @var Collection|SkillRelUser[] |
||
193 | * |
||
194 | * @ORM\OneToMany(targetEntity="SkillRelUser", mappedBy="course", cascade={"persist", "remove"}) |
||
195 | */ |
||
196 | protected Collection $issuedSkills; |
||
197 | |||
198 | /** |
||
199 | * @var Collection|GradebookCategory[] |
||
200 | * |
||
201 | * @ORM\OneToMany(targetEntity="GradebookCategory", mappedBy="course", cascade={"persist", "remove"}) |
||
202 | */ |
||
203 | protected Collection $gradebookCategories; |
||
204 | |||
205 | /** |
||
206 | * @var Collection|GradebookEvaluation[] |
||
207 | * |
||
208 | * @ORM\OneToMany(targetEntity="GradebookEvaluation", mappedBy="course", cascade={"persist", "remove"}) |
||
209 | */ |
||
210 | protected Collection $gradebookEvaluations; |
||
211 | |||
212 | /** |
||
213 | * @var Collection|GradebookLink[] |
||
214 | * |
||
215 | * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="course", cascade={"persist", "remove"}) |
||
216 | */ |
||
217 | protected Collection $gradebookLinks; |
||
218 | |||
219 | /** |
||
220 | * @var Collection|TrackEHotspot[] |
||
221 | * |
||
222 | * @ORM\OneToMany(targetEntity="TrackEHotspot", mappedBy="course", cascade={"persist", "remove"}) |
||
223 | */ |
||
224 | protected Collection $trackEHotspots; |
||
225 | |||
226 | /** |
||
227 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SearchEngineRef", mappedBy="course", cascade={"persist", "remove"}) |
||
228 | * |
||
229 | * @var SearchEngineRef[]|Collection |
||
230 | */ |
||
231 | protected Collection $searchEngineRefs; |
||
232 | |||
233 | /** |
||
234 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Templates", mappedBy="course", cascade={"persist", "remove"}) |
||
235 | * |
||
236 | * @var Templates[]|Collection |
||
237 | */ |
||
238 | protected Collection $templates; |
||
239 | |||
240 | /** |
||
241 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course") |
||
242 | */ |
||
243 | //protected $specificFieldValues; |
||
244 | |||
245 | /** |
||
246 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course") |
||
247 | */ |
||
248 | //protected $sharedSurveys; |
||
249 | |||
250 | /** |
||
251 | * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false) |
||
252 | */ |
||
253 | protected ?string $directory = null; |
||
254 | |||
255 | /** |
||
256 | * @ORM\Column(name="course_language", type="string", length=20, nullable=false, unique=false) |
||
257 | */ |
||
258 | #[Groups(['course:read'])] |
||
259 | protected string $courseLanguage; |
||
260 | |||
261 | /** |
||
262 | * @ORM\Column(name="description", type="text", nullable=true, unique=false) |
||
263 | */ |
||
264 | #[Groups(['course:read', 'course_rel_user:read'])] |
||
265 | protected ?string $description; |
||
266 | |||
267 | /** |
||
268 | * @ORM\Column(name="introduction", type="text", nullable=true) |
||
269 | */ |
||
270 | #[Groups(['course:read', 'course_rel_user:read'])] |
||
271 | protected ?string $introduction; |
||
272 | |||
273 | /** |
||
274 | * @var CourseCategory[]|Collection |
||
275 | * |
||
276 | * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses") |
||
277 | * @ORM\JoinTable( |
||
278 | * name="course_rel_category", |
||
279 | * joinColumns={ |
||
280 | * @ORM\JoinColumn(name="course_id", referencedColumnName="id") |
||
281 | * }, |
||
282 | * inverseJoinColumns={ |
||
283 | * @ORM\JoinColumn(name="course_category_id", referencedColumnName="id")} |
||
284 | * ) |
||
285 | */ |
||
286 | #[ApiSubresource] |
||
287 | #[Groups(['course:read', 'course:write', 'course_rel_user:read'])] |
||
288 | protected Collection $categories; |
||
289 | |||
290 | /** |
||
291 | * @var int Course visibility |
||
292 | * |
||
293 | * @ORM\Column(name="visibility", type="integer", nullable=false, unique=false) |
||
294 | */ |
||
295 | #[Assert\NotBlank] |
||
296 | #[Groups(['course:read', 'course:write'])] |
||
297 | protected int $visibility; |
||
298 | |||
299 | /** |
||
300 | * @ORM\Column(name="show_score", type="integer", nullable=true, unique=false) |
||
301 | */ |
||
302 | protected ?int $showScore = null; |
||
303 | |||
304 | /** |
||
305 | * @ORM\Column(name="tutor_name", type="string", length=200, nullable=true, unique=false) |
||
306 | */ |
||
307 | protected ?string $tutorName; |
||
308 | |||
309 | /** |
||
310 | * @ORM\Column(name="department_name", type="string", length=30, nullable=true, unique=false) |
||
311 | */ |
||
312 | #[Groups(['course:read'])] |
||
313 | protected ?string $departmentName = null; |
||
314 | |||
315 | /** |
||
316 | * @ORM\Column(name="department_url", type="string", length=180, nullable=true, unique=false) |
||
317 | */ |
||
318 | #[Assert\Url] |
||
319 | #[Groups(['course:read', 'course:write'])] |
||
320 | protected ?string $departmentUrl = null; |
||
321 | |||
322 | /** |
||
323 | * @ORM\Column(name="video_url", type="string", length=255) |
||
324 | */ |
||
325 | #[Assert\Url] |
||
326 | #[Groups(['course:read', 'course:write'])] |
||
327 | protected string $videoUrl; |
||
328 | |||
329 | /** |
||
330 | * @ORM\Column(name="sticky", type="boolean") |
||
331 | */ |
||
332 | #[Groups(['course:read', 'course:write'])] |
||
333 | protected bool $sticky; |
||
334 | |||
335 | /** |
||
336 | * @ORM\Column(name="disk_quota", type="bigint", nullable=true, unique=false) |
||
337 | */ |
||
338 | protected ?int $diskQuota = null; |
||
339 | |||
340 | /** |
||
341 | * @ORM\Column(name="last_visit", type="datetime", nullable=true, unique=false) |
||
342 | */ |
||
343 | protected ?DateTime $lastVisit; |
||
344 | |||
345 | /** |
||
346 | * @ORM\Column(name="last_edit", type="datetime", nullable=true, unique=false) |
||
347 | */ |
||
348 | protected ?DateTime $lastEdit; |
||
349 | |||
350 | /** |
||
351 | * @ORM\Column(name="creation_date", type="datetime", nullable=false, unique=false) |
||
352 | */ |
||
353 | protected DateTime $creationDate; |
||
354 | |||
355 | /** |
||
356 | * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false) |
||
357 | */ |
||
358 | #[Groups(['course:read'])] |
||
359 | protected ?DateTime $expirationDate = null; |
||
360 | |||
361 | /** |
||
362 | * @ORM\Column(name="subscribe", type="boolean", nullable=false, unique=false) |
||
363 | */ |
||
364 | protected bool $subscribe; |
||
365 | |||
366 | /** |
||
367 | * @ORM\Column(name="unsubscribe", type="boolean", nullable=false, unique=false) |
||
368 | */ |
||
369 | protected bool $unsubscribe; |
||
370 | |||
371 | /** |
||
372 | * @ORM\Column(name="registration_code", type="string", length=255, nullable=true, unique=false) |
||
373 | */ |
||
374 | protected ?string $registrationCode; |
||
375 | |||
376 | /** |
||
377 | * @ORM\Column(name="legal", type="text", nullable=true, unique=false) |
||
378 | */ |
||
379 | protected ?string $legal; |
||
380 | |||
381 | /** |
||
382 | * @ORM\Column(name="activate_legal", type="integer", nullable=true, unique=false) |
||
383 | */ |
||
384 | protected ?int $activateLegal; |
||
385 | |||
386 | /** |
||
387 | * @ORM\Column(name="add_teachers_to_sessions_courses", type="boolean", nullable=true) |
||
388 | */ |
||
389 | protected ?bool $addTeachersToSessionsCourses; |
||
390 | |||
391 | /** |
||
392 | * @ORM\Column(name="course_type_id", type="integer", nullable=true, unique=false) |
||
393 | */ |
||
394 | protected ?int $courseTypeId; |
||
395 | |||
396 | /** |
||
397 | * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course"). |
||
398 | */ |
||
399 | //protected $curriculumCategories; |
||
400 | |||
401 | /** |
||
402 | * @ORM\ManyToOne(targetEntity="Room") |
||
403 | * @ORM\JoinColumn(name="room_id", referencedColumnName="id") |
||
404 | */ |
||
405 | protected ?Room $room; |
||
406 | |||
407 | public function __construct() |
||
408 | { |
||
409 | $this->visibility = self::OPEN_PLATFORM; |
||
410 | $this->sessions = new ArrayCollection(); |
||
411 | $this->sessionRelCourseRelUsers = new ArrayCollection(); |
||
412 | $this->skills = new ArrayCollection(); |
||
413 | $this->issuedSkills = new ArrayCollection(); |
||
414 | $this->creationDate = new DateTime(); |
||
415 | $this->lastVisit = new DateTime(); |
||
416 | $this->lastEdit = new DateTime(); |
||
417 | $this->description = ''; |
||
418 | $this->introduction = ''; |
||
419 | $this->tutorName = ''; |
||
420 | $this->legal = ''; |
||
421 | $this->videoUrl = ''; |
||
422 | $this->registrationCode = null; |
||
423 | $this->users = new ArrayCollection(); |
||
424 | $this->urls = new ArrayCollection(); |
||
425 | $this->tools = new ArrayCollection(); |
||
426 | $this->categories = new ArrayCollection(); |
||
427 | $this->gradebookCategories = new ArrayCollection(); |
||
428 | $this->gradebookEvaluations = new ArrayCollection(); |
||
429 | $this->gradebookLinks = new ArrayCollection(); |
||
430 | $this->trackEHotspots = new ArrayCollection(); |
||
431 | |||
432 | $this->searchEngineRefs = new ArrayCollection(); |
||
433 | $this->templates = new ArrayCollection(); |
||
434 | $this->activateLegal = 0; |
||
435 | $this->addTeachersToSessionsCourses = false; |
||
436 | $this->courseTypeId = null; |
||
437 | $this->room = null; |
||
438 | $this->courseLanguage = 'en'; |
||
439 | $this->subscribe = true; |
||
440 | $this->unsubscribe = false; |
||
441 | $this->sticky = false; |
||
442 | //$this->specificFieldValues = new ArrayCollection(); |
||
443 | //$this->sharedSurveys = new ArrayCollection(); |
||
444 | } |
||
445 | |||
446 | public function __toString(): string |
||
447 | { |
||
448 | return $this->getTitle(); |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * @return SessionRelCourse[]|ArrayCollection|Collection |
||
453 | */ |
||
454 | public function getSessions() |
||
455 | { |
||
456 | return $this->sessions; |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @return CTool[]|ArrayCollection|Collection |
||
461 | */ |
||
462 | public function getTools() |
||
463 | { |
||
464 | return $this->tools; |
||
465 | } |
||
466 | |||
467 | public function setTools(array $tools): self |
||
468 | { |
||
469 | foreach ($tools as $tool) { |
||
470 | $this->addTool($tool); |
||
471 | } |
||
472 | |||
473 | return $this; |
||
474 | } |
||
475 | |||
476 | public function addTool(CTool $tool): self |
||
477 | { |
||
478 | $tool->setCourse($this); |
||
479 | $this->tools->add($tool); |
||
480 | |||
481 | return $this; |
||
482 | } |
||
483 | |||
484 | /** |
||
485 | * @return AccessUrlRelCourse[]|Collection |
||
486 | */ |
||
487 | public function getUrls() |
||
488 | { |
||
489 | return $this->urls; |
||
490 | } |
||
491 | |||
492 | public function setUrls(Collection $urls): self |
||
493 | { |
||
494 | $this->urls = new ArrayCollection(); |
||
495 | foreach ($urls as $url) { |
||
496 | $this->addAccessUrl($url); |
||
497 | } |
||
498 | |||
499 | return $this; |
||
500 | } |
||
501 | |||
502 | public function addUrlRelCourse(AccessUrlRelCourse $accessUrlRelCourse): self |
||
503 | { |
||
504 | $accessUrlRelCourse->setCourse($this); |
||
505 | $this->urls->add($accessUrlRelCourse); |
||
506 | |||
507 | return $this; |
||
508 | } |
||
509 | |||
510 | public function addAccessUrl(AccessUrl $url): self |
||
511 | { |
||
512 | $urlRelCourse = (new AccessUrlRelCourse()) |
||
513 | ->setCourse($this) |
||
514 | ->setUrl($url) |
||
515 | ; |
||
516 | $this->addUrlRelCourse($urlRelCourse); |
||
517 | |||
518 | return $this; |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * @return Collection|CourseRelUser[] |
||
523 | */ |
||
524 | public function getUsers() |
||
525 | { |
||
526 | return $this->users; |
||
527 | } |
||
528 | |||
529 | /** |
||
530 | * @return Collection|CourseRelUser[] |
||
531 | */ |
||
532 | public function getTeachers() |
||
533 | { |
||
534 | $criteria = Criteria::create(); |
||
535 | $criteria->where(Criteria::expr()->eq('status', CourseRelUser::TEACHER)); |
||
536 | |||
537 | return $this->users->matching($criteria); |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * @return Collection|CourseRelUser[] |
||
542 | */ |
||
543 | public function getStudents() |
||
544 | { |
||
545 | $criteria = Criteria::create(); |
||
546 | $criteria->where(Criteria::expr()->eq('status', CourseRelUser::STUDENT)); |
||
547 | |||
548 | return $this->users->matching($criteria); |
||
549 | } |
||
550 | |||
551 | public function setUsers(Collection $users): self |
||
552 | { |
||
553 | $this->users = new ArrayCollection(); |
||
554 | |||
555 | foreach ($users as $user) { |
||
556 | $this->addUsers($user); |
||
557 | } |
||
558 | |||
559 | return $this; |
||
560 | } |
||
561 | |||
562 | public function addUsers(CourseRelUser $courseRelUser): self |
||
563 | { |
||
564 | $courseRelUser->setCourse($this); |
||
565 | |||
566 | if (!$this->hasSubscription($courseRelUser)) { |
||
567 | $this->users->add($courseRelUser); |
||
568 | } |
||
569 | |||
570 | return $this; |
||
571 | } |
||
572 | |||
573 | public function hasUser(User $user): bool |
||
574 | { |
||
575 | $criteria = Criteria::create()->where( |
||
576 | Criteria::expr()->eq('user', $user) |
||
577 | ); |
||
578 | |||
579 | return $this->getUsers()->matching($criteria)->count() > 0; |
||
580 | } |
||
581 | |||
582 | public function hasStudent(User $user): bool |
||
583 | { |
||
584 | $criteria = Criteria::create()->where( |
||
585 | Criteria::expr()->eq('user', $user) |
||
586 | ); |
||
587 | |||
588 | return $this->getStudents()->matching($criteria)->count() > 0; |
||
589 | } |
||
590 | |||
591 | public function hasTeacher(User $user): bool |
||
592 | { |
||
593 | $criteria = Criteria::create()->where( |
||
594 | Criteria::expr()->eq('user', $user) |
||
595 | ); |
||
596 | |||
597 | return $this->getTeachers()->matching($criteria)->count() > 0; |
||
598 | } |
||
599 | |||
600 | public function hasGroup(CGroup $group): void |
||
601 | { |
||
602 | /*$criteria = Criteria::create()->where( |
||
603 | Criteria::expr()->eq('groups', $group) |
||
604 | );*/ |
||
605 | |||
606 | //return $this->getGroups()->contains($group); |
||
607 | } |
||
608 | |||
609 | /** |
||
610 | * Remove $user. |
||
611 | */ |
||
612 | public function removeUsers(CourseRelUser $user): void |
||
613 | { |
||
614 | foreach ($this->users as $key => $value) { |
||
615 | if ($value->getId() === $user->getId()) { |
||
616 | unset($this->users[$key]); |
||
617 | } |
||
618 | } |
||
619 | } |
||
620 | |||
621 | public function addTeacher(User $user): self |
||
622 | { |
||
623 | $this->addUser($user, 0, 'Trainer', CourseRelUser::TEACHER); |
||
624 | |||
625 | return $this; |
||
626 | } |
||
627 | |||
628 | public function addStudent(User $user): self |
||
629 | { |
||
630 | $this->addUser($user, 0, '', CourseRelUser::STUDENT); |
||
631 | |||
632 | return $this; |
||
633 | } |
||
634 | |||
635 | /** |
||
636 | * Get id. |
||
637 | * |
||
638 | * @return int |
||
639 | */ |
||
640 | public function getId() |
||
641 | { |
||
642 | return $this->id; |
||
643 | } |
||
644 | |||
645 | public function setCode(string $code): self |
||
646 | { |
||
647 | $this->code = $code; |
||
648 | $this->visualCode = $code; |
||
649 | |||
650 | return $this; |
||
651 | } |
||
652 | |||
653 | public function getCode(): string |
||
654 | { |
||
655 | return $this->code; |
||
656 | } |
||
657 | |||
658 | /** |
||
659 | * Get directory, needed in migrations. |
||
660 | * |
||
661 | * @return string |
||
662 | */ |
||
663 | public function getDirectory() |
||
664 | { |
||
665 | return $this->directory; |
||
666 | } |
||
667 | |||
668 | public function setCourseLanguage(string $courseLanguage): self |
||
673 | } |
||
674 | |||
675 | public function getCourseLanguage(): string |
||
678 | } |
||
679 | |||
680 | public function setTitle(string $title): self |
||
681 | { |
||
682 | $this->title = $title; |
||
683 | |||
684 | // Set the code based in the title if it doesnt exists. |
||
685 | if (empty($this->code)) { |
||
686 | $this->setCode($title); |
||
687 | } |
||
688 | |||
689 | return $this; |
||
690 | } |
||
691 | |||
692 | public function getTitle(): string |
||
693 | { |
||
694 | return $this->title; |
||
|
|||
695 | } |
||
696 | |||
697 | public function getName(): string |
||
698 | { |
||
699 | return $this->getTitle(); |
||
700 | } |
||
701 | |||
702 | public function getTitleAndCode(): string |
||
703 | { |
||
704 | return $this->getTitle().' ('.$this->getCode().')'; |
||
705 | } |
||
706 | |||
707 | public function setDescription(string $description): self |
||
708 | { |
||
709 | $this->description = $description; |
||
710 | |||
711 | return $this; |
||
712 | } |
||
713 | |||
714 | public function getDescription(): ?string |
||
715 | { |
||
716 | return $this->description; |
||
717 | } |
||
718 | |||
719 | public function setCategories(Collection $categories): self |
||
720 | { |
||
721 | $this->categories = $categories; |
||
722 | |||
723 | return $this; |
||
724 | } |
||
725 | |||
726 | /** |
||
727 | * @return CourseCategory[]|Collection |
||
728 | */ |
||
729 | public function getCategories() |
||
730 | { |
||
731 | return $this->categories; |
||
732 | } |
||
733 | |||
734 | public function addCategory(CourseCategory $category): self |
||
735 | { |
||
736 | $this->categories[] = $category; |
||
737 | |||
738 | return $this; |
||
739 | } |
||
740 | |||
741 | public function removeCategory(CourseCategory $category): void |
||
742 | { |
||
743 | $this->categories->removeElement($category); |
||
744 | } |
||
745 | |||
746 | public function setVisibility(int $visibility): self |
||
747 | { |
||
748 | $this->visibility = $visibility; |
||
749 | |||
750 | return $this; |
||
751 | } |
||
752 | |||
753 | public function getVisibility(): int |
||
754 | { |
||
755 | return $this->visibility; |
||
756 | } |
||
757 | |||
758 | public function setShowScore(int $showScore): self |
||
759 | { |
||
760 | $this->showScore = $showScore; |
||
761 | |||
762 | return $this; |
||
763 | } |
||
764 | |||
765 | /** |
||
766 | * Get showScore. |
||
767 | * |
||
768 | * @return int |
||
769 | */ |
||
770 | public function getShowScore() |
||
771 | { |
||
772 | return $this->showScore; |
||
773 | } |
||
774 | |||
775 | public function setTutorName(?string $tutorName): self |
||
776 | { |
||
777 | $this->tutorName = $tutorName; |
||
778 | |||
779 | return $this; |
||
780 | } |
||
781 | |||
782 | public function getTutorName(): ?string |
||
783 | { |
||
784 | return $this->tutorName; |
||
785 | } |
||
786 | |||
787 | public function setVisualCode(string $visualCode): self |
||
788 | { |
||
789 | $this->visualCode = $visualCode; |
||
790 | |||
791 | return $this; |
||
792 | } |
||
793 | |||
794 | /** |
||
795 | * Get visualCode. |
||
796 | * |
||
797 | * @return string |
||
798 | */ |
||
799 | public function getVisualCode() |
||
800 | { |
||
801 | return $this->visualCode; |
||
802 | } |
||
803 | |||
804 | public function setDepartmentName(string $departmentName): self |
||
805 | { |
||
806 | $this->departmentName = $departmentName; |
||
807 | |||
808 | return $this; |
||
809 | } |
||
810 | |||
811 | /** |
||
812 | * Get departmentName. |
||
813 | * |
||
814 | * @return string |
||
815 | */ |
||
816 | public function getDepartmentName() |
||
817 | { |
||
818 | return $this->departmentName; |
||
819 | } |
||
820 | |||
821 | public function setDepartmentUrl(string $departmentUrl): self |
||
822 | { |
||
823 | $this->departmentUrl = $departmentUrl; |
||
824 | |||
825 | return $this; |
||
826 | } |
||
827 | |||
828 | /** |
||
829 | * Get departmentUrl. |
||
830 | * |
||
831 | * @return string |
||
832 | */ |
||
833 | public function getDepartmentUrl() |
||
834 | { |
||
835 | return $this->departmentUrl; |
||
836 | } |
||
837 | |||
838 | public function setDiskQuota(int $diskQuota): self |
||
839 | { |
||
840 | $this->diskQuota = $diskQuota; |
||
841 | |||
842 | return $this; |
||
843 | } |
||
844 | |||
845 | /** |
||
846 | * Get diskQuota. |
||
847 | * |
||
848 | * @return int |
||
849 | */ |
||
850 | public function getDiskQuota() |
||
851 | { |
||
852 | return $this->diskQuota; |
||
853 | } |
||
854 | |||
855 | public function setLastVisit(DateTime $lastVisit): self |
||
856 | { |
||
857 | $this->lastVisit = $lastVisit; |
||
858 | |||
859 | return $this; |
||
860 | } |
||
861 | |||
862 | /** |
||
863 | * Get lastVisit. |
||
864 | * |
||
865 | * @return DateTime |
||
866 | */ |
||
867 | public function getLastVisit() |
||
868 | { |
||
869 | return $this->lastVisit; |
||
870 | } |
||
871 | |||
872 | public function setLastEdit(DateTime $lastEdit): self |
||
873 | { |
||
874 | $this->lastEdit = $lastEdit; |
||
875 | |||
876 | return $this; |
||
877 | } |
||
878 | |||
879 | /** |
||
880 | * Get lastEdit. |
||
881 | * |
||
882 | * @return DateTime |
||
883 | */ |
||
884 | public function getLastEdit() |
||
885 | { |
||
886 | return $this->lastEdit; |
||
887 | } |
||
888 | |||
889 | public function setCreationDate(DateTime $creationDate): self |
||
890 | { |
||
891 | $this->creationDate = $creationDate; |
||
892 | |||
893 | return $this; |
||
894 | } |
||
895 | |||
896 | /** |
||
897 | * Get creationDate. |
||
898 | * |
||
899 | * @return DateTime |
||
900 | */ |
||
901 | public function getCreationDate() |
||
902 | { |
||
903 | return $this->creationDate; |
||
904 | } |
||
905 | |||
906 | public function setExpirationDate(DateTime $expirationDate): self |
||
907 | { |
||
908 | $this->expirationDate = $expirationDate; |
||
909 | |||
910 | return $this; |
||
911 | } |
||
912 | |||
913 | /** |
||
914 | * Get expirationDate. |
||
915 | * |
||
916 | * @return DateTime |
||
917 | */ |
||
918 | public function getExpirationDate() |
||
919 | { |
||
920 | return $this->expirationDate; |
||
921 | } |
||
922 | |||
923 | public function setSubscribe(bool $subscribe): self |
||
924 | { |
||
925 | $this->subscribe = $subscribe; |
||
926 | |||
927 | return $this; |
||
928 | } |
||
929 | |||
930 | /** |
||
931 | * Get subscribe. |
||
932 | * |
||
933 | * @return bool |
||
934 | */ |
||
935 | public function getSubscribe() |
||
936 | { |
||
937 | return $this->subscribe; |
||
938 | } |
||
939 | |||
940 | public function setUnsubscribe(bool $unsubscribe): self |
||
941 | { |
||
942 | $this->unsubscribe = $unsubscribe; |
||
943 | |||
944 | return $this; |
||
945 | } |
||
946 | |||
947 | /** |
||
948 | * Get unsubscribe. |
||
949 | * |
||
950 | * @return bool |
||
951 | */ |
||
952 | public function getUnsubscribe() |
||
953 | { |
||
954 | return $this->unsubscribe; |
||
955 | } |
||
956 | |||
957 | public function setRegistrationCode(string $registrationCode): self |
||
958 | { |
||
959 | $this->registrationCode = $registrationCode; |
||
960 | |||
961 | return $this; |
||
962 | } |
||
963 | |||
964 | /** |
||
965 | * Get registrationCode. |
||
966 | * |
||
967 | * @return string |
||
968 | */ |
||
969 | public function getRegistrationCode() |
||
970 | { |
||
971 | return $this->registrationCode; |
||
972 | } |
||
973 | |||
974 | public function setLegal(string $legal): self |
||
975 | { |
||
976 | $this->legal = $legal; |
||
977 | |||
978 | return $this; |
||
979 | } |
||
980 | |||
981 | /** |
||
982 | * Get legal. |
||
983 | * |
||
984 | * @return string |
||
985 | */ |
||
986 | public function getLegal() |
||
987 | { |
||
988 | return $this->legal; |
||
989 | } |
||
990 | |||
991 | public function setActivateLegal(int $activateLegal): self |
||
992 | { |
||
993 | $this->activateLegal = $activateLegal; |
||
994 | |||
995 | return $this; |
||
996 | } |
||
997 | |||
998 | /** |
||
999 | * Get activateLegal. |
||
1000 | * |
||
1001 | * @return int |
||
1002 | */ |
||
1003 | public function getActivateLegal() |
||
1004 | { |
||
1005 | return $this->activateLegal; |
||
1006 | } |
||
1007 | |||
1008 | /** |
||
1009 | * @return bool |
||
1010 | */ |
||
1011 | public function isAddTeachersToSessionsCourses() |
||
1012 | { |
||
1013 | return $this->addTeachersToSessionsCourses; |
||
1014 | } |
||
1015 | |||
1016 | public function setAddTeachersToSessionsCourses(bool $addTeachersToSessionsCourses): self |
||
1017 | { |
||
1018 | $this->addTeachersToSessionsCourses = $addTeachersToSessionsCourses; |
||
1019 | |||
1020 | return $this; |
||
1021 | } |
||
1022 | |||
1023 | public function setCourseTypeId(int $courseTypeId): self |
||
1024 | { |
||
1025 | $this->courseTypeId = $courseTypeId; |
||
1026 | |||
1027 | return $this; |
||
1028 | } |
||
1029 | |||
1030 | /** |
||
1031 | * Get courseTypeId. |
||
1032 | * |
||
1033 | * @return int |
||
1034 | */ |
||
1035 | public function getCourseTypeId() |
||
1036 | { |
||
1037 | return $this->courseTypeId; |
||
1038 | } |
||
1039 | |||
1040 | public function getRoom(): ?Room |
||
1041 | { |
||
1042 | return $this->room; |
||
1043 | } |
||
1044 | |||
1045 | public function setRoom(Room $room): self |
||
1046 | { |
||
1047 | $this->room = $room; |
||
1048 | |||
1049 | return $this; |
||
1050 | } |
||
1051 | |||
1052 | public function isActive(): bool |
||
1053 | { |
||
1054 | $activeVisibilityList = [ |
||
1055 | self::REGISTERED, |
||
1056 | self::OPEN_PLATFORM, |
||
1057 | self::OPEN_WORLD, |
||
1058 | ]; |
||
1059 | |||
1060 | return \in_array($this->visibility, $activeVisibilityList, true); |
||
1061 | } |
||
1062 | |||
1063 | /** |
||
1064 | * Anybody can see this course. |
||
1065 | */ |
||
1066 | public function isPublic(): bool |
||
1067 | { |
||
1068 | return self::OPEN_WORLD === $this->visibility; |
||
1069 | } |
||
1070 | |||
1071 | public function isHidden(): bool |
||
1072 | { |
||
1073 | return self::HIDDEN === $this->visibility; |
||
1074 | } |
||
1075 | |||
1076 | public static function getStatusList(): array |
||
1077 | { |
||
1078 | return [ |
||
1079 | self::CLOSED => 'Closed', |
||
1080 | self::REGISTERED => 'Registered', |
||
1081 | self::OPEN_PLATFORM => 'Open platform', |
||
1082 | self::OPEN_WORLD => 'Open world', |
||
1083 | self::HIDDEN => 'Hidden', |
||
1084 | ]; |
||
1085 | } |
||
1086 | |||
1087 | /** |
||
1088 | * @return Session |
||
1089 | */ |
||
1090 | public function getCurrentSession() |
||
1093 | } |
||
1094 | |||
1095 | public function setCurrentSession(Session $session): self |
||
1096 | { |
||
1097 | // If the session is registered in the course session list. |
||
1098 | /*if ($this->getSessions()->contains($session->getId())) { |
||
1099 | $this->currentSession = $session; |
||
1100 | }*/ |
||
1101 | |||
1102 | $list = $this->getSessions(); |
||
1103 | /** @var SessionRelCourse $item */ |
||
1104 | foreach ($list as $item) { |
||
1105 | if ($item->getSession()->getId() === $session->getId()) { |
||
1106 | $this->currentSession = $session; |
||
1107 | |||
1108 | break; |
||
1109 | } |
||
1110 | } |
||
1111 | |||
1112 | return $this; |
||
1113 | } |
||
1114 | |||
1115 | public function setCurrentUrl(AccessUrl $url): self |
||
1116 | { |
||
1117 | $urlList = $this->getUrls(); |
||
1118 | /** @var AccessUrlRelCourse $item */ |
||
1119 | foreach ($urlList as $item) { |
||
1120 | if ($item->getUrl()->getId() === $url->getId()) { |
||
1121 | $this->currentUrl = $url; |
||
1122 | |||
1123 | break; |
||
1124 | } |
||
1125 | } |
||
1126 | |||
1127 | return $this; |
||
1128 | } |
||
1129 | |||
1130 | /** |
||
1131 | * @return AccessUrl |
||
1132 | */ |
||
1133 | public function getCurrentUrl() |
||
1134 | { |
||
1135 | return $this->currentUrl; |
||
1136 | } |
||
1137 | |||
1138 | /** |
||
1139 | * Get issuedSkills. |
||
1140 | * |
||
1141 | * @return Collection |
||
1142 | */ |
||
1143 | public function getIssuedSkills() |
||
1144 | { |
||
1145 | return $this->issuedSkills; |
||
1146 | } |
||
1147 | |||
1148 | public function hasSubscription(CourseRelUser $subscription): bool |
||
1165 | } |
||
1166 | |||
1167 | public function addUser(User $user, int $relationType, ?string $role, int $status): self |
||
1168 | { |
||
1169 | $courseRelUser = |
||
1170 | (new CourseRelUser()) |
||
1171 | ->setCourse($this) |
||
1172 | ->setUser($user) |
||
1173 | ->setRelationType($relationType) |
||
1174 | ->setStatus($status) |
||
1175 | ; |
||
1176 | $this->addUsers($courseRelUser); |
||
1177 | |||
1178 | return $this; |
||
1179 | } |
||
1180 | |||
1181 | /** |
||
1182 | * @return SessionRelCourseRelUser[]|Collection |
||
1183 | */ |
||
1184 | public function getSessionRelCourseRelUsers() |
||
1185 | { |
||
1186 | return $this->sessionRelCourseRelUsers; |
||
1187 | } |
||
1188 | |||
1189 | public function setSessionRelCourseRelUsers(Collection $sessionUserSubscriptions): self |
||
1190 | { |
||
1191 | $this->sessionRelCourseRelUsers = $sessionUserSubscriptions; |
||
1192 | |||
1193 | return $this; |
||
1194 | } |
||
1195 | |||
1196 | /** |
||
1197 | * @return SkillRelCourse[]|Collection |
||
1198 | */ |
||
1199 | public function getSkills() |
||
1200 | { |
||
1201 | return $this->skills; |
||
1202 | } |
||
1203 | |||
1204 | /** |
||
1205 | * @param SkillRelCourse[]|Collection $skills |
||
1206 | */ |
||
1207 | public function setSkills(Collection $skills): self |
||
1208 | { |
||
1209 | $this->skills = $skills; |
||
1210 | |||
1211 | return $this; |
||
1212 | } |
||
1213 | |||
1214 | /** |
||
1215 | * @return GradebookCategory[]|Collection |
||
1216 | */ |
||
1217 | public function getGradebookCategories() |
||
1218 | { |
||
1219 | return $this->gradebookCategories; |
||
1220 | } |
||
1221 | |||
1222 | /** |
||
1223 | * @param GradebookCategory[]|Collection $gradebookCategories |
||
1224 | */ |
||
1225 | public function setGradebookCategories(Collection $gradebookCategories): self |
||
1226 | { |
||
1227 | $this->gradebookCategories = $gradebookCategories; |
||
1228 | |||
1229 | return $this; |
||
1230 | } |
||
1231 | |||
1232 | /** |
||
1233 | * @return GradebookEvaluation[]|Collection |
||
1234 | */ |
||
1235 | public function getGradebookEvaluations() |
||
1236 | { |
||
1237 | return $this->gradebookEvaluations; |
||
1238 | } |
||
1239 | |||
1240 | /** |
||
1241 | * @param GradebookEvaluation[]|Collection $gradebookEvaluations |
||
1242 | */ |
||
1243 | public function setGradebookEvaluations(Collection $gradebookEvaluations): self |
||
1244 | { |
||
1245 | $this->gradebookEvaluations = $gradebookEvaluations; |
||
1246 | |||
1247 | return $this; |
||
1248 | } |
||
1249 | |||
1250 | /** |
||
1251 | * @return GradebookLink[]|Collection |
||
1252 | */ |
||
1253 | public function getGradebookLinks() |
||
1254 | { |
||
1255 | return $this->gradebookLinks; |
||
1256 | } |
||
1257 | |||
1258 | /** |
||
1259 | * @param GradebookLink[]|Collection $gradebookLinks |
||
1260 | */ |
||
1261 | public function setGradebookLinks(Collection $gradebookLinks): self |
||
1266 | } |
||
1267 | |||
1268 | /** |
||
1269 | * @return TrackEHotspot[]|Collection |
||
1270 | */ |
||
1271 | public function getTrackEHotspots() |
||
1272 | { |
||
1273 | return $this->trackEHotspots; |
||
1274 | } |
||
1275 | |||
1276 | /** |
||
1277 | * @param TrackEHotspot[]|Collection $trackEHotspots |
||
1278 | */ |
||
1279 | public function setTrackEHotspots(Collection $trackEHotspots): self |
||
1280 | { |
||
1281 | $this->trackEHotspots = $trackEHotspots; |
||
1282 | |||
1283 | return $this; |
||
1284 | } |
||
1285 | |||
1286 | /** |
||
1287 | * @return SearchEngineRef[]|Collection |
||
1288 | */ |
||
1289 | public function getSearchEngineRefs() |
||
1290 | { |
||
1291 | return $this->searchEngineRefs; |
||
1292 | } |
||
1293 | |||
1294 | /** |
||
1295 | * @param SearchEngineRef[]|Collection $searchEngineRefs |
||
1296 | */ |
||
1297 | public function setSearchEngineRefs(Collection $searchEngineRefs): self |
||
1298 | { |
||
1299 | $this->searchEngineRefs = $searchEngineRefs; |
||
1300 | |||
1301 | return $this; |
||
1302 | } |
||
1303 | |||
1304 | public function getIntroduction(): ?string |
||
1305 | { |
||
1306 | return $this->introduction; |
||
1307 | } |
||
1308 | |||
1309 | public function setIntroduction(?string $introduction): self |
||
1310 | { |
||
1311 | $this->introduction = $introduction; |
||
1312 | |||
1313 | return $this; |
||
1314 | } |
||
1315 | |||
1316 | /** |
||
1317 | * @return Templates[]|Collection |
||
1318 | */ |
||
1319 | public function getTemplates() |
||
1320 | { |
||
1321 | return $this->templates; |
||
1322 | } |
||
1323 | |||
1324 | /** |
||
1325 | * @param Templates[]|Collection $templates |
||
1326 | */ |
||
1327 | public function setTemplates(Collection $templates): self |
||
1328 | { |
||
1329 | $this->templates = $templates; |
||
1330 | |||
1331 | return $this; |
||
1332 | } |
||
1333 | |||
1334 | public function getVideoUrl(): string |
||
1335 | { |
||
1336 | return $this->videoUrl; |
||
1337 | } |
||
1338 | |||
1339 | public function setVideoUrl(string $videoUrl): self |
||
1344 | } |
||
1345 | |||
1346 | public function isSticky(): bool |
||
1347 | { |
||
1348 | return $this->sticky; |
||
1349 | } |
||
1350 | |||
1351 | public function setSticky(bool $sticky): self |
||
1352 | { |
||
1353 | $this->sticky = $sticky; |
||
1354 | |||
1355 | return $this; |
||
1356 | } |
||
1357 | |||
1358 | public function getDefaultIllustration(int $size): string |
||
1361 | } |
||
1362 | |||
1363 | public function getResourceIdentifier(): int |
||
1364 | { |
||
1365 | return $this->getId(); |
||
1366 | } |
||
1367 | |||
1368 | public function getResourceName(): string |
||
1371 | } |
||
1372 | |||
1373 | public function setResourceName(string $name): self |
||
1374 | { |
||
1375 | return $this->setCode($name); |
||
1376 | } |
||
1377 | } |
||
1378 |