From 1716486704a51eca41cdc066e66744c9c832f05b Mon Sep 17 00:00:00 2001 From: John D'Orazio Date: Sun, 6 Feb 2022 23:24:26 +0100 Subject: [PATCH] begin moving NationalCalendar to json data --- includes/LitCalAPI.php | 57 ++++-- nations/EUROPE/it.json | 7 + nations/Europe.json | 172 ++++++++++++++++++ ... Sora - Cassino - Aquino - Pontecorvo.json | 1 + nations/ITALY/ITALY.json | 0 nations/index.json | 2 +- 6 files changed, 225 insertions(+), 14 deletions(-) create mode 100644 nations/EUROPE/it.json create mode 100644 nations/Europe.json create mode 100644 nations/ITALY/Diocesi di Sora - Cassino - Aquino - Pontecorvo.json create mode 100644 nations/ITALY/ITALY.json diff --git a/includes/LitCalAPI.php b/includes/LitCalAPI.php index d31d6ae6..539b8eeb 100644 --- a/includes/LitCalAPI.php +++ b/includes/LitCalAPI.php @@ -32,6 +32,8 @@ class LitCalAPI { private LitGrade $LitGrade; private ?object $DiocesanData = null; + private ?object $NationalData = null; + private ?object $widerRegionData = null; private ?object $GeneralIndex = null; private NumberFormatter $formatter; private NumberFormatter $formatterFem; @@ -172,7 +174,7 @@ private function updateSettingsBasedOnDiocesanCalendar() : void { } - private function loadLocalCalendarData() : void { + private function loadDiocesanCalendarData() : void { if( $this->LitSettings->DiocesanCalendar !== null ){ //since a Diocesan calendar is being requested, we need to retrieve the JSON data //first we need to discover the path, so let's retrieve our index file @@ -220,14 +222,14 @@ private function dieIfBeforeMinYear() : void { //with the Prima Editio Typica of the Roman Missal and the General Norms promulgated with the Motu Proprio "Mysterii Paschali" in 1969 if ( $this->LitSettings->Year < 1970 ) { $this->Messages[] = sprintf( _( "Only years from 1970 and after are supported. You tried requesting the year %d." ), $this->LitSettings->Year ); - $this->GenerateResponseToRequest(); + $this->GenerateResponse(); } } /** * Retrieve Higher Ranking Solemnities from Proprium de Tempore */ - private function populatePropriumDeTempore() : void { + private function loadPropriumDeTemporeData() : void { $propriumdetemporeFile = strtolower( "data/propriumdetempore/{$this->LitSettings->Locale}.json" ); if( file_exists( $propriumdetemporeFile ) ) { $PropriumDeTempore = json_decode( file_get_contents( $propriumdetemporeFile ), true ); @@ -241,7 +243,7 @@ private function populatePropriumDeTempore() : void { } } - private function readPropriumDeSanctisJSONData( string $missal ) : void { + private function loadPropriumDeSanctisData( string $missal ) : void { $propriumdesanctisFile = RomanMissal::getSanctoraleFileName( $missal ); $propriumdesanctisI18nPath = RomanMissal::getSanctoraleI18nFilePath( $missal ); @@ -271,7 +273,7 @@ private function readPropriumDeSanctisJSONData( string $missal ) : void { } } - private function readMemorialsFromDecreesJSONData() : void { + private function loadMemorialsFromDecreesData() : void { $memorialsFromDecreesFile = "data/memorialsFromDecrees/memorialsFromDecrees.json"; $memorialsFromDecreesI18nPath = "data/memorialsFromDecrees/i18n/"; $memorialsFromDecreesI18nFile = $memorialsFromDecreesI18nPath . strtolower( $this->LitSettings->Locale ) . ".json"; @@ -1584,7 +1586,7 @@ private function applyCalendarItaly() : void { $this->applyPatronSaintsEurope(); $this->applyPatronSaintsItaly(); if( $this->LitSettings->Year >= 1983 && $this->LitSettings->Year < 2002 ) { - $this->readPropriumDeSanctisJSONData( RomanMissal::ITALY_EDITION_1983 ); + $this->loadPropriumDeSanctisData( RomanMissal::ITALY_EDITION_1983 ); //The extra liturgical events found in the 1983 edition of the Roman Missal in Italian, //were then incorporated into the Latin edition in 2002 ( effectively being incorporated into the General Roman Calendar ) //so when dealing with Italy, we only need to add them from 1983 until 2002, after which it's taken care of by the General Calendar @@ -1767,7 +1769,7 @@ private function applyCalendarUSA() : void { $currentFeastDate = DateTime::createFromFormat( '!j-n-Y', '5-7-' . $this->LitSettings->Year, new DateTimeZone( 'UTC' ) ); $this->moveFestivityDate( "StElizabethPortugal", $currentFeastDate, "Independence Day", RomanMissal::USA_EDITION_2011 ); - $this->readPropriumDeSanctisJSONData( RomanMissal::USA_EDITION_2011 ); + $this->loadPropriumDeSanctisData( RomanMissal::USA_EDITION_2011 ); foreach ( $this->tempCal[ RomanMissal::USA_EDITION_2011 ] as $row ) { $currentFeastDate = DateTime::createFromFormat( '!j-n-Y', $row->DAY . '-' . $row->MONTH . '-' . $this->LitSettings->Year, new DateTimeZone( 'UTC' ) ); @@ -1867,7 +1869,7 @@ private static function DateIsNotSunday( DateTime $dt ) : bool { private function calculateUniversalCalendar() : void { - $this->populatePropriumDeTempore(); + $this->loadPropriumDeTemporeData(); /** * CALCULATE LITURGICAL EVENTS BASED ON THE ORDER OF PRECEDENCE OF LITURGICAL DAYS ( LY 59 ) * General Norms for the Liturgical Year and the Calendar ( issued on Feb. 14 1969 ) @@ -1886,7 +1888,7 @@ private function calculateUniversalCalendar() : void { $this->calculateEasterOctave(); //3. Solemnities of the Lord, of the Blessed Virgin Mary, and of saints listed in the General Calendar $this->calculateMobileSolemnitiesOfTheLord(); - $this->readPropriumDeSanctisJSONData( RomanMissal::EDITIO_TYPICA_1970 ); + $this->loadPropriumDeSanctisData( RomanMissal::EDITIO_TYPICA_1970 ); $this->calculateFixedSolemnities(); //this will also handle All Souls Day //4. PROPER SOLEMNITIES: @@ -1920,16 +1922,16 @@ private function calculateUniversalCalendar() : void { $this->calculateMemorials( LitGrade::MEMORIAL, RomanMissal::EDITIO_TYPICA_1970 ); if ( $this->LitSettings->Year >= 2002 ) { - $this->readPropriumDeSanctisJSONData( RomanMissal::EDITIO_TYPICA_TERTIA_2002 ); + $this->loadPropriumDeSanctisData( RomanMissal::EDITIO_TYPICA_TERTIA_2002 ); $this->calculateMemorials( LitGrade::MEMORIAL, RomanMissal::EDITIO_TYPICA_TERTIA_2002 ); } if( $this->LitSettings->Year >= 2008 ) { - $this->readPropriumDeSanctisJSONData( RomanMissal::EDITIO_TYPICA_TERTIA_EMENDATA_2008 ); + $this->loadPropriumDeSanctisData( RomanMissal::EDITIO_TYPICA_TERTIA_EMENDATA_2008 ); $this->calculateMemorials( LitGrade::MEMORIAL, RomanMissal::EDITIO_TYPICA_TERTIA_EMENDATA_2008 ); } - $this->readMemorialsFromDecreesJSONData(); + $this->loadMemorialsFromDecreesData(); $this->applyDecrees( LitGrade::MEMORIAL ); //11. Proper obligatory memorials, and that is: @@ -2210,6 +2212,33 @@ public function setAllowedReturnTypes( array $returnTypes ) : void { $this->AllowedReturnTypes = array_values( array_intersect( ReturnType::$values, $returnTypes ) ); } + private function loadNationalCalendarData() : void { + $nationalDataFile = "nations/{$this->LitSettings->NationalCalendar}/{$this->LitSettings->NationalCalendar}.json"; + if( file_exists( $nationalDataFile ) ) { + $this->NationalData = json_decode( file_get_contents($nationalDataFile ) ); + if( property_exists( $this->NationalData, "Metadata" ) && property_exists( $this->NationalData, "WiderRegion" ) ){ + $widerRegionDataFile = $this->NationalData->Metadata->WiderRegion->jsonFile; + $widerRegionI18nFile = $this->NationalData->Metadata->WiderRegion->i18nFile; + if( file_exists( $widerRegionI18nFile ) ) { + $widerRegionI18nData = json_decode( file_get_contents( $widerRegionI18nFile ) ); + if( json_last_error() === JSON_ERROR_NONE && file_exists( $widerRegionDataFile ) ) { + $this->WiderRegionData = json_decode( file_get_contents( $widerRegionDataFile ), true ); + if( json_last_error() === JSON_ERROR_NONE ) { + foreach( $this->WiderRegionData as $idx => $value ) { + $tag = $value["Festivity"]["tag"]; + $this->WiderRegionData[$idx]["Festivity"]["name"] = $widerRegionI18nData[ $tag ]; + } + } else { + $this->Messages[] = sprintf( _( "Error retrieving and decoding Wider Region data from file %s." ), $widerRegionDataFile ) . ": " . json_last_error_msg(); + } + } else { + $this->Messages[] = sprintf( _( "Error retrieving and decoding Wider Region data from file %s." ), $widerRegionI18nFile ) . ": " . json_last_error_msg(); + } + } + } + } + } + /** * The LitCalEngine will only work once you call the public Init() method * Do not change the order of the methods that follow, @@ -2218,7 +2247,7 @@ public function setAllowedReturnTypes( array $returnTypes ) : void { public function Init(){ $this->APICore->Init(); $this->initParameterData(); - $this->loadLocalCalendarData(); + $this->loadDiocesanCalendarData(); $this->APICore->setResponseContentTypeHeader(); if( $this->cacheFileIsAvailable() ){ //If we already have done the calculation @@ -2232,6 +2261,8 @@ public function Init(){ $this->calculateUniversalCalendar(); if( $this->LitSettings->NationalCalendar !== null ) { + //$this->loadNationalCalendarData(); + //$this->applyNationalCalendar(); switch( $this->LitSettings->NationalCalendar ){ case 'ITALY': $this->applyCalendarItaly(); diff --git a/nations/EUROPE/it.json b/nations/EUROPE/it.json new file mode 100644 index 00000000..de7a9e86 --- /dev/null +++ b/nations/EUROPE/it.json @@ -0,0 +1,7 @@ +{ + "StBenedict": "San Benedetto, abate, patrono d'Europa", + "StsCyrilMethodius": "Santi Cirillo, monaco, e Metodio, vescovo, patroni d'Europa", + "StBridget": "Santa Brigida, religiosa, patrona d'Europa", + "StCatherineSiena": "Santa Caterina da Siena, vergine e dottore della Chiesa, patrona d'Italia e d'Europa", + "StEdithStein": "Santa Teresa Benedetta della Croce, vergine e martire, patrona d'Europa" +} diff --git a/nations/Europe.json b/nations/Europe.json new file mode 100644 index 00000000..14098228 --- /dev/null +++ b/nations/Europe.json @@ -0,0 +1,172 @@ +{ + "LitCal": [ + { + "Festivity": { + "tag": "StBenedict", + "color": "white", + "grade": 4, + "day": 11, + "month": 7, + "sinceYear": 1964 + }, + "Metadata": { + "action": "makePatron", + "decreeURL": "https://www.vatican.va/content/paul-vi/%s/apost_letters/documents/hf_p-vi_apl_19641024_pacis-nuntius.html", + "decreeLangs": { + "IT": "it", + "ES": "es", + "LA": "la" + } + } + }, + { + "Festivity": { + "tag": "StsCyrilMethodius", + "color": "white", + "grade": 4, + "day": 14, + "month": 2, + "sinceYear": 1980 + }, + "Metadata": { + "action": "makePatron", + "decreeURL": "https://www.vatican.va/content/john-paul-ii/%s/apost_letters/1980/documents/hf_jp-ii_apl_31121980_egregiae-virtutis.html", + "decreeLangs": { + "ES": "es", + "IT": "it", + "LA": "la", + "PT": "pt" + } + } + }, + { + "Festivity": { + "tag": "StBridget", + "color": "white", + "grade": 4, + "day": 23, + "month": 7, + "sinceYear": 1999 + }, + "Metadata": { + "action": "makePatron", + "decreeURL": "https://www.vatican.va/content/john-paul-ii/%s/motu_proprio/documents/hf_jp-ii_motu-proprio_01101999_co-patronesses-europe.html", + "decreeLangs": { + "DE": "de", + "EN": "en", + "ES": "es", + "FR": "fr", + "IT": "it", + "LA": "la", + "PT": "pt" + } + } + }, + { + "Festivity": { + "tag": "StCatherineSiena", + "color": "white", + "grade": 4, + "day": 29, + "month": 4, + "sinceYear": 1999 + }, + "Metadata": { + "action": "makePatron", + "decreeURL": "https://www.vatican.va/content/john-paul-ii/%s/motu_proprio/documents/hf_jp-ii_motu-proprio_01101999_co-patronesses-europe.html", + "decreeLangs": { + "DE": "de", + "EN": "en", + "ES": "es", + "FR": "fr", + "IT": "it", + "LA": "la", + "PT": "pt" + } + } + }, + { + "Festivity": { + "tag": "StEdithStein", + "color": "white", + "grade": 4, + "day": 9, + "month": 8, + "sinceYear": 1999, + "common": "Martyrs:For a Virgin Martyr,Virgins:For One Virgin", + "readings": { + "FIRST_READING": "", + "RESPONSORIAL_PSALM": "", + "SECOND_READING": "", + "ALLELUIA_VERSE": "", + "GOSPEL": "" + } + }, + "Metadata": { + "action": "create", + "decreeURL": "https://www.vatican.va/content/john-paul-ii/%s/motu_proprio/documents/hf_jp-ii_motu-proprio_01101999_co-patronesses-europe.html", + "decreeLangs": { + "DE": "de", + "EN": "en", + "ES": "es", + "FR": "fr", + "IT": "it", + "LA": "la", + "PT": "pt" + } + } + }, + { + "Festivity": { + "tag": "StEdithStein", + "color": "white", + "grade": 4, + "day": 9, + "month": 8, + "sinceYear": 2002 + }, + "Metadata": { + "action": "makePatron", + "decreeURL": "https://www.vatican.va/content/john-paul-ii/%s/motu_proprio/documents/hf_jp-ii_motu-proprio_01101999_co-patronesses-europe.html", + "decreeLangs": { + "DE": "de", + "EN": "en", + "ES": "es", + "FR": "fr", + "IT": "it", + "LA": "la", + "PT": "pt" + } + } + } + ], + "NationalCalendars": { + "AUSTRIA": "AT", + "BELGIUM": "BE", + "BULGARIA": "BG", + "CZECH REPUBLIC": "CZ", + "CYPRUS": "CY", + "CROATIA": "HR", + "DENMARK": "DK", + "ESTONIA": "EE", + "FINLAND": "FI", + "FRANCE": "FR", + "GERMANY": "DE", + "GREECE": "GR", + "IRELAND": "IE", + "ITALY": "IT", + "LATVIA": "LV", + "LITHUANIA": "LT", + "LUXEMBOURG": "LU", + "MALTA": "MT", + "NETHERLANDS": "NL", + "POLONIA": "PL", + "PORTUGAL": "PT", + "ROMANIA": "RO", + "SLOVACCHIA": "SK", + "SLOVENIA": "SI", + "SPAIN": "ES", + "SWEDEN": "SE", + "HUNGARY": "HU" + } +} diff --git a/nations/ITALY/Diocesi di Sora - Cassino - Aquino - Pontecorvo.json b/nations/ITALY/Diocesi di Sora - Cassino - Aquino - Pontecorvo.json new file mode 100644 index 00000000..977ef41f --- /dev/null +++ b/nations/ITALY/Diocesi di Sora - Cassino - Aquino - Pontecorvo.json @@ -0,0 +1 @@ +{"LitCal":{"DedicazionedellaChiesaMadrediCassinoinCassino":{"name":"Dedicazione della Chiesa Madre di Cassino (in Cassino)","color":"white","grade":6,"common":"Dedication of a Church","day":5,"month":6,"formRowNum":1,"sinceYear":"1970"},"SantaRestituta":{"name":"Santa Restituta","color":["white"],"grade":4,"common":"Proper","day":27,"month":5,"formRowNum":0,"sinceYear":"1970"}}} diff --git a/nations/ITALY/ITALY.json b/nations/ITALY/ITALY.json new file mode 100644 index 00000000..e69de29b diff --git a/nations/index.json b/nations/index.json index 5eff8744..8afa2a4b 100644 --- a/nations/index.json +++ b/nations/index.json @@ -1 +1 @@ -{"DIOCESIDIROMA":{"path":"nations\/ITALY\/Diocesi di Roma.json","nation":"ITALY","diocese":"Diocesi di Roma","group":"Diocesi del Lazio"},"ARCHDIOCESEOFBOSTONMASSACHUSETTS":{"path":"nations\/USA\/Archdiocese of Boston (Massachusetts).json","nation":"USA","diocese":"Archdiocese of Boston (Massachusetts)"}} +{"DIOCESIDIROMA":{"path":"nations\/ITALY\/Diocesi di Roma.json","nation":"ITALY","diocese":"Diocesi di Roma","group":"Diocesi del Lazio"},"ARCHDIOCESEOFBOSTONMASSACHUSETTS":{"path":"nations\/USA\/Archdiocese of Boston (Massachusetts).json","nation":"USA","diocese":"Archdiocese of Boston (Massachusetts)"},"DIOCESIDISORACASSINOAQUINOPONTECORVO":{"path":"nations\/ITALY\/Diocesi di Sora - Cassino - Aquino - Pontecorvo.json","nation":"ITALY","diocese":"Diocesi di Sora - Cassino - Aquino - Pontecorvo","group":"Diocesi del Lazio"}}