|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Tinyissue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
|
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 Tinyissue\Http\Controllers; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Http\Request; |
|
15
|
|
|
use Tinyissue\Form\Project as Form; |
|
16
|
|
|
use Tinyissue\Form\GlobalIssue as IssueForm; |
|
17
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
|
18
|
|
|
use Tinyissue\Model\Project; |
|
19
|
|
|
use Tinyissue\Model\User; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* ProjectsController is the controller class for managing request related to projects. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class ProjectsController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Display list of active/archived projects. |
|
30
|
|
|
* |
|
31
|
|
|
* @param int $status |
|
32
|
|
|
* |
|
33
|
|
|
* @return \Illuminate\View\View |
|
34
|
|
|
*/ |
|
35
|
5 |
|
public function getIndex($status = Project::STATUS_OPEN) |
|
36
|
|
|
{ |
|
37
|
5 |
|
$viewData = []; |
|
38
|
5 |
|
if (!$this->auth->guest()) { |
|
39
|
3 |
|
$projects = $this->auth->user()->projectsWithCountOpenIssues($status)->get(); |
|
|
|
|
|
|
40
|
3 |
|
if ($status) { |
|
41
|
3 |
|
$countActive = $projects->count(); |
|
42
|
3 |
|
$countArchived = $this->auth->user()->projectsWithCountOpenIssues(Project::STATUS_ARCHIVED)->count(); |
|
|
|
|
|
|
43
|
|
|
} else { |
|
44
|
2 |
|
$countActive = $this->auth->user()->projectsWithCountOpenIssues(Project::STATUS_OPEN)->count(); |
|
|
|
|
|
|
45
|
2 |
|
$countArchived = $projects->count(); |
|
46
|
|
|
} |
|
47
|
3 |
|
$viewData['projects'] = $this->auth->user()->projects()->get(); |
|
|
|
|
|
|
48
|
|
|
} else { |
|
49
|
2 |
|
$viewData['sidebar'] = 'public'; |
|
50
|
2 |
|
$project = new Project(); |
|
51
|
2 |
|
$projects = $project->projectsWithOpenIssuesCount($status, Project::PRIVATE_NO)->get(); |
|
52
|
2 |
|
if ($status) { |
|
53
|
2 |
|
$countActive = $projects->count(); |
|
54
|
2 |
|
$countArchived = $project->projectsWithOpenIssuesCount(Project::STATUS_ARCHIVED, Project::PRIVATE_NO)->count(); |
|
55
|
|
|
} else { |
|
56
|
|
|
$countActive = $project->projectsWithOpenIssuesCount(Project::STATUS_OPEN, Project::PRIVATE_NO)->count(); |
|
57
|
|
|
$countArchived = $projects->count(); |
|
58
|
|
|
} |
|
59
|
2 |
|
$user = new User(); |
|
60
|
2 |
|
$viewData['activeUsers'] = $user->activeUsers(); |
|
61
|
|
|
} |
|
62
|
5 |
|
$viewData['content_projects'] = $projects; |
|
63
|
5 |
|
$viewData['active'] = $status === Project::STATUS_OPEN ? 'active' : 'archived'; |
|
64
|
5 |
|
$viewData['active_count'] = $countActive; |
|
65
|
5 |
|
$viewData['archived_count'] = $countArchived; |
|
66
|
|
|
|
|
67
|
5 |
|
return view('projects.index', $viewData); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Add new project form. |
|
72
|
|
|
* |
|
73
|
|
|
* @param Form $form |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Illuminate\View\View |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function getNew(Form $form) |
|
78
|
|
|
{ |
|
79
|
1 |
|
return view('projects.new', [ |
|
|
|
|
|
|
80
|
1 |
|
'form' => $form, |
|
81
|
1 |
|
'projects' => $this->auth->user()->projects()->get(), |
|
|
|
|
|
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* To create a new project. |
|
87
|
|
|
* |
|
88
|
|
|
* @param Project $project |
|
89
|
|
|
* @param FormRequest\Project $request |
|
90
|
|
|
* |
|
91
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public function postNew(Project $project, FormRequest\Project $request) |
|
94
|
|
|
{ |
|
95
|
1 |
|
$project->createProject($request->all()); |
|
96
|
|
|
|
|
97
|
1 |
|
return redirect($project->to()); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Ajax: Calculate the progress of user projects. |
|
102
|
|
|
* |
|
103
|
|
|
* @param Request $request |
|
104
|
|
|
* @param Project $project |
|
105
|
|
|
* |
|
106
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function postProgress(Request $request, Project $project) |
|
109
|
|
|
{ |
|
110
|
|
|
// Get all projects with count of closed and opened issues |
|
111
|
1 |
|
$projects = $project->projectsWithCountIssues((array) $request->input('ids')); |
|
112
|
|
|
|
|
113
|
|
|
// The project progress Html and value |
|
114
|
1 |
|
$progress = $projects->transform(function (Project $project) { |
|
115
|
1 |
|
$progress = $project->getProgress(); |
|
116
|
1 |
|
$view = view('partials/progress', ['text' => $progress . '%', 'progress' => $progress])->render(); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
return [ |
|
119
|
1 |
|
'id' => $project->id, |
|
120
|
|
|
'progress' => [ |
|
121
|
1 |
|
'html' => $view, |
|
122
|
1 |
|
'value' => $progress, |
|
123
|
|
|
], |
|
124
|
|
|
]; |
|
125
|
1 |
|
})->lists('progress', 'id')->all(); |
|
126
|
|
|
|
|
127
|
1 |
|
return response()->json(['status' => true, 'progress' => $progress]); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Add new issue form. |
|
132
|
|
|
* |
|
133
|
|
|
* @param IssueForm $form |
|
134
|
|
|
* |
|
135
|
|
|
* @return \Illuminate\View\View |
|
136
|
|
|
*/ |
|
137
|
1 |
|
public function getNewIssue(IssueForm $form) |
|
138
|
|
|
{ |
|
139
|
1 |
|
return view('projects.new-issue', [ |
|
|
|
|
|
|
140
|
1 |
|
'form' => $form, |
|
141
|
1 |
|
'projects' => $this->auth->user()->projects()->get(), |
|
|
|
|
|
|
142
|
|
|
]); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* To create a new issue. |
|
147
|
|
|
* |
|
148
|
|
|
* @param Project\Issue $issue |
|
149
|
|
|
* @param FormRequest\GlobalIssue $request |
|
150
|
|
|
* |
|
151
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
152
|
|
|
*/ |
|
153
|
1 |
|
public function postNewIssue(Project\Issue $issue, FormRequest\GlobalIssue $request) |
|
154
|
|
|
{ |
|
155
|
1 |
|
$project = Project::find((int) $request->input('project')); |
|
156
|
|
|
|
|
157
|
1 |
|
$issue->setRelation('project', $project); |
|
158
|
1 |
|
$issue->setRelation('user', $this->auth->user()); |
|
159
|
1 |
|
$issue->createIssue([ |
|
160
|
1 |
|
'title' => $request->input('title'), |
|
161
|
1 |
|
'body' => $request->input('body'), |
|
162
|
1 |
|
'tag_type' => $request->input('tag_type'), |
|
163
|
1 |
|
'upload_token' => $request->input('upload_token'), |
|
164
|
1 |
|
'assigned_to' => (int) $project->default_assignee, |
|
165
|
1 |
|
'time_quote' => 0, |
|
166
|
|
|
]); |
|
167
|
|
|
|
|
168
|
1 |
|
return redirect($issue->to()) |
|
169
|
1 |
|
->with('notice', trans('tinyissue.issue_has_been_created')); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: