1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* @author Christoph Wurst <[email protected]> |
6
|
|
|
* @author Lukas Reschke <[email protected]> |
7
|
|
|
* @author Thomas Müller <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Mail |
10
|
|
|
* |
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
13
|
|
|
* as published by the Free Software Foundation. |
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, version 3, |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\Mail\Db; |
26
|
|
|
|
27
|
|
|
use OCP\AppFramework\Db\Mapper; |
28
|
|
|
use OCP\IDb; |
29
|
|
|
|
30
|
|
|
class MailAccountMapper extends Mapper { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param IDb $db |
34
|
|
|
*/ |
35
|
2 |
|
public function __construct(IDb $db) { |
36
|
2 |
|
parent::__construct($db, 'mail_accounts'); |
37
|
2 |
|
} |
38
|
|
|
|
39
|
|
|
/** Finds an Mail Account by id |
40
|
|
|
* |
41
|
|
|
* @param int $userId |
42
|
|
|
* @param int $accountId |
43
|
|
|
* @return MailAccount |
44
|
|
|
*/ |
45
|
|
|
public function find($userId, $accountId) { |
46
|
|
|
$sql = 'SELECT * FROM `' . $this->getTableName() . '` WHERE user_id = ? and id = ?'; |
47
|
|
|
$params = [$userId, $accountId]; |
48
|
|
|
|
49
|
|
|
return $this->findEntity($sql, $params); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Finds all Mail Accounts by user id existing for this user |
54
|
|
|
* @param string $userId the id of the user that we want to find |
55
|
|
|
* @param $userId |
56
|
|
|
* @return MailAccount[] |
57
|
|
|
*/ |
58
|
|
|
public function findByUserId($userId) { |
59
|
|
|
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
60
|
|
|
$params = [$userId]; |
61
|
|
|
|
62
|
|
|
return $this->findEntities($sql, $params); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Saves an User Account into the database |
67
|
|
|
* @param MailAccount $account |
68
|
|
|
* @return MailAccount |
69
|
|
|
*/ |
70
|
1 |
|
public function save(MailAccount $account) { |
71
|
1 |
|
if (is_null($account->getId())) { |
72
|
1 |
|
return $this->insert($account); |
73
|
|
|
} else { |
74
|
|
|
$this->update($account); |
75
|
|
|
return $account; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|