-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
152 lines (132 loc) · 5.95 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace OpinionManagement;
use MapasCulturais\App,
OpinionManagement\Controllers\OpinionManagement;
use MapasCulturais\Entities\Opportunity as OpportunityEntity;
use MapasCulturais\Entities\Registration;
/**
* @method part(string $string, array $args = [])
* @property mixed|null $controller
*/
class Plugin extends \MapasCulturais\Plugin
{
public function _init(): void
{
$app = (new App)->i();
// Load assets in head
$app->hook('template(<<registration|opportunity|panel>>.<<single|view|registrations|index>>.head):begin', function () use ($app) {
$app->view->enqueueScript(
'app',
'swal2',
'js/sweetalert2.all.min.js'
);
$app->view->enqueueStyle(
'app',
'swal2-theme-secultce',
'css/swal2-secultce.min.css'
);
$app->view->enqueueStyle(
'app',
'opinionManagement',
'OpinionManagement/css/opinionManagement.css'
);
$app->view->enqueueScript(
'app',
'opinion-management',
'OpinionManagement/js/opinionManagement.js'
);
});
$plugin = $this;
$app->hook('template(opportunity.edit.evaluations-config):begin', function () use ($app, $plugin) {
$opportunity = $this->controller->requestedEntity;
if($plugin::isEvaluationMethodValid($opportunity)) {
$this->part('OpinionManagement/selection-autopublish', ['opportunity' => $opportunity]);
}
});
$app->hook('template(opportunity.single.registration-list-header):end', function() use($app, $plugin) {
$opportunity = $this->controller->requestedEntity;
if($plugin::isEvaluationMethodValid($opportunity) && $opportunity->canUser('@control')) {
$this->part('OpinionManagement/admin-registrations-table-column.php');
$app->view->enqueueScript(
'app',
'opinion-management-tab-registrations',
'OpinionManagement/js/admin-tab-registrations.js'
);
$app->hook('template(opportunity.single.registration-list-item):end', function() {
$this->part('OpinionManagement/admin-btn-show-opinion.php');
});
}
});
$app->hook('template(opportunity.single.user-registration-table--registration--status):end', function ($registration, $opportunity) use ($app) {
if($opportunity->publishedOpinions === true && $registration->canUser('@control')) {
$this->part('OpinionManagement/user-btn-show-opinion.php', ['registration' => $registration]);
}
});
$app->hook('template(opportunity.single.opportunity-registrations--tables):begin', function () use ($app, $plugin) {
$opportunity = $this->controller->requestedEntity;
if($plugin::isEvaluationMethodValid($opportunity)
&& $opportunity->autopublishOpinions !== 'Sim'
&& !$opportunity->publishedOpinions
&& $opportunity->canUser('@control')//Verifica a gestão
) {
$this->part('OpinionManagement/admin-btn-publish-opinions.php', ['opportunity' => $opportunity]);
}
});
$app->hook('template(registration.view.header-fieldset):after', function() use($app, $plugin) {
$registration = $this->controller->requestedEntity;
$opportunity = $registration->opportunity;
if($plugin::isEvaluationMethodValid($opportunity)
&& $opportunity->publishedOpinions
&& $opportunity->canUser('@control')
) {
$this->part('OpinionManagement/user-btn-show-opinion.php');
}
});
$app->hook('template(panel.<<registrations|index>>.panel-registration):end', function (Registration $registration) use ($app,$plugin) {
if($registration->opportunity->publishedOpinions
&& $plugin::isEvaluationMethodValid($registration->opportunity)
) {
$this->part('OpinionManagement/user-btn-show-opinion.php', ['registration' => $registration]);
$app->view->enqueueScript(
'app',
'opinion-management',
'OpinionManagement/js/opinionManagement.js'
);
}
});
$app->hook('entity(Opportunity).publishRegistrations:before', function () {
if($this->autopublishOpinions === 'Sim') {
$this->setMetadata('publishedOpinions', true);
OpinionManagement::notificateUsers($this->id);
}
});
}
/**
* @throws \Exception
*/
public function register(): void
{
$app = (new App)->i();
$app->registerController('opinionManagement', OpinionManagement::class);
$this->registerOpportunityMetadata('autopublishOpinions', [
'type' => 'select',
'default_value' => 'Não',
'label' => \MapasCulturais\i::__('Publicar pareceres automaticamente'),
'description' => \MapasCulturais\i::__('Indica se os pareceres devem ser publicados automaticamente'),
'options' => ['Sim', 'Não'],
'required' => true,
]);
$this->registerOpportunityMetadata('publishedOpinions', [
'type' => 'boolean',
'label' => \MapasCulturais\i::__('Pareceres publicados'),
'default_value' => false,
'options' => [true, false],
'required' => true,
]);
}
public static function isEvaluationMethodValid(OpportunityEntity $opportunity): bool
{
return $opportunity->evaluationMethodConfiguration->type == 'documentary'
|| $opportunity->evaluationMethodConfiguration->type == 'technical';
}
}