Completed
Push — master ( 716c72...0a3015 )
by Christoph
09:06
created

AliasMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A find() 0 4 1
A findAll() 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 Tahaa Karim <[email protected]>
10
 * @copyright Tahaa Karim 2016
11
 */
12
13
namespace OCA\Mail\Db;
14
15
use OCP\AppFramework\Db\Mapper;
16
use OCP\IDb;
17
18
class AliasMapper extends Mapper {
19
20
	/**
21
	 * @param IDb $db
22
	 */
23
	public function __construct(IDb $db) {
24
		parent::__construct($db, 'mail_aliases');
25
	}
26
27
	/**
28
	 * @param int $aliasId
29
	 * @param string $currentUserId
30
	 * @return Alias[]
31
	 */
32
	public function find($aliasId, $currentUserId) {
33
		$sql = 'select *PREFIX*mail_aliases.* from *PREFIX*mail_aliases join *PREFIX*mail_accounts on oc_mail_aliases.account_id = oc_mail_accounts.id where *PREFIX*mail_accounts.user_id = ? and *PREFIX*mail_aliases.id=?';
34
		return $this->findEntity($sql, [$currentUserId, $aliasId]);
35
	}
36
37
	/**
38
	 * @param int $accountId
39
	 * @param string $currentUserId
40
	 * @return Alias[]
41
	 */
42
	public function findAll($accountId, $currentUserId) {
43
		$sql = 'select *PREFIX*mail_aliases.* from *PREFIX*mail_aliases join *PREFIX*mail_accounts on oc_mail_aliases.account_id = oc_mail_accounts.id where *PREFIX*mail_accounts.user_id = ? AND *PREFIX*mail_aliases.account_id=?';
44
		$params = [
45
			$currentUserId,
46
			$accountId
47
		];
48
		return $this->findEntities($sql, $params);
49
	}
50
}
51