Skip to content

Commit d2b16e6

Browse files
committed
feat: ajout - Add back DEFAULT_CHOSEN_RANK instead use database. eslint fix
1 parent 1527f87 commit d2b16e6

File tree

11 files changed

+192
-172
lines changed

11 files changed

+192
-172
lines changed

lib/Db/Poll.php

Lines changed: 133 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,63 @@
1818

1919
/**
2020
* @psalm-api
21-
* @method int getId()
22-
* @method void setId(int $value)
23-
* @method string getType()
24-
* @method void setType(string $value)
25-
* @method string getTitle()
26-
* @method void setTitle(string $value)
27-
* @method string getDescription()
28-
* @method void setDescription(string $value)
29-
* @method string getOwner()
30-
* @method void setOwner(string $value)
31-
* @method int getCreated()
32-
* @method void setCreated(int $value)
33-
* @method int getExpire()
34-
* @method void setExpire(int $value)
35-
* @method int getDeleted()
36-
* @method void setDeleted(int $value)
37-
* @method string getAccess()
38-
* @method void setAccess(string $value)
39-
* @method int getAnonymous()
40-
* @method void setAnonymous(int $value)
41-
* @method int getAllowComment()
42-
* @method void setAllowComment(int $value)
43-
* @method int getAllowMaybe()
44-
* @method string getChosenRank()
45-
* @method void setAllowMaybe(int $value)
46-
* @method void setChosenRank(string $value)
47-
* @method string getAllowProposals()
48-
* @method void setAllowProposals(string $value)
49-
* @method int getProposalsExpire()
50-
* @method void setProposalsExpire(int $value)
51-
* @method int getVoteLimit()
52-
* @method void setVoteLimit(int $value)
53-
* @method int getOptionLimit()
54-
* @method void setOptionLimit(int $value)
55-
* @method string getShowResults()
56-
* @method void setShowResults(string $value)
57-
* @method int getAdminAccess()
58-
* @method void setAdminAccess(int $value)
59-
* @method int getHideBookedUp()
60-
* @method void setHideBookedUp(int $value)
61-
* @method int getUseNo()
62-
* @method void setUseNo(int $value)
63-
* @method int getLastInteraction()
64-
* @method void setLastInteraction(int $value)
65-
* @method string getMiscSettings()
66-
* @method void setMiscSettings(string $value)
21+
* @method int getId()
22+
* @method void setId(int $value)
23+
* @method string getType()
24+
* @method void setType(string $value)
25+
* @method string getTitle()
26+
* @method void setTitle(string $value)
27+
* @method string getDescription()
28+
* @method void setDescription(string $value)
29+
* @method string getOwner()
30+
* @method void setOwner(string $value)
31+
* @method int getCreated()
32+
* @method void setCreated(int $value)
33+
* @method int getExpire()
34+
* @method void setExpire(int $value)
35+
* @method int getDeleted()
36+
* @method void setDeleted(int $value)
37+
* @method string getAccess()
38+
* @method void setAccess(string $value)
39+
* @method int getAnonymous()
40+
* @method void setAnonymous(int $value)
41+
* @method int getAllowComment()
42+
* @method void setAllowComment(int $value)
43+
* @method int getAllowMaybe()
44+
* @method string getChosenRank()
45+
* @method void setAllowMaybe(int $value)
46+
* @method void setChosenRank(string $value)
47+
* @method string getAllowProposals()
48+
* @method void setAllowProposals(string $value)
49+
* @method int getProposalsExpire()
50+
* @method void setProposalsExpire(int $value)
51+
* @method int getVoteLimit()
52+
* @method void setVoteLimit(int $value)
53+
* @method int getOptionLimit()
54+
* @method void setOptionLimit(int $value)
55+
* @method string getShowResults()
56+
* @method void setShowResults(string $value)
57+
* @method int getAdminAccess()
58+
* @method void setAdminAccess(int $value)
59+
* @method int getHideBookedUp()
60+
* @method void setHideBookedUp(int $value)
61+
* @method int getUseNo()
62+
* @method void setUseNo(int $value)
63+
* @method int getLastInteraction()
64+
* @method void setLastInteraction(int $value)
65+
* @method string getMiscSettings()
66+
* @method void setMiscSettings(string $value)
6767
*
6868
* Magic functions for joined columns
69-
* @method int getMinDate()
70-
* @method int getMaxDate()
71-
* @method int getShareToken()
72-
* @method int getCountOptions()
69+
* @method int getMinDate()
70+
* @method int getMaxDate()
71+
* @method int getShareToken()
72+
* @method int getCountOptions()
7373
*
7474
* Magic functions for subqueried columns
75-
* @method int getCurrentUserOrphanedVotes()
76-
* @method int getCurrentUserVotes()
77-
* @method int getCurrentUserVotesYes()
75+
* @method int getCurrentUserOrphanedVotes()
76+
* @method int getCurrentUserVotes()
77+
* @method int getCurrentUserVotesYes()
7878
*/
7979

8080
class Poll extends EntityWithUser implements JsonSerializable
@@ -206,83 +206,83 @@ public function __construct()
206206
public function jsonSerialize(): array
207207
{
208208
return [
209-
'id' => $this->getId(),
210-
'type' => $this->getType(),
211-
// editable settings
212-
'configuration' => $this->getConfigurationArray(),
213-
// read only properties
214-
'descriptionSafe' => $this->getDescriptionSafe(),
215-
// read only properties
216-
'owner' => $this->getUser(),
217-
'status' => $this->getStatusArray(),
218-
'currentUserStatus' => $this->getCurrentUserStatus(),
219-
'permissions' => $this->getPermissionsArray(),
209+
'id' => $this->getId(),
210+
'type' => $this->getType(),
211+
// editable settings
212+
'configuration' => $this->getConfigurationArray(),
213+
// read only properties
214+
'descriptionSafe' => $this->getDescriptionSafe(),
215+
// read only properties
216+
'owner' => $this->getUser(),
217+
'status' => $this->getStatusArray(),
218+
'currentUserStatus' => $this->getCurrentUserStatus(),
219+
'permissions' => $this->getPermissionsArray(),
220220
];
221221
}
222222

223223
public function getStatusArray(): array
224224
{
225225
return [
226-
'lastInteraction' => $this->getLastInteraction(),
227-
'created' => $this->getCreated(),
228-
'deleted' => boolval($this->getDeleted()),
229-
'expired' => $this->getExpired(),
230-
'relevantThreshold' => $this->getRelevantThreshold(),
231-
'countOptions' => $this->getCountOptions(),
226+
'lastInteraction' => $this->getLastInteraction(),
227+
'created' => $this->getCreated(),
228+
'deleted' => boolval($this->getDeleted()),
229+
'expired' => $this->getExpired(),
230+
'relevantThreshold' => $this->getRelevantThreshold(),
231+
'countOptions' => $this->getCountOptions(),
232232
];
233233
}
234234
public function getConfigurationArray(): array
235235
{
236236
return [
237-
'title' => $this->getTitle(),
238-
'description' => $this->getDescription(),
239-
'access' => $this->getAccess(),
240-
'allowComment' => boolval($this->getAllowComment()),
241-
'allowMaybe' => boolval($this->getAllowMaybe()),
242-
'chosenRank' => $this->getChosenRank(),
243-
'allowProposals' => $this->getAllowProposals(),
244-
'anonymous' => boolval($this->getAnonymous()),
245-
'autoReminder' => $this->getAutoReminder(),
246-
'expire' => $this->getExpire(),
247-
'hideBookedUp' => boolval($this->getHideBookedUp()),
248-
'proposalsExpire' => $this->getProposalsExpire(),
249-
'showResults' => $this->getShowResults(),
250-
'useNo' => boolval($this->getUseNo()),
251-
'maxVotesPerOption' => $this->getOptionLimit(),
252-
'maxVotesPerUser' => $this->getVoteLimit(),
237+
'title' => $this->getTitle(),
238+
'description' => $this->getDescription(),
239+
'access' => $this->getAccess(),
240+
'allowComment' => boolval($this->getAllowComment()),
241+
'allowMaybe' => boolval($this->getAllowMaybe()),
242+
'chosenRank' => $this->getChosenRank(),
243+
'allowProposals' => $this->getAllowProposals(),
244+
'anonymous' => boolval($this->getAnonymous()),
245+
'autoReminder' => $this->getAutoReminder(),
246+
'expire' => $this->getExpire(),
247+
'hideBookedUp' => boolval($this->getHideBookedUp()),
248+
'proposalsExpire' => $this->getProposalsExpire(),
249+
'showResults' => $this->getShowResults(),
250+
'useNo' => boolval($this->getUseNo()),
251+
'maxVotesPerOption' => $this->getOptionLimit(),
252+
'maxVotesPerUser' => $this->getVoteLimit(),
253253
];
254254
}
255255

256256
public function getCurrentUserStatus(): array
257257
{
258258
return [
259-
'userRole' => $this->getUserRole(),
260-
'isLocked' => boolval($this->getIsCurrentUserLocked()),
261-
'isInvolved' => $this->getIsInvolved(),
262-
'isLoggedIn' => $this->userSession->getIsLoggedIn(),
263-
'isNoUser' => !$this->userSession->getIsLoggedIn(),
264-
'isOwner' => $this->getIsPollOwner(),
265-
'userId' => $this->getUserId(),
266-
'orphanedVotes' => $this->getCurrentUserOrphanedVotes(),
267-
'yesVotes' => $this->getCurrentUserVotesYes(),
268-
'countVotes' => $this->getCurrentUserVotes(),
269-
'shareToken' => $this->getShareToken(),
270-
'groupInvitations' => $this->getGroupShares(),
259+
'userRole' => $this->getUserRole(),
260+
'isLocked' => boolval($this->getIsCurrentUserLocked()),
261+
'isInvolved' => $this->getIsInvolved(),
262+
'isLoggedIn' => $this->userSession->getIsLoggedIn(),
263+
'isNoUser' => !$this->userSession->getIsLoggedIn(),
264+
'isOwner' => $this->getIsPollOwner(),
265+
'userId' => $this->getUserId(),
266+
'orphanedVotes' => $this->getCurrentUserOrphanedVotes(),
267+
'yesVotes' => $this->getCurrentUserVotesYes(),
268+
'countVotes' => $this->getCurrentUserVotes(),
269+
'shareToken' => $this->getShareToken(),
270+
'groupInvitations' => $this->getGroupShares(),
271271
];
272272
}
273273
public function getPermissionsArray(): array
274274
{
275275
return [
276-
'addOptions' => $this->getIsAllowed(self::PERMISSION_OPTIONS_ADD),
277-
'archive' => $this->getIsAllowed(self::PERMISSION_POLL_ARCHIVE),
278-
'comment' => $this->getIsAllowed(self::PERMISSION_COMMENT_ADD),
279-
'delete' => $this->getIsAllowed(self::PERMISSION_POLL_DELETE),
280-
'edit' => $this->getIsAllowed(self::PERMISSION_POLL_EDIT),
281-
'seeResults' => $this->getIsAllowed(self::PERMISSION_POLL_RESULTS_VIEW),
282-
'seeUsernames' => $this->getIsAllowed(self::PERMISSION_POLL_USERNAMES_VIEW),
283-
'subscribe' => $this->getIsAllowed(self::PERMISSION_POLL_SUBSCRIBE),
284-
'view' => $this->getIsAllowed(self::PERMISSION_POLL_VIEW),
285-
'vote' => $this->getIsAllowed(self::PERMISSION_VOTE_EDIT),
276+
'addOptions' => $this->getIsAllowed(self::PERMISSION_OPTIONS_ADD),
277+
'archive' => $this->getIsAllowed(self::PERMISSION_POLL_ARCHIVE),
278+
'comment' => $this->getIsAllowed(self::PERMISSION_COMMENT_ADD),
279+
'delete' => $this->getIsAllowed(self::PERMISSION_POLL_DELETE),
280+
'edit' => $this->getIsAllowed(self::PERMISSION_POLL_EDIT),
281+
'seeResults' => $this->getIsAllowed(self::PERMISSION_POLL_RESULTS_VIEW),
282+
'seeUsernames' => $this->getIsAllowed(self::PERMISSION_POLL_USERNAMES_VIEW),
283+
'subscribe' => $this->getIsAllowed(self::PERMISSION_POLL_SUBSCRIBE),
284+
'view' => $this->getIsAllowed(self::PERMISSION_POLL_VIEW),
285+
'vote' => $this->getIsAllowed(self::PERMISSION_VOTE_EDIT),
286286
];
287287
}
288288

@@ -321,8 +321,8 @@ public function getExpired(): bool
321321
$expiry = $this->getExpire();
322322

323323
return (
324-
$expiry > 0
325-
&& $expiry < $compareTime
324+
$expiry > 0
325+
&& $expiry < $compareTime
326326
);
327327
}
328328

@@ -402,8 +402,8 @@ public function getAccess()
402402
public function getProposalsExpired(): bool
403403
{
404404
return (
405-
$this->getProposalsExpire() > 0
406-
&& $this->getProposalsExpire() < time()
405+
$this->getProposalsExpire() > 0
406+
&& $this->getProposalsExpire() < time()
407407
);
408408
}
409409

@@ -446,16 +446,14 @@ public function getTimeToDeadline(int $time = 0): int
446446

447447
$deadline = $this->getDeadline();
448448

449-
if (
450-
$deadline - $this->getCreated() > self::FIVE_DAYS
449+
if ($deadline - $this->getCreated() > self::FIVE_DAYS
451450
&& $deadline - $time < self::TWO_DAYS
452451
&& $deadline > $time
453452
) {
454453
return self::TWO_DAYS;
455454
}
456455

457-
if (
458-
$deadline - $this->getCreated() > self::TWO_DAYS
456+
if ($deadline - $this->getCreated() > self::TWO_DAYS
459457
&& $deadline - $time < self::ONE_AND_HALF_DAY
460458
&& $deadline > $time
461459
) {
@@ -505,13 +503,12 @@ private function setMiscSettingsByKey(string $key, $value): void
505503
}
506504

507505
/**
508-
*
509506
* Check Permissions
510-
*
511507
*/
512508

513509
/**
514510
* Request a permission level and get exception if denied
511+
*
515512
* @throws ForbiddenException Thrown if access is denied
516513
*/
517514
public function request(string $permission): void
@@ -548,15 +545,16 @@ public function getIsAllowed(string $permission): bool
548545

549546
/**
550547
* getIsInvolved - Is current user involved in current poll?
548+
*
551549
* @return bool Returns true, if the current user is involved in the poll via share, as a participant or as the poll owner.
552550
*/
553551
private function getIsInvolved(): bool
554552
{
555553
return (
556-
$this->getIsPollOwner()
557-
|| $this->getIsParticipant()
558-
|| $this->getIsPersonallyInvited())
559-
|| $this->getIsInvitedViaGroupShare();
554+
$this->getIsPollOwner()
555+
|| $this->getIsParticipant()
556+
|| $this->getIsPersonallyInvited())
557+
|| $this->getIsInvitedViaGroupShare();
560558
}
561559

562560
/**
@@ -569,6 +567,7 @@ private function getIsOpenPoll(): bool
569567

570568
/**
571569
* getIsParticipant - Is user a participant?
570+
*
572571
* @return bool Returns true, if the current user is already a particitipant of the current poll.
573572
*/
574573
private function getIsParticipant(): bool
@@ -579,6 +578,7 @@ private function getIsParticipant(): bool
579578
/**
580579
* getIsInvitedViaGroupShare - Is the poll shared via group share?
581580
* where the current user is member of. This only affects logged in users.
581+
*
582582
* @return bool Returns true, if the current poll contains a group share with a group,
583583
*/
584584
private function getIsInvitedViaGroupShare(): bool
@@ -592,24 +592,29 @@ private function getIsInvitedViaGroupShare(): bool
592592

593593
private function getGroupSharesForUser(): array
594594
{
595-
return array_filter($this->getGroupShares(), function ($groupName) {
596-
return ($this->userSession->getUser()->getIsInGroup($groupName));
597-
});
595+
return array_filter(
596+
$this->getGroupShares(), function ($groupName) {
597+
return ($this->userSession->getUser()->getIsInGroup($groupName));
598+
}
599+
);
598600
}
599601
/**
600602
* getIsPersonallyInvited - Is the poll shared via user share with the current user?
601603
* Checking via user role
604+
*
602605
* @return bool Returns true, if the current poll contains a user role which matches a share type
603606
*/
604607
private function getIsPersonallyInvited(): bool
605608
{
606-
return in_array($this->getUserRole(), [
609+
return in_array(
610+
$this->getUserRole(), [
607611
Poll::ROLE_ADMIN,
608612
Poll::ROLE_USER,
609613
Poll::ROLE_EXTERNAL,
610614
Poll::ROLE_EMAIL,
611615
Poll::ROLE_CONTACT,
612-
]);
616+
]
617+
);
613618
}
614619

615620
/**
@@ -623,7 +628,7 @@ private function getIsPersonallyInvited(): bool
623628
private function getIsDelegatedAdmin(): bool
624629
{
625630
return $this->getUserRole() === Poll::ROLE_ADMIN
626-
&& !$this->getIsCurrentUserLocked();
631+
&& !$this->getIsCurrentUserLocked();
627632
}
628633

629634
/**

0 commit comments

Comments
 (0)