|
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 Tinyissue\Form\Settings as FormSettings; |
|
15
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
|
16
|
|
|
use Tinyissue\Model\Project; |
|
17
|
|
|
use Tinyissue\Model\Settings; |
|
18
|
|
|
use Tinyissue\Model\Tag; |
|
19
|
|
|
use Tinyissue\Model\User; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* AdministrationController is the controller class for managing request related the application system admin |
|
23
|
|
|
* |
|
24
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class AdministrationController extends Controller |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Show general application stats |
|
30
|
|
|
* |
|
31
|
|
|
* @param Tag $tag |
|
32
|
|
|
* @param Project $project |
|
33
|
|
|
* @param User $user |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Illuminate\View\View |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function getIndex(Tag $tag, Project $project, User $user) |
|
38
|
|
|
{ |
|
39
|
1 |
|
return view('administration.index', [ |
|
40
|
1 |
|
'users' => $user->countUsers(), |
|
41
|
1 |
|
'active_projects' => $project->countOpenProjects(), |
|
42
|
1 |
|
'archived_projects' => $project->countArchivedProjects(), |
|
43
|
1 |
|
'open_issues' => $project->countOpenIssues(), |
|
44
|
1 |
|
'closed_issues' => $project->countClosedIssues(), |
|
45
|
1 |
|
'projects' => $this->auth->user()->projects()->get(), |
|
|
|
|
|
|
46
|
1 |
|
'tags' => $tag->count(), |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Add new tag page |
|
52
|
|
|
* |
|
53
|
|
|
* @param FormSettings $form |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Illuminate\View\View |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getSettings(FormSettings $form) |
|
58
|
|
|
{ |
|
59
|
|
|
return view('administration.settings', [ |
|
60
|
|
|
'form' => $form, |
|
61
|
|
|
'projects' => $this->auth->user()->projects()->get(), |
|
|
|
|
|
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* To create new tag |
|
67
|
|
|
* |
|
68
|
|
|
* @param Settings $settings |
|
69
|
|
|
* @param FormRequest\Settings $request |
|
70
|
|
|
* |
|
71
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
72
|
|
|
*/ |
|
73
|
|
|
public function postSettings(Settings $settings, FormRequest\Settings $request) |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
$settingsToSave = $request->except('_token'); |
|
76
|
|
|
|
|
77
|
|
|
foreach ($settingsToSave as $name => $value) { |
|
78
|
|
|
$settings = new Settings(); |
|
79
|
|
|
$setting = $settings->where('key', '=', $name)->first(); |
|
|
|
|
|
|
80
|
|
|
if ($setting) { |
|
81
|
|
|
$setting->value = $value; |
|
82
|
|
|
$setting->save(); |
|
83
|
|
|
} |
|
84
|
|
|
unset($settings, $setting); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return redirect('administration/settings')->with('notice', trans('tinyissue.settings_saved')); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
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: