Skip to content

Commit fffbd4c

Browse files
committed
hide share's vote count in true anonymous polls
Signed-off-by: dartcafe <[email protected]>
1 parent 8eb57f3 commit fffbd4c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/Db/Share.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
* @method void setDisplayName(string $value)
3838
* @method string getMiscSettings()
3939
* @method void setMiscSettings(string $value)
40-
* @method int getVoted()
41-
* @method void setVoted(int $value)
40+
* @method int getAnonymizedVotes()
4241
* @method int getDeleted()
4342
* @method void setDeleted(int $value)
4443
* @method string getLabel()
@@ -124,6 +123,7 @@ class Share extends EntityWithUser implements JsonSerializable {
124123

125124
// joined columns
126125
protected int $voted = 0;
126+
protected int $anonymizedVotes = 0;
127127

128128
public function __construct() {
129129
$this->addType('pollId', 'integer');
@@ -157,6 +157,10 @@ public function jsonSerialize(): array {
157157
];
158158
}
159159

160+
private function getVoted(): int {
161+
return $this->getAnonymizedVotes() ? 0 : $this->voted;
162+
}
163+
160164
/**
161165
* Setting, if email is optional, mandatory or hidden on public poll registration
162166
*/

lib/Db/ShareMapper.php

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function findByPoll(int $pollId, bool $getDeleted = false): array {
4646
}
4747

4848
$this->joinUserVoteCount($qb, self::TABLE);
49+
$this->joinAnon($qb, self::TABLE);
4950

5051
return $this->findEntities($qb);
5152
}
@@ -107,6 +108,7 @@ public function findByPollAndUser(int $pollId, string $userId, bool $findDeleted
107108
$qb->andWhere($qb->expr()->eq(self::TABLE . '.deleted', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
108109
}
109110
$this->joinUserVoteCount($qb, self::TABLE);
111+
$this->joinAnon($qb, self::TABLE);
110112

111113
try {
112114
return $this->findEntity($qb);
@@ -131,6 +133,7 @@ public function findByToken(string $token, bool $getDeleted = false): Share {
131133
}
132134

133135
$this->joinUserVoteCount($qb, self::TABLE);
136+
$this->joinAnon($qb, self::TABLE);
134137

135138
try {
136139
return $this->findEntity($qb);
@@ -183,4 +186,22 @@ protected function joinUserVoteCount(IQueryBuilder &$qb, string $fromAlias): voi
183186
);
184187
}
185188

189+
/**
190+
* Joins anonymous setting of poll
191+
*/
192+
protected function joinAnon(IQueryBuilder &$qb, string $fromAlias): void {
193+
$joinAlias = 'anon';
194+
195+
$qb->selectAlias($joinAlias . '.anonymous', 'anonymizedVotes')
196+
->addGroupBy(
197+
$joinAlias . '.anonymous',
198+
);
199+
200+
$qb->leftJoin(
201+
$fromAlias,
202+
Poll::TABLE,
203+
$joinAlias,
204+
$qb->expr()->eq($joinAlias . '.id', $fromAlias . '.poll_id'),
205+
);
206+
}
186207
}

0 commit comments

Comments
 (0)