ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AssignmentManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
28 public const TYPE_ALL = "all";
29 public const TYPE_ONGOING = "ongoing";
30 public const TYPE_FUTURE = "future";
31 public const TYPE_PAST = "past";
32 protected int $user_id;
33 protected \ilLanguage $lng;
36 protected int $obj_id;
37
38 public function __construct(
39 InternalRepoService $repo_service,
40 InternalDomainService $domain_service,
41 int $obj_id,
42 int $user_id
43 ) {
44 $this->obj_id = $obj_id;
45 $this->domain = $domain_service;
46 $this->repo = $repo_service->assignment()->assignments();
47 $this->lng = $domain_service->lng();
48 $this->user_id = $user_id;
49 }
50
51 protected function getExcId(): int
52 {
53 return $this->obj_id;
54 }
55
56 public function getValidListMode(string $mode): string
57 {
58 if (!in_array($mode, [self::TYPE_ONGOING,self::TYPE_FUTURE,self::TYPE_PAST,self::TYPE_ALL])) {
59 return self::TYPE_ONGOING;
60 }
61 return $mode;
62 }
63
64 public function getListModes(): array
65 {
66 return [
67 self::TYPE_ONGOING => $this->lng->txt("exc_ongoing"),
68 self::TYPE_FUTURE => $this->lng->txt("exc_future"),
69 self::TYPE_PAST => $this->lng->txt("exc_past"),
70 self::TYPE_ALL => $this->lng->txt("exc_all")
71 ];
72 }
73
74 public function getListModeLabel(string $mode): string
75 {
76 $modes = $this->getListModes();
77 return $modes[$mode] ?? "";
78 }
79
83 public function getList(string $mode): \Iterator
84 {
85 foreach ($this->repo->getList($this->getExcId()) as $ass) {
86 $state = $this->domain->assignment()->state($ass->getId(), $this->user_id);
87 if ($mode === self::TYPE_PAST && $state->hasEnded()) {
88 yield $ass;
89 }
90 if ($mode === self::TYPE_FUTURE && $state->isFuture()) {
91 yield $ass;
92 }
93 if ($mode === self::TYPE_ONGOING && !$state->hasEnded() && !$state->isFuture()) {
94 yield $ass;
95 }
96 }
97 }
98
102 public function getAll(): \Iterator
103 {
104 foreach ($this->repo->getList($this->getExcId()) as $ass) {
105 yield $ass;
106 }
107 }
108
109 public function get(int $ass_id): Assignment
110 {
111 $ass = $this->repo->get($this->getExcId(), $ass_id);
112 if (is_null($ass)) {
113 throw new \ilExerciseException("Assignment not found (" . $this->getExcId() . "," . $ass_id . ").");
114 }
115 return $ass;
116 }
117
118}
__construct(InternalRepoService $repo_service, InternalDomainService $domain_service, int $obj_id, int $user_id)