These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\UpdateOwnerCommand; |
||
17 | use Gitamin\Models\Group; |
||
18 | use Gitamin\Models\Owner; |
||
19 | use Gitamin\Models\Project; |
||
20 | use GrahamCampbell\Binput\Facades\Binput; |
||
21 | use Illuminate\Database\QueryException; |
||
22 | use Illuminate\Support\Facades\Auth; |
||
23 | use Illuminate\Support\Facades\Redirect; |
||
24 | use Illuminate\Support\Facades\View; |
||
25 | |||
26 | class GroupsController extends Controller |
||
27 | { |
||
28 | /** |
||
29 | * Array of sub-menu items. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $subMenu = []; |
||
34 | |||
35 | /** |
||
36 | * Creates a new project controller instance. |
||
37 | * |
||
38 | * @return void |
||
0 ignored issues
–
show
|
|||
39 | */ |
||
40 | View Code Duplication | public function __construct() |
|
41 | { |
||
42 | $this->subMenu = [ |
||
43 | 'projects' => [ |
||
44 | 'title' => trans('dashboard.projects.projects'), |
||
45 | 'url' => route('dashboard.projects.index'), |
||
46 | 'icon' => 'fa fa-sitemap', |
||
47 | 'active' => false, |
||
48 | ], |
||
49 | 'groups' => [ |
||
50 | 'title' => trans_choice('gitamin.groups.groups', 2), |
||
51 | 'url' => route('dashboard.groups.index'), |
||
52 | 'icon' => 'fa fa-folder', |
||
53 | 'active' => false, |
||
54 | ], |
||
55 | 'labels' => [ |
||
56 | 'title' => trans_choice('dashboard.projects.labels.labels', 2), |
||
57 | 'url' => route('dashboard.projects.index'), |
||
58 | 'icon' => 'fa fa-tags', |
||
59 | 'active' => false, |
||
60 | ], |
||
61 | ]; |
||
62 | |||
63 | View::share([ |
||
64 | 'sub_menu' => $this->subMenu, |
||
65 | 'sub_title' => trans_choice('dashboard.projects.projects', 2), |
||
66 | ]); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Shows the project groups view. |
||
71 | * |
||
72 | * @return \Illuminate\View\View |
||
73 | */ |
||
74 | View Code Duplication | public function indexAction() |
|
75 | { |
||
76 | $this->subMenu['groups']['active'] = true; |
||
77 | |||
78 | return View::make('groups.index') |
||
79 | ->withPageTitle(trans_choice('gitamin.groups.groups', 2).' - '.trans('dashboard.dashboard')) |
||
80 | ->withGroups(Group::get()) |
||
81 | ->withSubMenu($this->subMenu); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Shows the group view. |
||
86 | * |
||
87 | * @return \Illuminate\View\View |
||
88 | */ |
||
89 | public function showAction($path) |
||
90 | { |
||
91 | $group = Group::findByPath($path); |
||
92 | |||
93 | return View::make('groups.show') |
||
94 | ->withPageTitle($group->name) |
||
95 | ->withGroup($group); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Shows the new project view. |
||
100 | * |
||
101 | * @return \Illuminate\View\View |
||
102 | */ |
||
103 | public function newAction() |
||
104 | { |
||
105 | return View::make('groups.new') |
||
106 | ->withPageTitle(trans('dashboard.groups.new.title').' - '.trans('dashboard.dashboard')); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Creates a new project. |
||
111 | * |
||
112 | * @return \Illuminate\Http\RedirectResponse |
||
113 | */ |
||
114 | public function createAction() |
||
115 | { |
||
116 | $groupData = Binput::get('group'); |
||
117 | $groupData['type'] = 'group'; |
||
118 | $groupData['user_id'] = Auth::user()->id; |
||
119 | try { |
||
120 | $group = $this->dispatchFromArray(AddOwnerCommand::class, $groupData); |
||
121 | } catch (ValidationException $e) { |
||
122 | return Redirect::route('groups.new') |
||
123 | ->withInput(Binput::all()) |
||
124 | ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.add.failure'))) |
||
125 | ->withErrors($e->getMessageBag()); |
||
126 | } catch (QueryException $e) { |
||
127 | return Redirect::route('groups.new') |
||
128 | ->withInput(Binput::all()) |
||
129 | ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.add.failure'))) |
||
130 | ->withErrors('Path has been used'); |
||
131 | } |
||
132 | |||
133 | return Redirect::route('dashboard.groups.index') |
||
134 | ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.add.success'))); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Shows the edit project namespace view. |
||
139 | * |
||
140 | * @param \Gitamin\Models\Owner $namespace |
||
141 | * |
||
142 | * @return \Illuminate\View\View |
||
143 | */ |
||
144 | public function editAction($path) |
||
145 | { |
||
146 | $group = Group::findByPath($path); |
||
147 | |||
148 | return View::make('groups.edit') |
||
149 | ->withPageTitle(trans('gitamin.groups.edit.title').' - '.trans('dashboard.dashboard')) |
||
150 | ->withGroup($group); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Updates a project namespace. |
||
155 | * |
||
156 | * @param \Gitamin\Models\Owner $namespace |
||
157 | * |
||
158 | * @return \Illuminate\Http\RedirectResponse |
||
159 | */ |
||
160 | View Code Duplication | public function updateAction($path) |
|
161 | { |
||
162 | $groupData = Binput::get('group'); |
||
163 | $group = Owner::where('path', '=', $path)->first(); |
||
164 | try { |
||
165 | $groupData['owner'] = $group; |
||
166 | $groupData['user_id'] = Auth::user()->id; |
||
167 | $group = $this->dispatchFromArray(UpdateOwnerCommand::class, $groupData); |
||
168 | } catch (ValidationException $e) { |
||
169 | return Redirect::route('groups.group_edit', ['owner' => $group->path]) |
||
170 | ->withInput(Binput::all()) |
||
171 | ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure'))) |
||
172 | ->withErrors($e->getMessageBag()); |
||
173 | } |
||
174 | |||
175 | return Redirect::route('groups.group_edit', ['owner' => $group->path]) |
||
176 | ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success'))); |
||
177 | } |
||
178 | } |
||
179 |
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.