| 1 | <?php |
||
| 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 | 3 | } 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 | 3 | } 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 | 2 | } 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 | 1 | ]); |
|
| 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 | 1 | { |
|
| 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(); |
|
|
1 ignored issue
–
show
|
|||
| 117 | |||
| 118 | return [ |
||
| 119 | 1 | 'id' => $project->id, |
|
| 120 | 'progress' => [ |
||
| 121 | 1 | 'html' => $view, |
|
| 122 | 1 | 'value' => $progress, |
|
| 123 | 1 | ], |
|
| 124 | 1 | ]; |
|
| 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 | 1 | ]); |
|
| 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) |
|
| 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: