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 Illuminate\Database\QueryException; |
21
|
|
|
use Illuminate\Support\Facades\Auth; |
22
|
|
|
use Illuminate\Support\Facades\Redirect; |
23
|
|
|
use Illuminate\Support\Facades\Request; |
24
|
|
|
use Illuminate\Support\Facades\View; |
25
|
|
|
|
26
|
|
|
class GroupsController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Shows the project groups view. |
30
|
|
|
* |
31
|
|
|
* @return \Illuminate\View\View |
32
|
|
|
*/ |
33
|
|
|
public function indexAction() |
34
|
|
|
{ |
35
|
|
|
return View::make('groups.index') |
36
|
|
|
->withPageTitle(trans_choice('gitamin.groups.groups', 2).' - '.trans('dashboard.dashboard')) |
37
|
|
|
->withGroups(Group::get()) |
38
|
|
|
->withSubMenu($this->subMenu); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Shows the group view. |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\View\View |
45
|
|
|
*/ |
46
|
|
|
public function showAction($path) |
47
|
|
|
{ |
48
|
|
|
$group = Group::findByPath($path); |
49
|
|
|
|
50
|
|
|
return View::make('groups.show') |
51
|
|
|
->withPageTitle($group->name) |
|
|
|
|
52
|
|
|
->withGroup($group); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Shows the new project view. |
57
|
|
|
* |
58
|
|
|
* @return \Illuminate\View\View |
59
|
|
|
*/ |
60
|
|
|
public function newAction() |
61
|
|
|
{ |
62
|
|
|
return View::make('groups.new') |
63
|
|
|
->withPageTitle(trans('dashboard.groups.new.title').' - '.trans('dashboard.dashboard')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Creates a new project. |
68
|
|
|
* |
69
|
|
|
* @return \Illuminate\Http\RedirectResponse |
70
|
|
|
*/ |
71
|
|
|
public function createAction() |
72
|
|
|
{ |
73
|
|
|
$groupData = Request::get('group'); |
74
|
|
|
$groupData['type'] = 'group'; |
75
|
|
|
$groupData['user_id'] = Auth::user()->id; |
76
|
|
|
try { |
77
|
|
|
$group = $this->dispatchFromArray(AddOwnerCommand::class, $groupData); |
|
|
|
|
78
|
|
|
} catch (ValidationException $e) { |
79
|
|
|
return Redirect::route('groups.new') |
80
|
|
|
->withInput(Request::all()) |
81
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.add.failure'))) |
82
|
|
|
->withErrors($e->getMessageBag()); |
83
|
|
|
} catch (QueryException $e) { |
84
|
|
|
return Redirect::route('groups.new') |
85
|
|
|
->withInput(Request::all()) |
86
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.add.failure'))) |
87
|
|
|
->withErrors('Path has been used'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return Redirect::route('dashboard.groups.index') |
91
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.add.success'))); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Shows the edit project namespace view. |
96
|
|
|
* |
97
|
|
|
* @param \Gitamin\Models\Owner $namespace |
|
|
|
|
98
|
|
|
* |
99
|
|
|
* @return \Illuminate\View\View |
100
|
|
|
*/ |
101
|
|
|
public function editAction($path) |
102
|
|
|
{ |
103
|
|
|
$group = Group::findByPath($path); |
104
|
|
|
|
105
|
|
|
return View::make('groups.edit') |
106
|
|
|
->withPageTitle(trans('gitamin.groups.edit.title').' - '.trans('dashboard.dashboard')) |
107
|
|
|
->withGroup($group); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Updates a project namespace. |
112
|
|
|
* |
113
|
|
|
* @param \Gitamin\Models\Owner $namespace |
|
|
|
|
114
|
|
|
* |
115
|
|
|
* @return \Illuminate\Http\RedirectResponse |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
public function updateAction($path) |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
$groupData = Request::get('group'); |
120
|
|
|
$group = Owner::where('path', '=', $path)->first(); |
121
|
|
|
try { |
122
|
|
|
$groupData['owner'] = $group; |
123
|
|
|
$groupData['user_id'] = Auth::user()->id; |
124
|
|
|
$group = $this->dispatchFromArray(UpdateOwnerCommand::class, $groupData); |
125
|
|
|
} catch (ValidationException $e) { |
126
|
|
|
return Redirect::route('groups.group_edit', ['owner' => $group->path]) |
127
|
|
|
->withInput(Request::all()) |
128
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure'))) |
129
|
|
|
->withErrors($e->getMessageBag()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return Redirect::route('groups.group_edit', ['owner' => $group->path]) |
133
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success'))); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: