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\Project\AddProjectCommand; |
16
|
|
|
use Gitamin\Commands\Project\UpdateProjectCommand; |
17
|
|
|
use Gitamin\Models\Group; |
18
|
|
|
use Gitamin\Models\Owner; |
19
|
|
|
use Gitamin\Models\Project; |
20
|
|
|
use Gitamin\Models\Tag; |
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 ProjectsController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Display a listing of the resource. |
30
|
|
|
* |
31
|
|
|
* @return \Illuminate\Http\Response |
32
|
|
|
*/ |
33
|
|
|
public function indexAction() |
34
|
|
|
{ |
35
|
|
|
// |
36
|
|
|
echo 'In projects controller'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Show the form or adding a new resource. |
41
|
|
|
* |
42
|
|
|
* return \Illuminate\Http\Response |
43
|
|
|
*/ |
44
|
|
|
public function newAction() |
45
|
|
|
{ |
46
|
|
|
return View::make('projects.new') |
47
|
|
|
->withPageTitle(trans('dashboard.projects.new.title').' - '.trans('dashboard.dashboard')) |
48
|
|
|
->withGroupId('') |
49
|
|
|
->withOwners(Owner::where('user_id', '=', Auth::user()->id)->get()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Show the form for creating a new resource. |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Http\Response |
56
|
|
|
*/ |
57
|
|
|
public function createAction() |
58
|
|
|
{ |
59
|
|
|
// |
60
|
|
|
$projectData = Request::get('project'); |
61
|
|
|
$tags = array_pull($projectData, 'tags'); |
62
|
|
|
|
63
|
|
|
try { |
64
|
|
|
$projectData['creator_id'] = Auth::user()->id; |
65
|
|
|
$project = $this->dispatchFromArray(AddProjectCommand::class, $projectData); |
66
|
|
|
} catch (ValidationException $e) { |
67
|
|
|
return Redirect::route('projects.new') |
68
|
|
|
->withInput(Request::all()) |
69
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.new.failure'))) |
70
|
|
|
->withErrors($e->getMessageBag()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// The project was added successfully, so now let's deal with the tags. |
74
|
|
|
$tags = preg_split('/ ?, ?/', $tags); |
75
|
|
|
|
76
|
|
|
// For every tag, do we need to create it? |
77
|
|
|
$projectTags = array_map(function ($taggable) use ($project) { |
78
|
|
|
return Tag::firstOrCreate(['name' => $taggable])->id; |
|
|
|
|
79
|
|
|
}, $tags); |
80
|
|
|
|
81
|
|
|
$project->tags()->sync($projectTags); |
82
|
|
|
|
83
|
|
|
return Redirect::route('dashboard.projects.index') |
84
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.new.success'))); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Display the specified resource. |
89
|
|
|
* |
90
|
|
|
* @param string $owner |
|
|
|
|
91
|
|
|
* @param string $project_path |
92
|
|
|
* |
93
|
|
|
* @return \Illuminate\Http\Response |
94
|
|
|
*/ |
95
|
|
|
public function showAction($owner_path, $project_path) |
96
|
|
|
{ |
97
|
|
|
$project = Project::findByPath($owner_path, $project_path); |
98
|
|
|
|
99
|
|
|
return View::make('projects.show') |
100
|
|
|
->withPageTitle($project->name) |
|
|
|
|
101
|
|
|
->withActiveItem('project_show') |
102
|
|
|
->withProject($project) |
103
|
|
|
->withRepo('') |
104
|
|
|
->withRepository('') |
105
|
|
|
->withCurrentBranch('master') |
106
|
|
|
->withBranches([]) |
107
|
|
|
->withParentPath('') |
108
|
|
|
->withFiles([]); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Show the form for editing the specified resource. |
113
|
|
|
* |
114
|
|
|
* @param string $owner_path |
115
|
|
|
* @param string $project_path |
116
|
|
|
* |
117
|
|
|
* @return \Illuminate\Http\Response |
118
|
|
|
*/ |
119
|
|
|
public function editAction($owner_path, $project_path) |
120
|
|
|
{ |
121
|
|
|
$project = Project::findByPath($owner_path, $project_path); |
122
|
|
|
|
123
|
|
|
return View::make('projects.edit') |
124
|
|
|
->withPageTitle(trans('dashboard.projects.edit.title').' - '.trans('dashboard.dashboard')) |
125
|
|
|
->withProject($project) |
126
|
|
|
->withGroupId('') |
127
|
|
|
->withActiveItem('project_edit') |
128
|
|
|
->withGroups(Group::all()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Update the specified resource in storage. |
133
|
|
|
* |
134
|
|
|
* @param string $owner_path |
135
|
|
|
* @param string $project_path |
136
|
|
|
* |
137
|
|
|
* @return \Illuminate\Http\Response |
138
|
|
|
*/ |
139
|
|
|
public function updateAction($owner_path, $project_path) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$projectData = Request::get('project'); |
142
|
|
|
$tags = array_pull($projectData, 'tags'); |
143
|
|
|
$project = Project::find($projectData['id']); |
144
|
|
|
$projectData['namespace_id'] = $project->namespace_id; |
145
|
|
|
|
146
|
|
|
try { |
147
|
|
|
$projectData['project'] = $project; |
148
|
|
|
$projectData['creator_id'] = Auth::user()->id; |
149
|
|
|
$projectData['owner_id'] = $project->owner->id; |
150
|
|
|
$project = $this->dispatchFromArray(UpdateProjectCommand::class, $projectData); |
151
|
|
|
} catch (ValidationException $e) { |
152
|
|
|
return Redirect::route('projects.project_edit', ['owner' => $project->owner_path, 'project' => $project->path]) |
153
|
|
|
->withInput(Request::all()) |
154
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.edit.failure'))) |
155
|
|
|
->withErrors($e->getMessageBag()); |
156
|
|
|
} |
157
|
|
|
// The project was updated successfully, so now let's deal with the tags. |
158
|
|
|
$tags = preg_split('/ ?, ?/', $tags); |
|
|
|
|
159
|
|
|
|
160
|
|
|
return Redirect::route('projects.project_edit', ['owner' => $project->owner_path, 'project' => $project->path]) |
161
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.edit.success'))); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
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.