Skip to content

Commit 0f15486

Browse files
committed
refactor: ottimizzazione formato ICS
1 parent 7b23953 commit 0f15486

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

api/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ function serverError()
111111
// Impostazioni di Content-Type e Charset Header
112112
if (json_last_error() == JSON_ERROR_NONE) {
113113
header('Content-Type: application/json; charset=UTF-8');
114+
} elseif (get('resource') == 'sync') {
115+
header('Content-Type: text/calendar; charset=UTF-8');
114116
} else {
115117
header('Content-Type: text/plain; charset=UTF-8');
116118
}

modules/interventi/src/API/v1/Sync.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,30 @@ public function retrieve($request)
7474

7575
$result = '';
7676

77-
$result .= "BEGIN:VCALENDAR\n";
78-
$result .= "VERSION:2.0\n";
79-
$result .= "PRODID:-// OpenSTAManager\n";
77+
$result .= "BEGIN:VCALENDAR\r\n";
78+
$result .= "VERSION:2.0\r\n";
79+
$result .= "PRODID:-// OpenSTAManager\r\n";
8080

8181
foreach ($rs as $r) {
82-
$description = str_replace("\r\n", "\n", strip_tags((string) $r['description']));
82+
$description = str_replace("\r\n", "\n", strip_tags((string) $r['richiesta']));
8383
$description = str_replace("\r", "\n", $description);
84-
$description = str_replace("\n", '\\n', $description);
85-
86-
$r['summary'] = str_replace("\r\n", "\n", $r['summary']);
84+
$description = str_replace("\n", '\\r\\n', $description);
8785

8886
$now = new Carbon();
8987
$inizio = new Carbon($r['orario_inizio']);
9088
$fine = new Carbon($r['orario_fine']);
9189

92-
$result .= "BEGIN:VEVENT\n";
93-
$result .= 'UID:'.$r['idriga']."\n";
94-
$result .= 'DTSTAMP:'.$now->format('Ymd\THis')."\n";
95-
// $result .= 'ORGANIZER;CN='.$azienda.':MAILTO:'.$email."\n";
96-
$result .= 'DTSTART:'.$inizio->format('Ymd\THis')."\n";
97-
$result .= 'DTEND:'.$fine->format('Ymd\THis')."\n";
98-
$result .= 'SUMMARY:'.html_entity_decode($r['summary'])."\n";
99-
$result .= 'DESCRIPTION:'.html_entity_decode($description, ENT_QUOTES, 'UTF-8')."\n";
100-
$result .= "END:VEVENT\n";
90+
$result .= "BEGIN:VEVENT\r\n";
91+
$result .= 'UID:'.$r['idriga']."\r\n";
92+
$result .= 'DTSTAMP:'.$now->format('Ymd\THis')."\r\n";
93+
$result .= 'DTSTART:'.$inizio->format('Ymd\THis')."\r\n";
94+
$result .= 'DTEND:'.$fine->format('Ymd\THis')."\r\n";
95+
$result .= 'SUMMARY:'.html_entity_decode($r['summary'])."\r\n";
96+
$result .= 'DESCRIPTION:'.html_entity_decode($description, ENT_QUOTES, 'UTF-8')."\r\n";
97+
$result .= "END:VEVENT\r\n";
10198
}
10299

103-
$result .= "END:VCALENDAR\n";
100+
$result .= "END:VCALENDAR\r\n";
104101

105102
return [
106103
'custom' => $result,

0 commit comments

Comments
 (0)