ILIAS  release_8 Revision v8.23
class.ilBuddySystemRelation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
28  protected int $usrId;
29  protected int $buddyUsrId;
30  protected bool $isOwnedByActor;
31  protected int $timestamp;
33 
34  public function __construct(
36  int $usrId,
37  int $buddyUsrId,
38  bool $isOwnedByActor,
39  int $timestamp
40  ) {
41  $this->usrId = $usrId;
42  $this->buddyUsrId = $buddyUsrId;
44  $this->timestamp = $timestamp;
45  $this->setState($state, false);
46  }
47 
48  private function setPriorState(ilBuddySystemRelationState $prior_state): void
49  {
50  $this->priorState = $prior_state;
51  }
52 
53  public function setState(ilBuddySystemRelationState $state, bool $rememberPriorState = true): self
54  {
55  if ($rememberPriorState) {
56  $this->setPriorState($this->getState());
57  }
58 
59  $this->state = $state;
60  return $this;
61  }
62 
64  {
65  return $this->state;
66  }
67 
69  {
70  return $this->priorState;
71  }
72 
73  public function isOwnedByActor(): bool
74  {
75  return $this->isOwnedByActor;
76  }
77 
78  public function withIsOwnedByActor(bool $isOwnedByActor): self
79  {
80  $clone = clone $this;
81  $clone->isOwnedByActor = $isOwnedByActor;
82 
83  return $clone;
84  }
85 
86  public function getBuddyUsrId(): int
87  {
88  return $this->buddyUsrId;
89  }
90 
91  public function withBuddyUsrId(int $buddyUsrId): self
92  {
93  $clone = clone $this;
94  $clone->buddyUsrId = $buddyUsrId;
95 
96  return $clone;
97  }
98 
99  public function getUsrId(): int
100  {
101  return $this->usrId;
102  }
103 
104  public function withUsrId(int $usrId): self
105  {
106  $clone = clone $this;
107  $clone->usrId = $usrId;
108 
109  return $clone;
110  }
111 
112  public function getTimestamp(): int
113  {
114  return $this->timestamp;
115  }
116 
117  public function withTimestamp(int $timestamp): self
118  {
119  $clone = clone $this;
120  $clone->timestamp = $timestamp;
121 
122  return $clone;
123  }
124 
126  {
127  return ilBuddySystemRelationStateFilterRuleFactory::getInstance()->getFilterRuleByRelation($this)->getStates();
128  }
129 
134  public function link(): self
135  {
136  if ($this->getUsrId() === $this->getBuddyUsrId()) {
137  throw new ilBuddySystemRelationStateException("Can't change a state when the requester equals the requestee.");
138  }
139 
140  $this->getState()->link($this);
141  return $this;
142  }
143 
148  public function unlink(): self
149  {
150  if ($this->getUsrId() === $this->getBuddyUsrId()) {
151  throw new ilBuddySystemRelationStateException("Can't change a state when the requester equals the requestee.");
152  }
153 
154  $this->getState()->unlink($this);
155  return $this;
156  }
157 
162  public function request(): self
163  {
164  if ($this->getUsrId() === $this->getBuddyUsrId()) {
165  throw new ilBuddySystemRelationStateException("Can't change a state when the requester equals the requestee.");
166  }
167 
168  $this->getState()->request($this);
169  return $this;
170  }
171 
176  public function ignore(): self
177  {
178  if ($this->getUsrId() === $this->getBuddyUsrId()) {
179  throw new ilBuddySystemRelationStateException("Can't change a state when the requester equals the requestee.");
180  }
181 
182  $this->getState()->ignore($this);
183  return $this;
184  }
185 
186  public function isLinked(): bool
187  {
188  return $this->getState() instanceof ilBuddySystemLinkedRelationState;
189  }
190 
191  public function isUnlinked(): bool
192  {
193  return $this->getState() instanceof ilBuddySystemUnlinkedRelationState;
194  }
195 
196  public function isRequested(): bool
197  {
198  return $this->getState() instanceof ilBuddySystemRequestedRelationState;
199  }
200 
201  public function isIgnored(): bool
202  {
203  return $this->getState() instanceof ilBuddySystemIgnoredRequestRelationState;
204  }
205 
206  public function wasLinked(): bool
207  {
208  return $this->getPriorState() instanceof ilBuddySystemLinkedRelationState;
209  }
210 
211  public function wasUnlinked(): bool
212  {
213  return $this->getPriorState() instanceof ilBuddySystemUnlinkedRelationState;
214  }
215 
216  public function wasRequested(): bool
217  {
218  return $this->getPriorState() instanceof ilBuddySystemRequestedRelationState;
219  }
220 
221  public function wasIgnored(): bool
222  {
223  return $this->getPriorState() instanceof ilBuddySystemIgnoredRequestRelationState;
224  }
225 }
setState(ilBuddySystemRelationState $state, bool $rememberPriorState=true)
ilBuddySystemRelationState $state
Interface ilBuddySystemCollection.
Class ilBuddySystemUnlinkedRelationState.
__construct(ilBuddySystemRelationState $state, int $usrId, int $buddyUsrId, bool $isOwnedByActor, int $timestamp)
setPriorState(ilBuddySystemRelationState $prior_state)
ilBuddySystemRelationState $priorState
withIsOwnedByActor(bool $isOwnedByActor)
Interface ilBuddySystemRelationState.