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