|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Deck\Service; |
|
25
|
|
|
|
|
26
|
|
|
use OCA\Deck\Db\Label; |
|
27
|
|
|
use OCA\Deck\Db\Acl; |
|
28
|
|
|
use OCA\Deck\Db\LabelMapper; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
class LabelService { |
|
32
|
|
|
|
|
33
|
|
|
private $labelMapper; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService) { |
|
36
|
|
|
$this->labelMapper = $labelMapper; |
|
37
|
|
|
$this->permissionService = $permissionService; |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function find($labelId) { |
|
41
|
|
|
$this->permissionService->checkPermission($this->labelMapper, $labelId, Acl::PERMISSION_READ); |
|
42
|
|
|
return $this->labelMapper->find($labelId); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
public function create($title, $color, $boardId) { |
|
|
|
|
|
|
46
|
|
|
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE); |
|
47
|
|
|
$label = new Label(); |
|
48
|
|
|
$label->setTitle($title); |
|
49
|
|
|
$label->setColor($color); |
|
50
|
|
|
$label->setBoardId($boardId); |
|
51
|
|
|
return $this->labelMapper->insert($label); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function delete($id) { |
|
55
|
|
|
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE); |
|
56
|
|
|
return $this->labelMapper->delete($this->find($id)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function update($id, $title, $color) { |
|
60
|
|
|
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE); |
|
61
|
|
|
$label = $this->find($id); |
|
62
|
|
|
$label->setTitle($title); |
|
63
|
|
|
$label->setColor($color); |
|
64
|
|
|
return $this->labelMapper->update($label); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: