Completed
Pull Request — master (#94)
by Maxence
02:28
created

BaseController::success()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
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 OC\AppFramework\Http;
30
use OCA\Circles\Service\CirclesService;
31
use OCA\Circles\Service\ConfigService;
32
use OCA\Circles\Service\FederatedService;
33
use OCA\Circles\Service\GroupsService;
34
use OCA\Circles\Service\MembersService;
35
36
use OCA\Circles\Service\MiscService;
37
use OCA\Circles\Service\SharesService;
38
use OCP\AppFramework\Controller;
39
use OCP\AppFramework\Http\DataResponse;
40
use OCP\IL10N;
41
use OCP\IRequest;
42
43
class BaseController extends Controller {
44
45
	/** @var string */
46
	protected $userId;
47
48
	/** @var IL10N */
49
	protected $l10n;
50
51
	/** @var ConfigService */
52
	protected $configService;
53
54
	/** @var CirclesService */
55
	protected $circlesService;
56
57
	/** @var MembersService */
58
	protected $membersService;
59
60
	/** @var GroupsService */
61
	protected $groupsService;
62
63
	/** @var SharesService */
64
	protected $sharesService;
65
66
	/** @var FederatedService */
67
	protected $federatedService;
68
69
	/** @var MiscService */
70
	protected $miscService;
71
72
73
	/**
74
	 * BaseController constructor.
75
	 *
76
	 * @param string $appName
77
	 * @param IRequest $request
78
	 * @param string $userId
79
	 * @param IL10N $l10n
80
	 * @param ConfigService $configService
81
	 * @param CirclesService $circlesService
82
	 * @param MembersService $membersService
83
	 * @param GroupsService $groupsService
84
	 * @param SharesService $sharesService
85
	 * @param FederatedService $federatedService
86
	 * @param MiscService $miscService
87
	 */
88
	public function __construct(
89
		$appName,
90
		IRequest $request,
91
		$userId,
92
		IL10N $l10n,
93
		ConfigService $configService,
94
		CirclesService $circlesService,
95
		MembersService $membersService,
96
		GroupsService $groupsService,
97
		SharesService $sharesService,
98
		FederatedService $federatedService,
99
		MiscService $miscService
100
	) {
101
		parent::__construct($appName, $request);
102
103
		$this->userId = $userId;
104
		$this->l10n = $l10n;
105
		$this->configService = $configService;
106
		$this->circlesService = $circlesService;
107
		$this->membersService = $membersService;
108
		$this->groupsService = $groupsService;
109
		$this->sharesService = $sharesService;
110
		$this->federatedService = $federatedService;
111
		$this->miscService = $miscService;
112
	}
113
114
	/**
115
	 * @param $data
116
	 *
117
	 * @return DataResponse
118
	 */
119
	protected function fail($data) {
120
		return new DataResponse(
121
			array_merge($data, array('status' => 0)),
122
			Http::STATUS_NON_AUTHORATIVE_INFORMATION
123
		);
124
	}
125
126
	/**
127
	 * @param $data
128
	 *
129
	 * @return DataResponse
130
	 */
131
	protected function success($data) {
132
		return new DataResponse(
133
			array_merge($data, array('status' => 1)),
134
			Http::STATUS_CREATED
135
		);
136
	}
137
138
}