1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gitamin\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
7
|
|
|
use Illuminate\Support\Facades\Redirect; |
8
|
|
|
use Illuminate\Support\Facades\Auth; |
9
|
|
|
use Illuminate\Support\Facades\View; |
10
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
11
|
|
|
use AltThree\Validator\ValidationException; |
12
|
|
|
use Gitamin\Commands\Project\AddProjectCommand; |
13
|
|
|
use Gitamin\Commands\Project\RemoveProjectCommand; |
14
|
|
|
use Gitamin\Commands\Project\UpdateProjectCommand; |
15
|
|
|
use Gitamin\Models\Project; |
16
|
|
|
use Gitamin\Models\ProjectNamespace; |
17
|
|
|
use Gitamin\Models\Group; |
18
|
|
|
use Gitamin\Models\Tag; |
19
|
|
|
|
20
|
|
|
use Gitamin\Http\Controllers\Controller; |
21
|
|
|
|
22
|
|
|
class ProjectsController extends Controller |
23
|
|
|
{ |
24
|
|
|
use DispatchesJobs; |
25
|
|
|
/** |
26
|
|
|
* Display a listing of the resource. |
27
|
|
|
* |
28
|
|
|
* @return \Illuminate\Http\Response |
29
|
|
|
*/ |
30
|
|
|
public function index() |
31
|
|
|
{ |
32
|
|
|
// |
33
|
|
|
echo "In projects controller"; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Show the form or adding a new resource. |
38
|
|
|
* |
39
|
|
|
* return \Illuminate\Http\Response |
40
|
|
|
*/ |
41
|
|
|
public function new() |
42
|
|
|
{ |
43
|
|
|
return View::make('projects.new') |
44
|
|
|
->withPageTitle(trans('dashboard.projects.new.title').' - '.trans('dashboard.dashboard')) |
45
|
|
|
->withGroupId('') |
46
|
|
|
->withGroups(Group::Mine()->get()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Show the form for creating a new resource. |
51
|
|
|
* |
52
|
|
|
* @return \Illuminate\Http\Response |
53
|
|
|
*/ |
54
|
|
|
public function create() |
55
|
|
|
{ |
56
|
|
|
// |
57
|
|
|
$projectData = Binput::get('project'); |
58
|
|
|
$tags = array_pull($projectData, 'tags'); |
59
|
|
|
|
60
|
|
|
try { |
61
|
|
|
$projectData['creator_id'] = Auth::user()->id; |
62
|
|
|
$project = $this->dispatchFromArray(AddProjectCommand::class, $projectData); |
63
|
|
|
} catch (ValidationException $e) { |
64
|
|
|
return Redirect::route('projects.new') |
65
|
|
|
->withInput(Binput::all()) |
66
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.new.failure'))) |
67
|
|
|
->withErrors($e->getMessageBag()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// The project was added successfully, so now let's deal with the tags. |
71
|
|
|
$tags = preg_split('/ ?, ?/', $tags); |
72
|
|
|
|
73
|
|
|
// For every tag, do we need to create it? |
74
|
|
|
$projectTags = array_map(function ($taggable) use ($project) { |
75
|
|
|
return Tag::firstOrCreate(['name' => $taggable])->id; |
|
|
|
|
76
|
|
|
}, $tags); |
77
|
|
|
|
78
|
|
|
$project->tags()->sync($projectTags); |
79
|
|
|
|
80
|
|
|
return Redirect::route('dashboard.projects.index') |
81
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.new.success'))); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Display the specified resource. |
86
|
|
|
* |
87
|
|
|
* @param string $namespace |
88
|
|
|
* @param string $project_path |
89
|
|
|
* @return \Illuminate\Http\Response |
90
|
|
|
*/ |
91
|
|
|
public function show($namespace, $project_path) |
92
|
|
|
{ |
93
|
|
|
$project = Project::leftJoin('namespaces', function($join) { |
94
|
|
|
$join->on('projects.namespace_id', '=', 'namespaces.id'); |
95
|
|
|
})->where('projects.path', '=', $project_path)->where('namespaces.path', '=', $namespace)->first(['projects.*']); |
96
|
|
|
|
97
|
|
|
return View::make('projects.show') |
98
|
|
|
->withPageTitle($project->name) |
99
|
|
|
->withProject($project) |
100
|
|
|
->withRepo('') |
101
|
|
|
->withRepository('') |
102
|
|
|
->withCurrentBranch('master') |
103
|
|
|
->withBranches([]) |
104
|
|
|
->withParentPath('') |
105
|
|
|
->withFiles([]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Show the form for editing the specified resource. |
110
|
|
|
* |
111
|
|
|
* @param int $id |
|
|
|
|
112
|
|
|
* @return \Illuminate\Http\Response |
113
|
|
|
*/ |
114
|
|
|
public function edit($namespace, $project_path) |
115
|
|
|
{ |
116
|
|
|
$project = Project::leftJoin('namespaces', function($join) { |
117
|
|
|
$join->on('projects.namespace_id', '=', 'namespaces.id'); |
118
|
|
|
})->where('projects.path', '=', $project_path)->where('namespaces.path', '=', $namespace)->first(['projects.*']); |
119
|
|
|
|
120
|
|
|
return View::make('projects.edit') |
121
|
|
|
->withPageTitle(trans('dashboard.projects.new.title').' - '.trans('dashboard.dashboard')) |
122
|
|
|
->withProject($project) |
123
|
|
|
->withGroupId('') |
124
|
|
|
->withGroups(Group::all()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Update the specified resource in storage. |
129
|
|
|
* |
130
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
131
|
|
|
* @param int $id |
|
|
|
|
132
|
|
|
* @return \Illuminate\Http\Response |
133
|
|
|
*/ |
134
|
|
|
public function update($namespace, $project_path) |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
$projectData = Binput::get('project'); |
137
|
|
|
$tags = array_pull($projectData, 'tags'); |
138
|
|
|
$project = Project::find($projectData['id']); |
139
|
|
|
$projectData['namespace_id'] = $project->namespace_id; |
140
|
|
|
|
141
|
|
|
try { |
142
|
|
|
$projectData['project'] = $project; |
143
|
|
|
$project = $this->dispatchFromArray(UpdateProjectCommand::class, $projectData); |
144
|
|
|
} catch (ValidationException $e) { |
145
|
|
|
return Redirect::route('projects.project_edit', ['namespace' => $project->namespace, 'project' => $project->path]) |
146
|
|
|
->withInput(Binput::all()) |
147
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.edit.failure'))) |
148
|
|
|
->withErrors($e->getMessageBag()); |
149
|
|
|
} |
150
|
|
|
// The project was updated successfully, so now let's deal with the tags. |
151
|
|
|
$tags = preg_split('/ ?, ?/', $tags); |
|
|
|
|
152
|
|
|
|
153
|
|
|
return Redirect::route('projects.project_edit', ['namespace' => $project->namespace, 'project' => $project->path]) |
154
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.edit.success'))); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Remove the specified resource from storage. |
159
|
|
|
* |
160
|
|
|
* @param int $id |
161
|
|
|
* @return \Illuminate\Http\Response |
162
|
|
|
*/ |
163
|
|
|
public function destroy($id) |
|
|
|
|
164
|
|
|
{ |
165
|
|
|
// |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.