-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
60 lines (48 loc) · 1.97 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
<?php
namespace EditOpportunityType;
use EditOpportunityType\Controllers\EditOpportunityType;
use MapasCulturais\App;
class Plugin extends \MapasCulturais\Plugin
{
function _init()
{
$app = App::i();
$app->hook('template(opportunity.edit.evaluations-config):begin', function () use($app) {
/**
* @var $opportunity MapasCulturais\Entities\Opportunity
*/
$opportunity = $this->data['entity'];
if(
$opportunity->evaluationMethodConfiguration->getType()->id !== 'documentary'
|| !$opportunity->canUser('@control')
|| $opportunity->publishedRegistrations
) {
return;
}
$queryResult = $app->em
->createQuery('SELECT DISTINCT emc._type FROM MapasCulturais\Entities\EvaluationMethodConfiguration emc')
->getArrayResult();
$opportunityTypes = array_map(function ($row) use ($app) {
$evaluationMethods = $app->getRegisteredEvaluationMethodBySlug($row['_type']);
return [$evaluationMethods->slug, $evaluationMethods->name];
}, $queryResult);
$currentType = $opportunity->evaluationMethodConfiguration->getType();
$opportunityId = $opportunity->id;
$app->view->enqueueStyle('app', 'editOpportunityType', 'EditOpportunityType/css/main.css');
$app->view->part('select-opportunity-type', [
'opportunityTypes' => $opportunityTypes,
'currentType' => $currentType,
'opportunityId' => $opportunityId,
]);
$app->view->enqueueScript('app', 'editOpportunityType', 'EditOpportunityType/js/editOpportunityType.js');
});
}
/**
* @throws \Exception
*/
function register()
{
$app = App::i();
$app->registerController('alterar-tipo-de-oportunidade', EditOpportunityType::class);
}
}