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\ProjectNamespace\AddProjectNamespaceCommand; |
16
|
|
|
use Gitamin\Commands\ProjectNamespace\RemoveProjectNamespaceCommand; |
17
|
|
|
use Gitamin\Commands\ProjectNamespace\UpdateProjectNamespaceCommand; |
18
|
|
|
use Gitamin\Models\Project; |
19
|
|
|
use Gitamin\Models\ProjectNamespace; |
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
|
|
|
|
29
|
|
|
class GroupsController extends Controller |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Array of sub-menu items. |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $subMenu = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Creates a new project controller instance. |
40
|
|
|
* |
41
|
|
|
* @return void |
|
|
|
|
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
$this->subMenu = [ |
46
|
|
|
'projects' => [ |
47
|
|
|
'title' => trans('dashboard.projects.projects'), |
48
|
|
|
'url' => route('dashboard.projects.index'), |
49
|
|
|
'icon' => 'fa fa-sitemap', |
50
|
|
|
'active' => false, |
51
|
|
|
], |
52
|
|
|
'groups' => [ |
53
|
|
|
'title' => trans_choice('gitamin.groups.groups', 2), |
54
|
|
|
'url' => route('dashboard.groups.index'), |
55
|
|
|
'icon' => 'fa fa-folder', |
56
|
|
|
'active' => false, |
57
|
|
|
], |
58
|
|
|
'labels' => [ |
59
|
|
|
'title' => trans_choice('dashboard.projects.labels.labels', 2), |
60
|
|
|
'url' => route('dashboard.projects.index'), |
61
|
|
|
'icon' => 'fa fa-tags', |
62
|
|
|
'active' => false, |
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
View::share([ |
67
|
|
|
'sub_menu' => $this->subMenu, |
68
|
|
|
'sub_title' => trans_choice('dashboard.projects.projects', 2), |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Shows the project teams view. |
74
|
|
|
* |
75
|
|
|
* @return \Illuminate\View\View |
76
|
|
|
*/ |
77
|
|
|
public function index() |
78
|
|
|
{ |
79
|
|
|
$this->subMenu['groups']['active'] = true; |
80
|
|
|
|
81
|
|
|
return View::make('groups.index') |
82
|
|
|
->withPageTitle(trans_choice('gitamin.groups.groups', 2).' - '.trans('dashboard.dashboard')) |
83
|
|
|
->withGroups(Group::get()) |
84
|
|
|
->withSubMenu($this->subMenu); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function show($namespace) |
88
|
|
|
{ |
89
|
|
|
$group = Group::where('path', '=', $namespace)->first(); |
90
|
|
|
return View::make('groups.show') |
91
|
|
|
->withGroup($group); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Shows the add project view. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\View\View |
98
|
|
|
*/ |
99
|
|
|
public function new() |
100
|
|
|
{ |
101
|
|
|
return View::make('groups.new') |
102
|
|
|
->withPageTitle(trans('dashboard.groups.new.title').' - '.trans('dashboard.dashboard')); |
103
|
|
|
//->withGroups(ProjectNamespace::all()); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Creates a new project. |
109
|
|
|
* |
110
|
|
|
* @return \Illuminate\Http\RedirectResponse |
111
|
|
|
*/ |
112
|
|
|
public function create() |
113
|
|
|
{ |
114
|
|
|
$groupData = Binput::get('group'); |
115
|
|
|
$groupData['type'] = 'group'; |
116
|
|
|
$groupData['owner_id'] = Auth::user()->id; |
117
|
|
|
try { |
118
|
|
|
$group = $this->dispatchFromArray(AddProjectNamespaceCommand::class, $groupData); |
|
|
|
|
119
|
|
|
} catch (ValidationException $e) { |
120
|
|
|
return Redirect::route('groups.new') |
121
|
|
|
->withInput(Binput::all()) |
122
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.teams.add.failure'))) |
123
|
|
|
->withErrors($e->getMessageBag()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return Redirect::route('groups.index') |
127
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.teams.add.success'))); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Shows the edit project team view. |
132
|
|
|
* |
133
|
|
|
* @param \Gitamin\Models\ProjectTeam $team |
|
|
|
|
134
|
|
|
* |
135
|
|
|
* @return \Illuminate\View\View |
136
|
|
|
*/ |
137
|
|
|
public function edit($namespace) |
138
|
|
|
{ |
139
|
|
|
$group = Group::where('path', '=', $namespace)->first(); |
140
|
|
|
|
141
|
|
|
return View::make('groups.edit') |
142
|
|
|
->withPageTitle(trans('dashboard.teams.edit.title').' - '.trans('dashboard.dashboard')) |
143
|
|
|
->withGroup($group); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Updates a project team. |
150
|
|
|
* |
151
|
|
|
* @param \Gitamin\Models\ProjectTeam $team |
|
|
|
|
152
|
|
|
* |
153
|
|
|
* @return \Illuminate\Http\RedirectResponse |
154
|
|
|
*/ |
155
|
|
|
public function update($namespace) |
156
|
|
|
{ |
157
|
|
|
$groupData = Binput::get('group'); |
158
|
|
|
$group = ProjectNamespace::where('path', '=', $namespace)->first(); |
159
|
|
|
try { |
160
|
|
|
$groupData['project_namespace'] = $group; |
161
|
|
|
$groupData['owner_id'] = Auth::user()->id; |
162
|
|
|
$group = $this->dispatchFromArray(UpdateProjectNamespaceCommand::class, $groupData); |
163
|
|
|
} catch (ValidationException $e) { |
164
|
|
|
return Redirect::route('groups.group_edit', ['namespace' => $group->path]) |
165
|
|
|
->withInput(Binput::all()) |
166
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure'))) |
167
|
|
|
->withErrors($e->getMessageBag()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
return Redirect::route('groups.group_edit', ['namespace' => $group->path]) |
171
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success'))); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
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.