Passed
Pull Request — master (#1269)
by René
03:33
created

LogMapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 32
dl 0
loc 65
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A findUnprocessed() 0 10 1
A findUnprocessedPolls() 0 7 1
A find() 0 10 1
A getLastRecord() 0 10 1
A findByPollId() 0 10 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author Vinzenz Rosenkranz <[email protected]>
6
 * @author René Gieling <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 *  This program is free software: you can redistribute it and/or modify
11
 *  it under the terms of the GNU Affero General Public License as
12
 *  published by the Free Software Foundation, either version 3 of the
13
 *  License, or (at your option) any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Affero General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU Affero General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\Polls\Db;
26
27
use OCP\DB\QueryBuilder\IQueryBuilder;
28
use OCP\IDBConnection;
29
use OCP\AppFramework\Db\QBMapper;
30
31
class LogMapper extends QBMapper {
32
33
	/**
34
	 * LogMapper constructor.
35
	 * @param IDBConnection $db
36
	 */
37
	public function __construct(IDBConnection $db) {
38
		parent::__construct($db, 'polls_log', '\OCA\Polls\Db\Log');
39
	}
40
41
	public function find($id) {
42
		$qb = $this->db->getQueryBuilder();
43
44
		$qb->select('*')
45
		   ->from($this->getTableName())
46
		   ->where(
47
			   $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
48
		   );
49
50
		return $this->findEntity($qb);
51
	}
52
53
	public function findByPollId($pollId) {
54
		$qb = $this->db->getQueryBuilder();
55
56
		$qb->select('*')
57
			->from($this->getTableName())
58
			->where(
59
			   $qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT))
60
		   );
61
62
		return $this->findEntities($qb);
63
	}
64
65
	public function findUnprocessed() {
66
		$qb = $this->db->getQueryBuilder();
67
68
		$qb->select('*')
69
			->from($this->getTableName())
70
			->where(
71
			   $qb->expr()->eq('processed', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
72
		   );
73
74
		return $this->findEntities($qb);
75
	}
76
77
	public function findUnprocessedPolls() {
78
		$qb = $this->db->getQueryBuilder();
79
80
		$qb->selectDistinct('poll_id')
81
			->from($this->getTableName())
82
			->where($qb->expr()->eq('processed', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
83
		return $this->findEntities($qb);
84
	}
85
86
	public function getLastRecord($pollId) {
87
		$qb = $this->db->getQueryBuilder();
88
89
		$qb->select('*')
90
			->from($this->getTableName())
91
			->where($qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT)))
92
			->setMaxResults(1)
93
			->orderBy('id', 'DESC');
94
95
		return $this->findEntity($qb);
96
	}
97
}
98