Skip to content

Commit

Permalink
begin moving NationalCalendar to json data
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Feb 6, 2022
1 parent a378f16 commit 1716486
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 14 deletions.
57 changes: 44 additions & 13 deletions includes/LitCalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' ) );
Expand Down Expand Up @@ -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 )
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions nations/EUROPE/it.json
Original file line number Diff line number Diff line change
@@ -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"
}
172 changes: 172 additions & 0 deletions nations/Europe.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"}}}
Empty file added nations/ITALY/ITALY.json
Empty file.
2 changes: 1 addition & 1 deletion nations/index.json
Original file line number Diff line number Diff line change
@@ -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"}}

0 comments on commit 1716486

Please sign in to comment.