-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTheme.php
More file actions
171 lines (140 loc) · 6.03 KB
/
Theme.php
File metadata and controls
171 lines (140 loc) · 6.03 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
namespace Funarte;
use MapasCulturais\App;
use MapasCulturais\API;
use MapasCulturais\Definitions;
use MapasCulturais\Entities\Agent;
// class Theme extends \Subsite\Theme {
class Theme extends \MapasCulturais\Themes\BaseV2\Theme
{
static function getThemeFolder()
{
return __DIR__;
}
function __construct($config = [])
{
$app = App::i();
$app->config['Metabase']['enabled'] = env('METABASE_FUNARTE_ENABLED', true);
parent::__construct($config);
$app->registerController('funarte_search', 'Funarte\SearchController');
$app->registerController('circuitos', 'Funarte\CircuitosController');
}
function register()
{
$app = App::i();
parent::register();
$def = new Definitions\Metadata('isFunarte', ['label' => 'É Funarte', 'type' => 'boolean']);
$app->registerMetadata($def, 'MapasCulturais\Entities\Agent');
}
function _init()
{
parent::_init();
$app = App::i();
// Definir isFunarte para todos os agentes do usuário ao fazer login
$app->hook('auth.login', function ($user) use ($app) {
if (!$user || $user->is('guest')) {
return;
}
$agents = $app->repo('Agent')->findBy(['user' => $user->id]);
foreach ($agents as $agent) {
if ($agent->isFunarte) {
continue;
}
$app->disableAccessControl();
$agent->isFunarte = true;
$agent->save(true);
$app->enableAccessControl();
}
});
$app->hook('template(<<*>>.head):end', function () {
$this->part('google-analytics--script');
$this->part('clarity--script');
});
$app->hook('template(<<*>>.<<*>>.body):begin', function(){
/** @var \MapasCulturais\Theme $this */
$this->part('glpi-form');
});
/**
* Validação do Captcha
*/
$app->hook('POST(site.valida-captcha)', function() use($app) {
$recaptcha_response = $_POST['g-recaptcha-response'] ?? '';
if (empty($recaptcha_response)) {
$this->json(['success' => false, 'error' => 'Captcha não fornecido. Tente novamente.']);
return;
}
// Usar a verificação nativa do App.php
if (!$app->verifyCaptcha($recaptcha_response)) {
$this->json(['success' => false, 'error' => 'Captcha inválido. Tente novamente.']);
return;
}
$this->json(['success' => true, 'message' => 'Captcha válido']);
});
/*
* Add custom navigation items to panel
*/
$app->hook("panel.nav", function (&$nav_items) use ($app) {
if (isset($nav_items["more"])) {
$i = $nav_items["more"]["items"];
// Use PHP array spread operator to prepend new item, then all previous items
$nav_items["more"]["items"] = [
[
"route" => "search/projects",
"icon" => "project",
"label" => "Listar Iniciativas",
],
...$i
];
}
});
/*
* correção para filtragem por estado/município na visualização de mapa
* substitui o método API_findByEvents para tratar corretamente os filtros En_Estado e En_Municipio
*/
$app->hook('API(space.findByEvents)', function() use ($app) {
$space_controller = $app->controller('space');
$query_data = $space_controller->getData;
$date_from = key_exists('@from', $query_data) ? $query_data['@from'] : date("Y-m-d");
$date_to = key_exists('@to', $query_data) ? $query_data['@to'] : $date_from;
unset(
$query_data['@from'],
$query_data['@to']
);
$event_data = ['@select' => 'id'] + $query_data;
unset($event_data['location']);
unset($event_data['_geoLocation']);
unset($event_data['@count']);
// remove En_Estado e En_Municipio do event_data pois devem ser aplicados aos espaços, não aos eventos
unset($event_data['En_Estado']);
unset($event_data['En_Municipio']);
$events_repo = $app->repo('Event');
$_event_ids = $events_repo->findByDateInterval($date_from, $date_to, null, null, true);
if (count($_event_ids) > 0) {
$event_data['id'] = 'IN(' . implode(',', $_event_ids) . ')';
$events = $app->controller('event')->apiQuery($event_data);
$event_ids = array_map(function ($e){ return $e['id']; }, $events);
$spaces = $space_controller->repository->findByEventsAndDateInterval($event_ids, $date_from, $date_to);
$space_ids = array_map(function($e){ return $e->id; }, $spaces);
if($space_ids){
$space_data = ['id' => 'IN(' . implode(',', $space_ids) .')'];
foreach($query_data as $key => $val)
if($key[0] === '@' || $key == '_geoLocation' || $key == 'location' || $key == 'En_Estado' || $key == 'En_Municipio')
$space_data[$key] = $val;
unset($space_data['@keyword']);
$response = $space_controller->apiQuery($space_data);
}else{
$response = key_exists('@count', $query_data) ? 0 : [];
}
} else {
$response = key_exists('@count', $query_data) ? 0 : [];
}
$this->json($response);
return false;
});
$app->hook("component(mc-icon).iconset", function(&$icon){
$icon['project'] = "ph:pinwheel-fill";
$icon['calendar'] = "bx:calendar";
$icon['map-marker'] = "mdi:map-marker";
});
}
}