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\Providers; |
13
|
|
|
|
14
|
|
|
use Illuminate\Support\Collection; |
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
use Illuminate\View\View; |
17
|
|
|
use Tinyissue\Extensions\Auth\LoggedUser; |
18
|
|
|
use Tinyissue\Form\ExportIssues; |
19
|
|
|
use Tinyissue\Model\Project; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* ComposerServiceProvider is the view service provider binding data to specific views. |
23
|
|
|
* |
24
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ComposerServiceProvider extends ServiceProvider |
27
|
|
|
{ |
28
|
|
|
use LoggedUser; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Bootstrap any application services. |
32
|
|
|
*/ |
33
|
|
|
public function boot() |
34
|
|
|
{ |
35
|
|
|
// Load variable into project side bar template |
36
|
|
|
\View::composer('layouts/sidebar/project', function (View $view) { |
37
|
|
|
$this->loadExportIssuesForm($view); |
38
|
|
|
|
39
|
|
|
$this->loadProjectSideBarDefaultVariables($view->project, $view); |
40
|
|
|
}); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Load any variables that are default to project side bar. |
45
|
|
|
* |
46
|
|
|
* @param Project $project |
47
|
|
|
* @param View $view |
48
|
|
|
*/ |
49
|
|
|
protected function loadProjectSideBarDefaultVariables(Project $project, View $view) |
50
|
|
|
{ |
51
|
|
|
if (!$view->offsetExists('closed_issues_count')) { |
52
|
|
|
$view->with('closed_issues_count', $project->countClosedIssues($this->getLoggedUser())); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (!$view->offsetExists('open_issues_count')) { |
56
|
|
|
$view->with('open_issues_count', $project->countOpenIssues($this->getLoggedUser())); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!$view->offsetExists('project_users') || !$view->project_users instanceof Collection) { |
60
|
|
|
$view->with('project_users', $project->getUsers()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Add export form to project sidebar. |
66
|
|
|
* |
67
|
|
|
* @param View $view |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
protected function loadExportIssuesForm(View $view) |
72
|
|
|
{ |
73
|
|
|
$exportForm = new ExportIssues($this->app); |
74
|
|
|
$exportForm->setup(['project' => $view->project]); |
75
|
|
|
|
76
|
|
|
$view->with('exportForm', $exportForm); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Register any application services. |
81
|
|
|
*/ |
82
|
|
|
public function register() |
83
|
|
|
{ |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|