Skip to content

Commit

Permalink
allow write widerregion calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed May 9, 2022
1 parent 0853363 commit 7395ef4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 8 deletions.
25 changes: 20 additions & 5 deletions LitCalNationalAndRegionalData.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,38 @@ private function retrieveNationalCalendar() {
}

private function writeNationalCalendar() {
if( !property_exists( $this->DATA, 'LitCal' ) || !property_exists( $this->DATA, 'Metadata' ) || !property_exists( $this->DATA, 'Settings' ) ) {
header( $_SERVER[ "SERVER_PROTOCOL" ]." 400 Bad request", true, 400 );
die( '{"error":"Not all required parameters were received (LitCal, Metadata, Settings)"}' );
} else {
if( property_exists( $this->DATA, 'LitCal' ) && property_exists( $this->DATA, 'Metadata' ) && property_exists( $this->DATA, 'Settings' ) ) {
$region = $this->DATA->Metadata->Region;
if( $region === 'UNITED STATES' ) {
$region = 'USA';
}
$path = "nations/{$region}";
if( !file_exists( $path ) ){
if( !file_exists( $path ) ) {
mkdir( $path, 0755, true );
}
$data = json_encode( $this->DATA, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE );
file_put_contents( $path . "/{$region}.json", $data . PHP_EOL );
header( $_SERVER[ "SERVER_PROTOCOL" ]." 201 Created", true, 201 );
die( '{"success":"National calendar created or updated for nation \"'. $this->DATA->Metadata->Region .'\""}' );
}
else if ( property_exists( $this->DATA, 'LitCal' ) && property_exists( $this->DATA, 'Metadata' ) && property_exists( $this->DATA, 'NationalCalendars' ) ) {
$this->DATA->Metadata->WiderRegion = ucfirst( strtolower( $this->DATA->Metadata->WiderRegion ) );
$widerRegion = strtoupper( $this->DATA->Metadata->WiderRegion );
if( $this->DATA->Metadata->IsMultilingual === true ) {
$path = "nations/{$widerRegion}";
if( !file_exists( $path ) ) {
mkdir( $path, 0755, true );
}
}
$data = json_encode( $this->DATA, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE );
file_put_contents( "nations/{$this->DATA->Metadata->WiderRegion}.json", $data . PHP_EOL );
header( $_SERVER[ "SERVER_PROTOCOL" ]." 201 Created", true, 201 );
die( '{"success":"Wider region calendar created or updated for region \"'. $this->DATA->Metadata->WiderRegion .'\""}' );
}
else {
header( $_SERVER[ "SERVER_PROTOCOL" ]." 400 Bad request", true, 400 );
die( '{"error":"Not all required parameters were received (LitCal, Metadata, Settings)"}' );
}
}

private function deleteNationalCalendar() {
Expand Down
39 changes: 39 additions & 0 deletions nations/Americas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"LitCal": [
{
"Festivity": {
"tag": "LadyGuadalupe",
"name": "Our Lady of Guadalupe",
"color": [
"white"
],
"grade": 4,
"day": 12,
"month": 12
},
"Metadata": {
"action": "makePatron",
"sinceYear": 1999,
"decreeURL": "https:\/\/www.vatican.va\/content\/john-paul-ii\/%s\/homilies\/1999\/documents\/hf_jp-ii_hom_19990123_mexico-guadalupe.html",
"decreeLangs": {
"DE": "de",
"ES": "es",
"EN": "en",
"FR": "fr",
"IT": "it",
"PT": "pt"
}
}
}
],
"NationalCalendars": {},
"Metadata": {
"IsMultilingual": true,
"Languages": [
"en",
"es",
"pt"
],
"WiderRegion": "Americas"
}
}
35 changes: 33 additions & 2 deletions nations/Europe.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"FRANCE": "FR",
"GERMANY": "DE",
"GREECE": "GR",
"HUNGARY": "HU",
"IRELAND": "IE",
"ITALY": "IT",
"LATVIA": "LV",
Expand All @@ -167,7 +168,37 @@
"SLOVACCHIA": "SK",
"SLOVENIA": "SI",
"SPAIN": "ES",
"SWEDEN": "SE",
"HUNGARY": "HU"
"SWEDEN": "SE"
},
"Metadata": {
"IsMultilingual": true,
"Languages": [
"bg",
"cs",
"da",
"de",
"el",
"es",
"et",
"fi",
"fr",
"ga",
"hr",
"hu",
"it",
"lb",
"lt",
"lv",
"mt",
"nl",
"pl",
"pt",
"ro",
"sk",
"sl",
"sv",
"tr"
],
"WiderRegion": "Europe"
}
}
29 changes: 28 additions & 1 deletion schemas/WiderRegionCalendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
},
"NationalCalendars": {
"$ref": "#/definitions/NationalCalendars"
},
"Metadata": {
"$ref": "#/definitions/CalendarMetadata"
}
},
"required": [
"LitCal",
"NationalCalendars"
"NationalCalendars",
"Metadata"
],
"title": "WiderRegionCalendar"
},
Expand Down Expand Up @@ -119,6 +123,29 @@
"NationalCalendarVals": {
"type": "string",
"description": "a key value pair where the key is the uppercased country name in English, and the value is the corresponding two letter ISO code for the same country; this is useful for discovery of National Calendars that use this same WiderRegion Calendar"
},
"CalendarMetadata": {
"type": "object",
"properties": {
"IsMultilingual": {
"type": "boolean"
},
"Languages": {
"type": "array",
"items": {
"type": "string",
"pattern": "[A-Z]{2}"
}
},
"WiderRegion": {
"type": "string"
}
},
"required": [
"IsMultilingual",
"WiderRegion"
],
"title": "CalendarMetadata"
}
}
}

0 comments on commit 7395ef4

Please sign in to comment.