CollectedAddressMapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Thomas Müller <[email protected]>
6
 *
7
 * Mail
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Mail\Db;
24
25
use OCP\AppFramework\Db\Mapper;
26
use OCP\IDb;
27
28
class CollectedAddressMapper extends Mapper {
29
30
	/**
31
	 * @param IDb $db
32
	 */
33 4
	public function __construct(IDb $db) {
34 4
		parent::__construct($db, 'mail_collected_addresses');
35 4
	}
36
37
	/**
38
	 * Find email addresses by query string
39
	 *
40
	 * @param string $userId
41
	 * @param string $query
42
	 * @return CollectedAddress[]
43
	 */
44 2
	public function findMatching($userId, $query) {
45 2
		$sql = 'SELECT * FROM *PREFIX*mail_collected_addresses WHERE `user_id` = ? AND `email` ILIKE ?';
46
		$params = [
47 2
			$userId,
48 2
			'%' . $query . '%',
49 2
		];
50 2
		return $this->findEntities($sql, $params);
51
	}
52
53 2
	public function exists($userId, $email) {
54 2
		$sql = 'SELECT * FROM *PREFIX*mail_collected_addresses WHERE `user_id` = ? AND `email` ILIKE ?';
55
		$params = [
56 2
			$userId,
57
			$email
58 2
		];
59 2
		return count($this->findEntities($sql, $params)) > 0;
60
	}
61
62
}
63