Completed
Push — master ( 7a51c1...7a51c1 )
by Maxence
04:21 queued 02:15
created

CirclesController::convertTypeStringToBitValue()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 6
eloc 11
nc 6
nop 1
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Controller;
28
29
use OCA\Circles\Exceptions\CircleDoesNotExistException;
30
use OCA\Circles\Exceptions\CircleTypeDisabledException;
31
use OCA\Circles\Model\Circle;
32
use OCA\Circles\Model\Member;
33
use OCP\AppFramework\Http\DataResponse;
34
35
class CirclesController extends BaseController {
36
37
	/**
38
	 * @NoAdminRequired
39
	 * @NoSubAdminRequired
40
	 *
41
	 * @param $type
42
	 * @param string $name
43
	 *
44
	 * @return DataResponse
45
	 */
46
	public function create($type, $name) {
47
48
		if (substr($name, 0, 1) === '_') {
49
			$error = "The name of your circle cannot start with this character";
50
		} else {
51
52
			try {
53
				$data = $this->circlesService->createCircle($type, $name);
54
55
				return $this->success(['name' => $name, 'circle' => $data, 'type' => $type]);
56
			} catch (\Exception $e) {
57
				$error = $e->getMessage();
58
			}
59
		}
60
61
		return $this->fail(['type' => $type, 'name' => $name, 'error' => $error]);
62
	}
63
64
65
	/**
66
	 * @NoAdminRequired
67
	 * @NoSubAdminRequired
68
	 *
69
	 * @param $type
70
	 * @param string $name
71
	 *
72
	 * @return DataResponse
73
	 */
74
	public function listing($type, $name = '') {
75
76
		try {
77
			$data = $this->circlesService->listCircles($type, $name, Member::LEVEL_NONE);
78
79
			return $this->success(['type' => $type, 'data' => $data]);
80
		} catch (CircleTypeDisabledException $e) {
81
82
			return $this->fail(['type' => $type, 'error' => $e->getMessage()]);
83
		}
84
	}
85
86
87
	/**
88
	 * @NoAdminRequired
89
	 * @NoSubAdminRequired
90
	 *
91
	 * @param $id
92
	 *
93
	 * @return DataResponse
94
	 * @internal param string $name
95
	 *
96
	 */
97 View Code Duplication
	public function details($id) {
98
		try {
99
			$data = $this->circlesService->detailsCircle($id);
100
101
			return $this->success(['circle_id' => $id, 'details' => $data]);
102
		} catch (\Exception $e) {
103
104
			return $this->fail(['circle_id' => $id, 'error' => $e->getMessage()]);
105
		}
106
107
	}
108
109
110
	/**
111
	 * @NoAdminRequired
112
	 * @NoSubAdminRequired
113
	 *
114
	 * @param $id
115
	 *
116
	 * @return DataResponse
117
	 * @internal param string $name
118
	 *
119
	 */
120 View Code Duplication
	public function join($id) {
121
		try {
122
			$data = $this->circlesService->joinCircle($id);
123
124
			return $this->success(['circle_id' => $id, 'member' => $data]);
125
		} catch (\Exception $e) {
126
127
			return $this->fail(['circle_id' => $id, 'error' => $e->getMessage()]);
128
		}
129
	}
130
131
132
	/**
133
	 * @NoAdminRequired
134
	 * @NoSubAdminRequired
135
	 *
136
	 * @param $id
137
	 *
138
	 * @return DataResponse
139
	 * @internal param string $name
140
	 *
141
	 */
142 View Code Duplication
	public function leave($id) {
143
		try {
144
			$data = $this->circlesService->leaveCircle($id);
145
146
			return $this->success(['circle_id' => $id, 'member' => $data]);
147
		} catch (\Exception $e) {
148
149
			return $this->fail(['circle_id' => $id, 'error' => $e->getMessage()]);
150
		}
151
152
	}
153
154
155
156
}
157
158