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

AliasMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 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