@@ -54,6 +54,12 @@ public function find(int $id): PollGroup {
5454 return $ this ->findEntity ($ qb );
5555 }
5656
57+ /**
58+ * Add a Poll to a PollGroup
59+ *
60+ * @param int $pollId id of poll
61+ * @param int $groupId id of group
62+ */
5763 public function addPollToGroup (int $ pollId , int $ groupId ): void {
5864 $ qb = $ this ->db ->getQueryBuilder ();
5965 $ qb ->insert (PollGroup::RELATION_TABLE )
@@ -81,37 +87,25 @@ public function removePollFromGroup(int $pollId, int $groupId): void {
8187 $ qb ->executeStatement ();
8288 }
8389
90+ /**
91+ * Add a PollGroup
92+ *
93+ * @param PollGroup $pollGroup
94+ * @return PollGroup
95+ */
8496 public function add (PollGroup $ pollGroup ): PollGroup {
8597 $ pollGroup ->setCreated (time ());
8698 $ pollGroup ->setOwner ($ this ->userSession ->getCurrentUserId ());
8799 return $ this ->insert ($ pollGroup );
88100
89101 }
90102
103+ /**
104+ * Remove all PollGroups without associated Polls
105+ */
91106 public function tidyPollGroups (): void {
92107 $ qb = $ this ->db ->getQueryBuilder ();
93108
94- // This is, what we wanna do
95- //
96- // DELETE FROM oc_polls_groups
97- // WHERE `id` not IN (
98- // SELECT `group_id`
99- // FROM oc_polls_groups_polls)
100- //
101- // should result in
102- //
103- // $qb->delete(PollGroup::TABLE)
104- // ->where($qb->expr()->notIn(
105- // 'id',
106- // $qb->selectDistinct('group_id')
107- // ->from(PollGroup::RELATION_TABLE)
108- // ->getSQL(),
109- // IQueryBuilder::PARAM_INT_ARRAY
110- // )
111- // );
112- //
113- // But we have to use a subquery, otherwise, we get 'InvalidArgumentException Only strings, Literals and Parameters are allowed'
114-
115109 $ subquery = $ this ->db ->getQueryBuilder ();
116110 $ subquery ->selectDistinct ('group_id ' )->from (PollGroup::RELATION_TABLE );
117111
@@ -140,6 +134,12 @@ protected function buildQuery(): IQueryBuilder {
140134 return $ qb ;
141135 }
142136
137+ /**
138+ * Join the poll ids to the query builder
139+ *
140+ * @param IQueryBuilder $qb
141+ * @param string $joinAlias Alias for the joined polls table
142+ */
143143 protected function joinPollIds (
144144 IQueryBuilder $ qb ,
145145 string $ joinAlias = 'polls ' ,
0 commit comments