diff --git a/LitCalNationalAndRegionalData.php b/LitCalNationalAndRegionalData.php index b41745c7..a9452bbb 100644 --- a/LitCalNationalAndRegionalData.php +++ b/LitCalNationalAndRegionalData.php @@ -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 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 .'\""}' ); } } diff --git a/nations/USA/USA.json b/nations/USA/USA.json new file mode 100644 index 00000000..c69fc143 --- /dev/null +++ b/nations/USA/USA.json @@ -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" + ] + } +}