| @@ 29-89 (lines=61) @@ | ||
| 26 | use OCP\AppFramework\Db\Mapper; |
|
| 27 | use OCP\IDBConnection; |
|
| 28 | ||
| 29 | class NotificationMapper extends Mapper { |
|
| 30 | ||
| 31 | public function __construct(IDBConnection $db) { |
|
| 32 | parent::__construct($db, 'polls_notif', '\OCA\Polls\Db\Notification'); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @param int $id |
|
| 37 | * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
| 38 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
| 39 | * @return Notification |
|
| 40 | */ |
|
| 41 | public function find($id) { |
|
| 42 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?'; |
|
| 43 | return $this->findEntity($sql, [$id]); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param string $userId |
|
| 48 | * @param string $from |
|
| 49 | * @param string $until |
|
| 50 | * @param int $limit |
|
| 51 | * @param int $offset |
|
| 52 | * @return Notification[] |
|
| 53 | */ |
|
| 54 | public function findBetween($userId, $from, $until, $limit = null, $offset = null) { |
|
| 55 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE userId = ? AND timestamp BETWEEN ? AND ?'; |
|
| 56 | return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * @param int $limit |
|
| 61 | * @param int $offset |
|
| 62 | * @return Notification[] |
|
| 63 | */ |
|
| 64 | public function findAll($limit = null, $offset = null) { |
|
| 65 | $sql = 'SELECT * FROM ' . $this->getTableName(); |
|
| 66 | return $this->findEntities($sql, [], $limit, $offset); |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @param string $pollId |
|
| 71 | * @param int $limit |
|
| 72 | * @param int $offset |
|
| 73 | * @return Notification[] |
|
| 74 | */ |
|
| 75 | public function findAllByPoll($pollId, $limit = null, $offset = null) { |
|
| 76 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 77 | return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 78 | } |
|
| 79 | ||
| 80 | /** |
|
| 81 | * @param string $pollId |
|
| 82 | * @param string $userId |
|
| 83 | * @return Notification if not found |
|
| 84 | */ |
|
| 85 | public function findByUserAndPoll($pollId, $userId) { |
|
| 86 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
| 87 | return $this->findEntity($sql, [$pollId, $userId]); |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| @@ 29-87 (lines=59) @@ | ||
| 26 | use OCP\AppFramework\Db\Mapper; |
|
| 27 | use OCP\IDBConnection; |
|
| 28 | ||
| 29 | class ParticipationMapper extends Mapper { |
|
| 30 | ||
| 31 | /** |
|
| 32 | * ParticipationMapper constructor. |
|
| 33 | * @param IDBConnection $db |
|
| 34 | */ |
|
| 35 | public function __construct(IDBConnection $db) { |
|
| 36 | parent::__construct($db, 'polls_particip', '\OCA\Polls\Db\Participation'); |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param string $userId |
|
| 41 | * @param int $limit |
|
| 42 | * @param int $offset |
|
| 43 | * @return Participation[] |
|
| 44 | */ |
|
| 45 | public function findDistinctByUser($userId, $limit = null, $offset = null) { |
|
| 46 | $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
|
| 47 | return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param string $pollId |
|
| 52 | * @param int $limit |
|
| 53 | * @param int $offset |
|
| 54 | * @return Participation[] |
|
| 55 | */ |
|
| 56 | public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 57 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 58 | return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @param string $pollId |
|
| 63 | * @param int $limit |
|
| 64 | * @param int $offset |
|
| 65 | */ |
|
| 66 | public function listParticipantsByPoll($pollId, $limit = null, $offset = null) { |
|
| 67 | $sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 68 | return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param string $pollId |
|
| 73 | */ |
|
| 74 | public function deleteByPoll($pollId) { |
|
| 75 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 76 | $this->execute($sql, [$pollId]); |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @param string $pollId |
|
| 81 | * @param string $userId |
|
| 82 | */ |
|
| 83 | public function deleteByPollAndUser($pollId, $userId) { |
|
| 84 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
| 85 | $this->execute($sql, [$pollId, $userId]); |
|
| 86 | } |
|
| 87 | } |
|
| 88 | ||
| @@ 29-87 (lines=59) @@ | ||
| 26 | use OCP\AppFramework\Db\Mapper; |
|
| 27 | use OCP\IDBConnection; |
|
| 28 | ||
| 29 | class ParticipationTextMapper extends Mapper { |
|
| 30 | ||
| 31 | /** |
|
| 32 | * ParticipationTextMapper constructor. |
|
| 33 | * @param IDBConnection $db |
|
| 34 | */ |
|
| 35 | public function __construct(IDBConnection $db) { |
|
| 36 | parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText'); |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param string $pollId |
|
| 41 | * @param int $limit |
|
| 42 | * @param int $offset |
|
| 43 | * @return ParticipationText[] |
|
| 44 | */ |
|
| 45 | public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 46 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 47 | return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param string $userId |
|
| 52 | * @param int $limit |
|
| 53 | * @param int $offset |
|
| 54 | * @return ParticipationText[] |
|
| 55 | */ |
|
| 56 | public function findDistinctByUser($userId, $limit = null, $offset = null) { |
|
| 57 | $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
|
| 58 | return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @param string $pollId |
|
| 63 | * @param int $limit |
|
| 64 | * @param int $offset |
|
| 65 | */ |
|
| 66 | public function listParticipantsByPoll($pollId, $limit = null, $offset = null) { |
|
| 67 | $sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 68 | return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param string $pollId |
|
| 73 | */ |
|
| 74 | public function deleteByPoll($pollId) { |
|
| 75 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 76 | $this->execute($sql, [$pollId]); |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @param string $pollId |
|
| 81 | * @param string $userId |
|
| 82 | */ |
|
| 83 | public function deleteByPollAndUser($pollId, $userId) { |
|
| 84 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
| 85 | $this->execute($sql, [$pollId, $userId]); |
|
| 86 | } |
|
| 87 | } |
|
| 88 | ||