Skip to content

Commit

Permalink
write national calendar to JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed May 7, 2022
1 parent 0bcbd3b commit 62ad946
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 22 deletions.
31 changes: 9 additions & 22 deletions LitCalNationalAndRegionalData.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,22 @@ private function retrieveNationalCalendar() {
}

private function writeNationalCalendar() {
if( !property_exists( $this->DATA, 'calendar' ) || !property_exists( $this->DATA, 'diocese' ) || !property_exists( $this->DATA, 'nation' ) ) {
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":"Required parameters were not received"}' );
die( '{"error":"Not all required parameters were received (LitCal, Metadata, Settings)"}' );
} else {
$this->RESPONSE->Nation = strip_tags( $this->DATA->nation );
$this->RESPONSE->Diocese = strip_tags( $this->DATA->diocese );
$CalData = json_decode( $this->DATA->calendar );
if( json_last_error() !== JSON_ERROR_NONE ) {
header( $_SERVER[ "SERVER_PROTOCOL" ]." 400 Bad request", true, 400 );
die( '{"error":"Malformed data received in <calendar> parameters"}' );
}
if( property_exists( $this->DATA, 'overrides' ) ) {
$CalData->Overrides = $this->DATA->overrides;
$region = $this->DATA->Metadata->Region;
if( $region === 'UNITED STATES' ) {
$region = 'USA';
}
$this->RESPONSE->Calendar = json_encode( $CalData );
if( property_exists( $this->DATA, 'group' ) ) {
$this->RESPONSE->Group = strip_tags( $this->DATA->group );
}
$path = "nations/{$this->RESPONSE->Nation}";
$path = "nations/{$region}";
if( !file_exists( $path ) ){
mkdir( $path, 0755, true );
}

file_put_contents( $path . "/{$this->RESPONSE->Diocese}.json", $this->RESPONSE->Calendar . PHP_EOL );

//$this->createOrUpdateIndex( $path );
$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->RESPONSE->Diocese .'\""}' );

die( '{"success":"National calendar created or updated for nation \"'. $this->DATA->Metadata->Region .'\""}' );
}
}

Expand Down
188 changes: 188 additions & 0 deletions nations/USA/USA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"LitCal": [
{
"Festivity": {
"tag": "ImmaculateConception",
"name": "The Immaculate Conception of the Blessed Virgin Mary, Patronal feastday of the United States of America",
"color": [
"white"
],
"grade": 6,
"day": 8,
"month": 12
},
"Metadata": {
"action": "makePatron",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StVincentDeacon",
"name": "Saint Vincent, Deacon and Martyr",
"day": 23,
"month": 1,
"missal": "USA_2011",
"reason": "National Day of Prayer for the Unborn"
},
"Metadata": {
"action": "moveFestivity",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StVincentDeacon",
"name": "[ USA ] Saint Vincent, Deacon and Martyr",
"day": 22,
"month": 1
},
"Metadata": {
"action": "setProperty",
"property": "name",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StPaulCross",
"name": "Saint Paul of the Cross, Priest",
"day": 20,
"month": 10,
"missal": "USA_2011",
"reason": "Saint John Brebeuf (elevated to memorial)"
},
"Metadata": {
"action": "moveFestivity",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StPaulCross",
"name": "[ USA ] Saint Paul of the Cross, Priest",
"day": 19,
"month": 10
},
"Metadata": {
"action": "setProperty",
"property": "name",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StsJeanBrebeuf",
"name": "Saints John de Brébeuf and Isaac Jogues, Priests, and Companions, Martyrs",
"grade": 3,
"day": 19,
"month": 10
},
"Metadata": {
"action": "setProperty",
"property": "grade",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StsJeanBrebeuf",
"name": "[ USA ] Saints John de Brébeuf and Isaac Jogues, Priests, and Companions, Martyrs",
"day": 19,
"month": 10
},
"Metadata": {
"action": "setProperty",
"property": "name",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "ThanksgivingDay",
"name": "[ USA ] Thanksgiving",
"color": [
"white"
],
"grade": 3,
"strtotime": "fourth thursday of november",
"common": [],
"readings": ""
},
"Metadata": {
"action": "createNew"
}
},
{
"Festivity": {
"tag": "StCamillusDeLellis",
"name": "Saint Camillus de Lellis, Priest",
"day": 18,
"month": 7,
"missal": "USA_2011",
"reason": "Blessed Kateri Tekakwitha"
},
"Metadata": {
"action": "moveFestivity",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StCamillusDeLellis",
"name": "[ USA ] Saint Camillus de Lellis, Priest",
"day": 14,
"month": 7
},
"Metadata": {
"action": "setProperty",
"property": "name",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StElizabethPortugal",
"name": "Saint Elizabeth of Portugal",
"day": 5,
"month": 7,
"missal": "USA_2011",
"reason": "Independence Day"
},
"Metadata": {
"action": "moveFestivity",
"sinceYear": 1970
}
},
{
"Festivity": {
"tag": "StElizabethPortugal",
"name": "[ USA ] Saint Elizabeth of Portugal",
"day": 4,
"month": 7
},
"Metadata": {
"action": "setProperty",
"property": "name",
"sinceYear": 1970
}
}
],
"Settings": {
"Epiphany": "SUNDAY_JAN2_JAN8",
"Ascension": "SUNDAY",
"CorpusChristi": "SUNDAY",
"Locale": "EN"
},
"Metadata": {
"Region": "UNITED STATES",
"WiderRegion": {
"name": "Americas",
"jsonFile": "nations\/Americas.json",
"i18nFile": "nations\/AMERICAS\/en.json"
},
"Missals": [
"USA_2011"
]
}
}

0 comments on commit 62ad946

Please sign in to comment.