Code Duplication    Length = 59-61 lines in 3 locations

lib/Db/NotificationMapper.php 1 location

@@ 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 int $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 int $pollId
82
	 * @param string $userId
83
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
84
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
85
	 * @return Notification
86
	 */
87
	public function findByUserAndPoll($pollId, $userId) {
88
		$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
89
		return $this->findEntity($sql, [$pollId, $userId]);
90
	}
91
}
92

lib/Db/ParticipationMapper.php 1 location

@@ 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 int $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 int $pollId
63
	 * @param int $limit
64
	 * @param int $offset
65
	 * @return Participation[]
66
	 */
67
	public function findParticipantsByPoll($pollId, $limit = null, $offset = null) {
68
		$sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
69
		return $this->findEntities($sql, [$pollId], $limit, $offset);
70
	}
71
72
	/**
73
	 * @param int $pollId
74
	 */
75
	public function deleteByPoll($pollId) {
76
		$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
77
		$this->execute($sql, [$pollId]);
78
	}
79
80
	/**
81
	 * @param int $pollId
82
	 * @param string $userId
83
	 */
84
	public function deleteByPollAndUser($pollId, $userId) {
85
		$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
86
		$this->execute($sql, [$pollId, $userId]);
87
	}
88
}
89

lib/Db/ParticipationTextMapper.php 1 location

@@ 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 int $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 int $pollId
63
	 * @param int $limit
64
	 * @param int $offset
65
	 * @return ParticipationText[]
66
	 */
67
	public function findParticipantsByPoll($pollId, $limit = null, $offset = null) {
68
		$sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
69
		return $this->findEntities($sql, [$pollId], $limit, $offset);
70
	}
71
72
	/**
73
	 * @param int $pollId
74
	 */
75
	public function deleteByPoll($pollId) {
76
		$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
77
		$this->execute($sql, [$pollId]);
78
	}
79
80
	/**
81
	 * @param int $pollId
82
	 * @param string $userId
83
	 */
84
	public function deleteByPollAndUser($pollId, $userId) {
85
		$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
86
		$this->execute($sql, [$pollId, $userId]);
87
	}
88
}
89