1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Mail app |
4
|
|
|
* |
5
|
|
|
* @author Sebastian Schmid |
6
|
|
|
* @copyright 2013 Sebastian Schmid [email protected] |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library 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 Lesser General Public |
19
|
|
|
* License along with this library. 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 MailAccountMapper extends Mapper { |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param IDb $db |
32
|
|
|
*/ |
33
|
2 |
|
public function __construct(IDb $db) { |
34
|
2 |
|
parent::__construct($db, 'mail_accounts'); |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** Finds an Mail Account by id |
38
|
|
|
* |
39
|
|
|
* @param int $userId |
40
|
|
|
* @param int $accountId |
41
|
|
|
* @return MailAccount |
42
|
|
|
*/ |
43
|
|
|
public function find($userId, $accountId) { |
44
|
|
|
$sql = 'SELECT * FROM `' . $this->getTableName() . '` WHERE user_id = ? and id = ?'; |
45
|
|
|
$params = [$userId, $accountId]; |
46
|
|
|
|
47
|
|
|
return $this->findEntity($sql, $params); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Finds all Mail Accounts by user id existing for this user |
52
|
|
|
* @param string $userId the id of the user that we want to find |
53
|
|
|
* @param $userId |
54
|
|
|
* @return MailAccount[] |
55
|
|
|
*/ |
56
|
|
|
public function findByUserId($userId) { |
57
|
|
|
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
58
|
|
|
$params = [$userId]; |
59
|
|
|
|
60
|
|
|
return $this->findEntities($sql, $params); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Saves an User Account into the database |
65
|
|
|
* @param MailAccount $account |
66
|
|
|
* @return MailAccount |
67
|
|
|
*/ |
68
|
1 |
|
public function save(MailAccount $account) { |
69
|
1 |
|
if (is_null($account->getId())) { |
70
|
1 |
|
return $this->insert($account); |
71
|
|
|
} else { |
72
|
|
|
$this->update($account); |
73
|
|
|
return $account; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|