Completed
Push — master ( d62417...7b2aa5 )
by René
10:14 queued 11s
created

LogMapper::findUnprocessed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 findByPollId($pollId) {
42
		$qb = $this->db->getQueryBuilder();
43
44
		$qb->select('*')
45
			->from($this->getTableName())
46
			->where(
47
 			   $qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT))
48
 		   );
49
50
		return $this->findEntities($qb);
51
52
	}
53
54
	public function findUnprocessed() {
55
		$qb = $this->db->getQueryBuilder();
56
57
		$qb->select('*')
58
			->from($this->getTableName())
59
			->where(
60
 			   $qb->expr()->eq('processed', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
61
 		   );
62
63
		return $this->findEntities($qb);
64
65
	}
66
67
	public function findUnprocessedPolls() {
68
		$qb = $this->db->getQueryBuilder();
69
70
		$qb->selectDistinct('poll_id')
71
			->from($this->getTableName())
72
			->where($qb->expr()->eq('processed', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
73
		return $this->findEntities($qb);
74
75
	}
76
77
	public function getLastRecord($pollId) {
78
		$qb = $this->db->getQueryBuilder();
79
80
		$qb->select('*')
81
			->from($this->getTableName())
82
			->where($qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId, IQueryBuilder::PARAM_INT)))
83
			->setMaxResults( 1 )
84
		    ->orderBy('id', 'DESC');
85
86
		return $this->findEntity($qb);
87
88
	}
89
90
91
92
}
93