Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AliasesService.php « Service « lib - github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c696556daae413c9afa8fcb59f00580b6fc7e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

declare(strict_types=1);

/**
 * @author Tahaa Karim <tahaalibra@gmail.com>
 *
 * Mail
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\Mail\Service;

use OCA\Mail\Db\Alias;
use OCA\Mail\Db\AliasMapper;

class AliasesService {

	/** @var AliasMapper */
	private $mapper;

	public function __construct(AliasMapper $mapper) {
		$this->mapper = $mapper;
	}

	/**
	 * @param int $accountId
	 * @param String $currentUserId
	 * @return Alias[]
	 */
	public function findAll(int $accountId, string $currentUserId): array {
		return $this->mapper->findAll($accountId, $currentUserId);
	}

	/**
	 * @param int $aliasId
	 * @param string $currentUserId
	 * @return Alias
	 */
	public function find(int $aliasId, string $currentUserId): Alias {
		return $this->mapper->find($aliasId, $currentUserId);
	}

	/**
	 * @param int $accountId
	 * @param string $alias
	 * @param string $aliasName
	 * @return Alias
	 */
	public function create(int $accountId, string $alias, string $aliasName) {
		$aliasEntity = new Alias();
		$aliasEntity->setAccountId($accountId);
		$aliasEntity->setAlias($alias);
		$aliasEntity->setName($aliasName);
		return $this->mapper->insert($aliasEntity);
	}

	/**
	 * @param int $aliasId
	 * @param String $currentUserId
	 * @return Alias
	 */
	public function delete(int $aliasId, string $currentUserId): Alias {
		$alias = $this->mapper->find($aliasId, $currentUserId);
		$this->mapper->delete($alias);
		return $alias;
	}

	/**
	 * Deletes all aliases of an account.
	 * @param int $accountId the account which aliases will be deleted
	 * @param string $currentUserId the user whom the account belongs to
	 */
	public function deleteAll($accountId, $currentUserId) {
		$this->mapper->deleteAll($accountId, $currentUserId);
	}
}