Completed
Pull Request — master (#1276)
by Thomas
04:23
created

CollectedAddressMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 2 Features 2
Metric Value
wmc 3
c 5
b 2
f 2
lcom 0
cbo 0
dl 0
loc 35
ccs 0
cts 14
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A exists() 0 8 1
A findMatching() 0 8 1
1
<?php
2
3
/**
4
 * ownCloud - Mail
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Christoph Wurst <[email protected]>
10
 * @copyright Christoph Wurst 2016
11
 */
12
13
namespace OCA\Mail\Db;
14
15
use OCP\AppFramework\Db\Mapper;
16
use OCP\IDb;
17
18
class CollectedAddressMapper extends Mapper {
19
20
	/**
21
	 * @param IDb $db
22
	 */
23
	public function __construct(IDb $db) {
24
		parent::__construct($db, 'mail_collected_addresses');
25
	}
26
27
	/**
28
	 * Find email addresses by query string
29
	 *
30
	 * @param string $userId
31
	 * @param string $query
32
	 * @return CollectedAddress[]
33
	 */
34
	public function findMatching($userId, $query) {
35
		$sql = 'SELECT * FROM *PREFIX*mail_collected_addresses WHERE `user_id` = ? AND `email` ILIKE ?';
36
		$params = [
37
			$userId,
38
			'%' . $query . '%',
39
		];
40
		return $this->findEntities($sql, $params);
41
	}
42
43
	public function exists($userId, $email) {
44
		$sql = 'SELECT * FROM *PREFIX*mail_collected_addresses WHERE `user_id` = ? AND `email` ILIKE ?';
45
		$params = [
46
			$userId,
47
			$email
48
		];
49
		return count($this->findEntities($sql, $params)) > 0;
50
	}
51
52
}
53