Skip to content

Commit dd4e1c1

Browse files
committed
Rimuove il calcolo di srcset e size nelle immagini embeddate
Permette di escludere la produzione degli attributi srcset e size da configurazione Imposta un index plugin per il placeholder evento Permette di impostare il widget appuntamenti da programma
1 parent 1bf368b commit dd4e1c1

File tree

21 files changed

+1184
-154
lines changed

21 files changed

+1184
-154
lines changed

autoloads/openpabootstrapitaliaoperators.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -840,18 +840,20 @@ private static function getImageUrl($url)
840840
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . '/';
841841
$urlList['default'] = $baseUrl . $filter . $url;
842842

843-
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . ',w_{width}/';
844-
$urlList['dynamic'] = $baseUrl . $filter . $url;
845-
846-
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . ',w_480/';
847-
$urlList['small'] = $baseUrl . $filter . $url;
848-
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . ',w_2500/';
849-
$urlList['large'] = $baseUrl . $filter . $url;
850-
851-
$srcSetSmall = $urlList['small'] . ' 480w';
852-
$srcSetLarge = $urlList['large'] . ' 1000w';
853-
$urlList['data-srcset'] = "{$srcSetSmall},{$srcSetLarge}";
854-
$urlList['sizes'] = '(max-width: 600px) 480w, 1000w';
843+
if (OpenPAINI::variable('ImageSettings', 'UseSizeAndSrcSet', 'enabled') == 'enabled') {
844+
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . ',w_{width}/';
845+
$urlList['dynamic'] = $baseUrl . $filter . $url;
846+
847+
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . ',w_480/';
848+
$urlList['small'] = $baseUrl . $filter . $url;
849+
$filter = OpenPAINI::variable('ImageSettings', 'FlyImgDefaultFilter') . ',w_2500/';
850+
$urlList['large'] = $baseUrl . $filter . $url;
851+
852+
$srcSetSmall = $urlList['small'] . ' 480w';
853+
$srcSetLarge = $urlList['large'] . ' 1000w';
854+
$urlList['data-srcset'] = "{$srcSetSmall},{$srcSetLarge}";
855+
$urlList['sizes'] = '(max-width: 600px) 480w, 1000w';
856+
}
855857
}
856858

857859
return $urlList;

classes/bridge/StanzaDelCittadinoBooking.php

Lines changed: 134 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ class StanzaDelCittadinoBooking
66

77
const ENABLE_CACHE_KEY = 'sdc_booking_enabled';
88

9+
const CALENDAR_FILTER_CACHE_KEY = 'sdc_booking_calendar_filter';
10+
11+
const STORE_AS_APPLICATION_CACHE_KEY = 'sdc_booking_as_application';
12+
13+
private static $useDraft = false;
14+
915
private static $instance;
1016

11-
private function __construct(){}
17+
private function __construct()
18+
{
19+
}
1220

1321
public static function factory(): StanzaDelCittadinoBooking
1422
{
@@ -72,6 +80,11 @@ public function storeConfig(int $office, int $service, int $place, array $calend
7280
return false;
7381
}
7482

83+
public function getCalendar($id)
84+
{
85+
return StanzaDelCittadinoBridge::factory()->instanceNewClient()->getCalendar($id);
86+
}
87+
7588
public function getCalendars(int $service, int $office, int $place): array
7689
{
7790
$query = "SELECT calendars FROM ocbookingconfig WHERE service_id = $service AND office_id = $office AND place_id = $place";
@@ -96,7 +109,7 @@ public function getOffices(int $service): array
96109
$query = "SELECT office_id, json_agg(json_build_object('place', place_id, 'calendars', calendars)) as data FROM ocbookingconfig WHERE service_id = $service GROUP BY office_id";
97110
$rows = eZDB::instance()->arrayQuery($query);
98111
$offices = [];
99-
foreach ($rows as $row){
112+
foreach ($rows as $row) {
100113
$officeObject = eZContentObject::fetch((int)$row['office_id']);
101114
if ($officeObject instanceof eZContentObject) {
102115
$data = json_decode($row['data'], true);
@@ -115,7 +128,7 @@ public function getOffices(int $service): array
115128
],
116129
'calendars' => $datum['calendars'],
117130
];
118-
if (isset($dataMap['has_address'])){
131+
if (isset($dataMap['has_address'])) {
119132
/** @var eZGmapLocation $address */
120133
$address = $dataMap['has_address']->content();
121134
$place['address'] = [
@@ -211,9 +224,9 @@ public function getAvailabilities(array $calendars, string $month = null): array
211224
StanzaDelCittadinoClient::$processTimeout = 10;
212225
$client = StanzaDelCittadinoBridge::factory()->instanceNewClient();
213226
$currentMonth = date('Y-m');
214-
if (!$month || $month == $currentMonth){
227+
if (!$month || $month == $currentMonth) {
215228
$startDate = date('Y-m-d');
216-
}else{
229+
} else {
217230
$startDate = $month . '-01';
218231
}
219232
$startDateTime = DateTime::createFromFormat('Y-m-d', $startDate);
@@ -226,9 +239,15 @@ public function getAvailabilities(array $calendars, string $month = null): array
226239
if ($startDateTime instanceof DateTime) {
227240
$endDateTime = new DateTime(sprintf('last day of %s', $startDateTime->format('Y-m')));
228241
$response['to'] = $endDateTime->format('Y-m-d');
229-
$remoteAvailabilities = $client->getCalendarsAvailabilities($calendars, $startDate, $endDateTime->format('Y-m-d'));
230-
foreach ($remoteAvailabilities['data'] as $index => $availability){
231-
$availability['name'] = $locale->formatDate(DateTime::createFromFormat('Y-m-d', $availability['date'])->format('U'));
242+
$remoteAvailabilities = $client->getCalendarsAvailabilities(
243+
$calendars,
244+
$startDate,
245+
$endDateTime->format('Y-m-d')
246+
);
247+
foreach ($remoteAvailabilities['data'] as $index => $availability) {
248+
$availability['name'] = $locale->formatDate(
249+
DateTime::createFromFormat('Y-m-d', $availability['date'])->format('U')
250+
);
232251
$response['availabilities'][$index] = $availability;
233252
}
234253
}
@@ -241,7 +260,7 @@ public function getAvailabilities(array $calendars, string $month = null): array
241260
public function getAvailabilitiesByDay(array $calendars, string $day = null): array
242261
{
243262
$availabilities = [];
244-
if ($day){
263+
if ($day) {
245264
$client = StanzaDelCittadinoBridge::factory()->instanceNewClient();
246265
$response = $client->getCalendarsAvailabilities($calendars, $day);
247266
$availabilities = $response['data'];
@@ -250,17 +269,6 @@ public function getAvailabilitiesByDay(array $calendars, string $day = null): ar
250269
return $availabilities;
251270
}
252271

253-
// public static function deleteDraftMeeting($meetingId)
254-
// {
255-
// try{
256-
// StanzaDelCittadinoBridge::factory()
257-
// ->instanceNewClient()
258-
// ->request('DELETE', '/api/meetings/'.$meetingId);
259-
// }catch (Throwable $e){
260-
// eZDebug::writeError($e->getMessage(), __METHOD__);
261-
// }
262-
// }
263-
264272
/**
265273
* @param string $calendar
266274
* @param string $date
@@ -270,19 +278,95 @@ public function getAvailabilitiesByDay(array $calendars, string $day = null): ar
270278
* @return array
271279
* @throws Exception
272280
*/
273-
public function upsertDraftMeeting(string $calendar, string $date, string $opening_hour, string $slot, string $meetingId = null): array
281+
public function upsertDraftMeeting(StanzaDelCittadinoBookingDTO $dto): array
274282
{
275-
$data = [
276-
'calendar' => $calendar,
277-
'date' => $date,
278-
'opening_hour' => $opening_hour,
279-
'slot' => $slot,
280-
'meeting' => $meetingId,
283+
$client = StanzaDelCittadinoBridge::factory()->instanceNewClient();
284+
if (empty($dto->getUserToken())) {
285+
$authResponse = $client->request('POST', '/api/session-auth');
286+
$dto->setUserToken($authResponse['token']);
287+
}
288+
$client->setBearerToken($dto->getUserToken());
289+
$endpoint = '/it/meetings/new-draft';
290+
$payload = $dto->toMeetingDraft();
291+
$response = [
292+
'token' => $dto->getUserToken(),
293+
'payload' => $payload,
294+
'dto' => $dto,
295+
'endpoint' => $endpoint,
281296
];
282-
return StanzaDelCittadinoBridge::factory()
283-
->instanceNewClient()
284-
->request('POST', '/it/meetings/new-draft', $data);
285297

298+
if (!self::$useDraft){
299+
$response['data'] = null;
300+
return $response;
301+
}
302+
try {
303+
$response['data'] = $client->request('POST', $endpoint, $payload);
304+
}catch (Throwable $e){
305+
$response['error'] = $e->getMessage();
306+
}
307+
308+
return $response;
309+
}
310+
311+
public function bookMeeting(StanzaDelCittadinoBookingDTO $dto): array
312+
{
313+
return $this->isStoreMeetingAsApplication() ? $this->bookAsApplication($dto) : $this->bookAsMeeting($dto);
314+
}
315+
316+
private function bookAsApplication(StanzaDelCittadinoBookingDTO $dto): array
317+
{
318+
$client = StanzaDelCittadinoBridge::factory()->instanceNewClient();
319+
if (empty($dto->getUserToken())) {
320+
$authResponse = $client->request('POST', '/api/session-auth');
321+
$dto->setUserToken($authResponse['token']);
322+
}
323+
$client->setBearerToken($dto->getUserToken());
324+
$endpoint = '/api/applications';
325+
$payload = $dto->toApplicationPayload();
326+
$response = [
327+
'token' => $dto->getUserToken(),
328+
'payload' => $payload,
329+
'dto' => $dto,
330+
'endpoint' => $endpoint,
331+
];
332+
try {
333+
$response['data'] = $client->request('POST', $endpoint, $payload);
334+
}catch (Throwable $e){
335+
$response['error'] = $e->getMessage();
336+
}
337+
338+
return $response;
339+
}
340+
341+
private function bookAsMeeting(StanzaDelCittadinoBookingDTO $dto): array
342+
{
343+
$client = StanzaDelCittadinoBridge::factory()->instanceNewClient();
344+
if (empty($dto->getUserToken())) {
345+
$authResponse = $client->request('POST', '/api/session-auth');
346+
$dto->setUserToken($authResponse['token']);
347+
}
348+
$client->setBearerToken($dto->getUserToken());
349+
if (self::$useDraft) {
350+
$method = 'PUT';
351+
$endpoint = '/api/meetings/' . $dto->getMeetingId();
352+
}else{
353+
$method = 'POST';
354+
$endpoint = '/api/meetings';
355+
}
356+
$payload = $dto->toMeetingPayload();
357+
$response = [
358+
'token' => $dto->getUserToken(),
359+
'payload' => $payload,
360+
'dto' => $dto,
361+
'endpoint' => $endpoint,
362+
];
363+
try {
364+
$response['data'] = $client->request($method, $endpoint, $payload);
365+
}catch (Throwable $e){
366+
$response['error'] = $e->getMessage();
367+
}
368+
369+
return $response;
286370
}
287371

288372
public function getSteps(): array
@@ -348,4 +432,24 @@ public function getSteps(): array
348432
],
349433
];
350434
}
435+
436+
public function useCalendarFilter(): bool
437+
{
438+
return (bool)$this->getStorage(self::CALENDAR_FILTER_CACHE_KEY);
439+
}
440+
441+
public function setUseCalendarFilter($enable)
442+
{
443+
$this->setStorage(self::CALENDAR_FILTER_CACHE_KEY, (int)$enable);
444+
}
445+
446+
public function isStoreMeetingAsApplication(): bool
447+
{
448+
return (bool)$this->getStorage(self::STORE_AS_APPLICATION_CACHE_KEY);
449+
}
450+
451+
public function setStoreMeetingAsApplication($enable)
452+
{
453+
$this->setStorage(self::STORE_AS_APPLICATION_CACHE_KEY, (int)$enable);
454+
}
351455
}

0 commit comments

Comments
 (0)