forked from FeliciLab/plugin-PDFReport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
56 lines (47 loc) · 1.84 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
<?php
namespace PDFReport;
use MapasCulturais\App;
class Plugin extends \MapasCulturais\Plugin {
public function _init() {
// enqueue scripts and styles
// add hooks
$app = App::i();
//
$app->hook('template(opportunity.single.header-inscritos):end', function () use ($app) {
$app->view->enqueueScript('app', 'pdfreport', 'js/pdfreport.js');
$entity = $this->controller->requestedEntity;
$resource = false;
//VERIFICANDO SE TEM A INDICAÇÃO DE RECURSO
$isResource = array_key_exists('claimDisabled', $entity->metadata);
//SE HOUVER O CAMPO FAZ O FOREACH
if($isResource) {
foreach ($entity->metadata as $key => $value) {
//SE O CAMPO EXISTIR E TIVER RECURSO HABILITADO
if($key == 'claimDisabled' && $value == 0) {
$resource = true;
}
}
}
$this->part('reports/buttons-report',['resource' => $resource]);
});
$plugin = $this;
$app->hook('template(registration.view.header-fieldset):before', function () use ($app, $plugin) {
$app->view->enqueueStyle('app', 'pdfreport', 'css/styleButtonPrint.css');
$id = $this->data['entity']->id;
$plugin->showButtonPrint($id);
});
}
public function showButtonPrint($id)
{
$app = App::i();
$registration = $app->repo('Registration')->find($id);
if(!is_null($registration) && $registration->status <> 0) {
$app->view->part('reports/button-print', ['id' => $id]);
}
}
public function register() {
// register metadata, taxonomies
$app = App::i();
$app->registerController('pdf', 'PDFReport\Controllers\Pdf');
}
}