1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers; |
13
|
|
|
|
14
|
|
|
use AltThree\Validator\ValidationException; |
15
|
|
|
use Gitamin\Commands\Owner\AddOwnerCommand; |
16
|
|
|
use Gitamin\Commands\Owner\RemoveOwnerCommand; |
17
|
|
|
use Gitamin\Commands\Owner\UpdateOwnerCommand; |
18
|
|
|
use Gitamin\Models\Project; |
19
|
|
|
use Gitamin\Models\Owner; |
20
|
|
|
use Gitamin\Models\Group; |
21
|
|
|
use Gitamin\Models\Tag; |
22
|
|
|
use Gitamin\Http\Controllers\Controller; |
23
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
24
|
|
|
use Illuminate\Support\Facades\Redirect; |
25
|
|
|
use Illuminate\Support\Facades\Auth; |
26
|
|
|
use Illuminate\Support\Facades\View; |
27
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
28
|
|
|
use Illuminate\Database\QueryException; |
29
|
|
|
|
30
|
|
|
class GroupsController extends Controller |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Array of sub-menu items. |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $subMenu = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Creates a new project controller instance. |
41
|
|
|
* |
42
|
|
|
* @return void |
|
|
|
|
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->subMenu = [ |
47
|
|
|
'projects' => [ |
48
|
|
|
'title' => trans('dashboard.projects.projects'), |
49
|
|
|
'url' => route('dashboard.projects.index'), |
50
|
|
|
'icon' => 'fa fa-sitemap', |
51
|
|
|
'active' => false, |
52
|
|
|
], |
53
|
|
|
'groups' => [ |
54
|
|
|
'title' => trans_choice('gitamin.groups.groups', 2), |
55
|
|
|
'url' => route('dashboard.groups.index'), |
56
|
|
|
'icon' => 'fa fa-folder', |
57
|
|
|
'active' => false, |
58
|
|
|
], |
59
|
|
|
'labels' => [ |
60
|
|
|
'title' => trans_choice('dashboard.projects.labels.labels', 2), |
61
|
|
|
'url' => route('dashboard.projects.index'), |
62
|
|
|
'icon' => 'fa fa-tags', |
63
|
|
|
'active' => false, |
64
|
|
|
], |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
View::share([ |
68
|
|
|
'sub_menu' => $this->subMenu, |
69
|
|
|
'sub_title' => trans_choice('dashboard.projects.projects', 2), |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Shows the project teams view. |
75
|
|
|
* |
76
|
|
|
* @return \Illuminate\View\View |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
public function indexAction() |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$this->subMenu['groups']['active'] = true; |
81
|
|
|
|
82
|
|
|
return View::make('groups.index') |
83
|
|
|
->withPageTitle(trans_choice('gitamin.groups.groups', 2).' - '.trans('dashboard.dashboard')) |
84
|
|
|
->withGroups(Group::get()) |
85
|
|
|
->withSubMenu($this->subMenu); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Shows the group view. |
90
|
|
|
* |
91
|
|
|
* @return \Illuminate\View\View |
92
|
|
|
*/ |
93
|
|
|
public function showAction($path) |
94
|
|
|
{ |
95
|
|
|
$group = Group::where('path', '=', $path)->first(); |
96
|
|
|
return View::make('groups.show') |
97
|
|
|
->withPageTitle($group->name) |
98
|
|
|
->withGroup($group); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Shows the new project view. |
103
|
|
|
* |
104
|
|
|
* @return \Illuminate\View\View |
105
|
|
|
*/ |
106
|
|
|
public function newAction() |
107
|
|
|
{ |
108
|
|
|
return View::make('groups.new') |
109
|
|
|
->withPageTitle(trans('dashboard.groups.new.title').' - '.trans('dashboard.dashboard')); |
110
|
|
|
//->withGroups(ProjectNamespace::all()); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Creates a new project. |
115
|
|
|
* |
116
|
|
|
* @return \Illuminate\Http\RedirectResponse |
117
|
|
|
*/ |
118
|
|
|
public function createAction() |
119
|
|
|
{ |
120
|
|
|
$groupData = Binput::get('group'); |
121
|
|
|
$groupData['type'] = 'group'; |
122
|
|
|
$groupData['user_id'] = Auth::user()->id; |
123
|
|
|
try { |
124
|
|
|
$group = $this->dispatchFromArray(AddOwnerCommand::class, $groupData); |
|
|
|
|
125
|
|
|
} catch (ValidationException $e) { |
126
|
|
|
return Redirect::route('groups.new') |
127
|
|
|
->withInput(Binput::all()) |
128
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.teams.add.failure'))) |
129
|
|
|
->withErrors($e->getMessageBag()); |
130
|
|
|
} catch (QueryException $e) { |
131
|
|
|
return Redirect::route('groups.new') |
132
|
|
|
->withInput(Binput::all()) |
133
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.teams.add.failure'))) |
134
|
|
|
->withErrors('Path has been used'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return Redirect::route('dashboard.groups.index') |
138
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.teams.add.success'))); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Shows the edit project namespace view. |
143
|
|
|
* |
144
|
|
|
* @param \Gitamin\Models\ProjectNamespace $namespace |
|
|
|
|
145
|
|
|
* |
146
|
|
|
* @return \Illuminate\View\View |
147
|
|
|
*/ |
148
|
|
|
public function editAction($path) |
149
|
|
|
{ |
150
|
|
|
$group = Group::where('path', '=', $path)->first(); |
151
|
|
|
|
152
|
|
|
return View::make('groups.edit') |
153
|
|
|
->withPageTitle(trans('dashboard.teams.edit.title').' - '.trans('dashboard.dashboard')) |
154
|
|
|
->withGroup($group); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Updates a project namespace. |
159
|
|
|
* |
160
|
|
|
* @param \Gitamin\Models\ProjectNamespace $namespace |
|
|
|
|
161
|
|
|
* |
162
|
|
|
* @return \Illuminate\Http\RedirectResponse |
163
|
|
|
*/ |
164
|
|
|
public function updateAction($path) |
165
|
|
|
{ |
166
|
|
|
$groupData = Binput::get('group'); |
167
|
|
|
$group = Owner::where('path', '=', $path)->first(); |
168
|
|
|
try { |
169
|
|
|
$groupData['owner'] = $group; |
170
|
|
|
$groupData['owner_id'] = Auth::user()->id; |
171
|
|
|
$group = $this->dispatchFromArray(UpdateOwnerCommand::class, $groupData); |
172
|
|
|
} catch (ValidationException $e) { |
173
|
|
|
return Redirect::route('groups.group_edit', ['owner' => $group->path]) |
174
|
|
|
->withInput(Binput::all()) |
175
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure'))) |
176
|
|
|
->withErrors($e->getMessageBag()); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return Redirect::route('groups.group_edit', ['owner' => $group->path]) |
180
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success'))); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.