Skip to content

Commit

Permalink
simplify vigil mass creation
Browse files Browse the repository at this point in the history
and make it more readable
  • Loading branch information
JohnRDOrazio committed Feb 1, 2022
1 parent c27289f commit 0afa39b
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 97 deletions.
200 changes: 104 additions & 96 deletions includes/FestivityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public function getCalEventsFromDate( DateTime $date ) : array {
return array_filter( $this->festivities, function( $el ) use ( $date ) { return $el->date == $date; } );
}

public function isSolemnityLordBVM( string $key ) {
public function isSolemnityLordBVM( string $key ) : bool {
return in_array( $key, $this->SolemnitiesLordBVM );
}

public function isSundayAdventLentEaster( DateTime $date ) {
public function isSundayAdventLentEaster( DateTime $date ) : bool {
return in_array( $date, $this->SundaysAdventLentEaster );
}

Expand Down Expand Up @@ -275,6 +275,94 @@ public function setCyclesAndVigils() {
}
}

private function festivityCanHaveVigil( Festivity|stdClass $festivity, ?string $key = null ) : bool {
if( $festivity instanceof Festivity ) {
return (
false === ( $key === 'AllSouls' )
&& false === ( $key === 'AshWednesday' )
&& false === ( $festivity->date > $this->festivities[ "PalmSun" ]->date && $festivity->date < $this->festivities[ "Easter" ]->date )
&& false === ( $festivity->date > $this->festivities[ "Easter" ]->date && $festivity->date < $this->festivities[ "Easter2" ]->date )
);
}
else if( $festivity instanceof stdClass ) {
return (
false === ( $festivity->event->date > $this->festivities[ "PalmSun" ]->date && $festivity->event->date < $this->festivities[ "Easter" ]->date )
&& false === ( $festivity->event->date > $this->festivities[ "Easter" ]->date && $festivity->event->date < $this->festivities[ "Easter2" ]->date )
);
}
}

private function createVigilMass( string $key, Festivity $festivity, DateTime $VigilDate ) : void {
$this->festivities[ $key . "_vigil" ] = new Festivity(
$festivity->name . " " . $this->T[ "Vigil Mass" ],
$VigilDate,
$festivity->color,
$festivity->type,
$festivity->grade,
$festivity->common
);
$this->festivities[ $key ]->hasVigilMass = true;
$this->festivities[ $key ]->hasVesperI = true;
$this->festivities[ $key ]->hasVesperII = true;
$this->festivities[ $key . "_vigil" ]->isVigilMass = true;
$this->festivities[ $key . "_vigil" ]->liturgicalYear = $this->festivities[ $key ]->liturgicalYear;
}

private function coincidingFestivityTakesPrecedenceOverVigil( string $key, Festivity $festivity, stdClass $coincidingFestivity ) : bool {
return (
$festivity->grade < $coincidingFestivity->event->grade ||
( $this->isSolemnityLordBVM( $coincidingFestivity->key ) && !$this->isSolemnityLordBVM( $key ) )
);
}

private function vigilTakesPrecedenceOverCoincidingFestivity( string $key, Festivity $festivity, stdClass $coincidingFestivity ) : bool {
return (
$festivity->grade > $coincidingFestivity->event->grade ||
( $this->isSolemnityLordBVM( $key ) && !$this->isSolemnityLordBVM( $coincidingFestivity->key ) )
);
}

private function handleVigilFestivityCoincidence( string $key, Festivity $festivity, string $festivityGrade, stdClass $coincidingFestivity, bool|string $vigilTakesPrecedence ) : void {
if( gettype($vigilTakesPrecedence) === "string" && $vigilTakesPrecedence === "YEAR2022" ) {
$festivity->hasVigilMass = true;
$festivity->hasVesperI = true;
$coincidingFestivity->event->hasVesperII = false;
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. As per %s, the first has precedence, therefore the Vigil Mass is confirmed as are I Vespers." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year,
'<a href="http://www.cultodivino.va/content/cultodivino/it/documenti/responsa-ad-dubia/2020/de-calendario-liturgico-2022.html">' . _( "Decree of the Congregation for Divine Worship" ) . '</a>'
);
} else {
$festivity->hasVigilMass = $vigilTakesPrecedence;
$festivity->hasVesperI = $vigilTakesPrecedence;
$coincidingFestivity->event->hasVesperII = !$vigilTakesPrecedence;
if( $vigilTakesPrecedence ) {
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. Since the first Solemnity has precedence, it will have Vespers I and a vigil Mass, whereas the last Solemnity will not have either Vespers II or an evening Mass." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year
);
} else {
unset( $this->festivities[ $key . "_vigil" ] );
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. This last Solemnity takes precedence, therefore it will maintain Vespers II and an evening Mass, while the first Solemnity will not have a Vigil Mass or Vespers I." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year
);
}
}
}

private function calculateVigilMass( string $key, Festivity $festivity ) {

//Let's calculate Vigil Masses while we're at it
Expand All @@ -295,25 +383,8 @@ private function calculateVigilMass( string $key, Festivity $festivity ) {
//conditions for which the festivity SHOULD have a vigil
if( self::DateIsSunday( $festivity->date ) || true === ( $festivity->grade >= LitGrade::SOLEMNITY ) ){
//filter out cases in which the festivity should NOT have a vigil
if(
false === ( $key === 'AllSouls' )
&& false === ( $key === 'AshWednesday' )
&& false === ( $festivity->date > $this->festivities[ "PalmSun" ]->date && $festivity->date < $this->festivities[ "Easter" ]->date )
&& false === ( $festivity->date > $this->festivities[ "Easter" ]->date && $festivity->date < $this->festivities[ "Easter2" ]->date )
){
$this->festivities[ $key . "_vigil" ] = new Festivity(
$festivity->name . " " . $this->T[ "Vigil Mass" ],
$VigilDate,
$festivity->color,
$festivity->type,
$festivity->grade,
$festivity->common
);
$this->festivities[ $key ]->hasVigilMass = true;
$this->festivities[ $key ]->hasVesperI = true;
$this->festivities[ $key ]->hasVesperII = true;
$this->festivities[ $key . "_vigil" ]->isVigilMass = true;
$this->festivities[ $key . "_vigil" ]->liturgicalYear = $this->festivities[ $key ]->liturgicalYear;
if( $this->festivityCanHaveVigil( $festivity, $key ) ) {
$this->createVigilMass( $key, $festivity, $VigilDate );
//if however the Vigil coincides with another Solemnity let's make a note of it!
if( $this->inSolemnities( $VigilDate ) ) {
$coincidingFestivity = new stdClass();
Expand All @@ -329,85 +400,19 @@ private function calculateVigilMass( string $key, Festivity $festivity ) {
}

//suppress warning messages for known situations, like the Octave of Easter
if( $festivity->grade !== LitGrade::HIGHER_SOLEMNITY ){
if( $festivity->grade < $coincidingFestivity->event->grade ){
$festivity->hasVigilMass = false;
$festivity->hasVesperI = false;
$coincidingFestivity->event->hasVesperII = true;
unset( $this->festivities[ $key . "_vigil" ] );
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. This last Solemnity takes precedence, therefore it will maintain Vespers II and an evening Mass, while the first Solemnity will not have a Vigil Mass or Vespers I." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year
);
if( $festivity->grade !== LitGrade::HIGHER_SOLEMNITY ) {
if( $this->coincidingFestivityTakesPrecedenceOverVigil( $key, $festivity, $coincidingFestivity ) ) {
$this->handleVigilFestivityCoincidence( $key, $festivity, $festivityGrade, $coincidingFestivity, false );
}
else if( $festivity->grade > $coincidingFestivity->event->grade || ( $this->isSolemnityLordBVM( $key ) && !$this->isSolemnityLordBVM( $coincidingFestivity->key ) ) ) {
$festivity->hasVigilMass = true;
$festivity->hasVesperI = true;
$coincidingFestivity->event->hasVesperII = false;
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. Since the first Solemnity has precedence, it will have Vespers I and a vigil Mass, whereas the last Solemnity will not have either Vespers II or an evening Mass." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year
);
else if( $this->vigilTakesPrecedenceOverCoincidingFestivity( $key, $festivity, $coincidingFestivity ) ) {
$this->handleVigilFestivityCoincidence( $key, $festivity, $festivityGrade, $coincidingFestivity, true );
}
else if( $this->isSolemnityLordBVM( $coincidingFestivity->key ) && !$this->isSolemnityLordBVM( $key ) ){
$coincidingFestivity->event->hasVesperII = true;
$festivity->hasVesperI = false;
$festivity->hasVigilMass = false;
unset( $this->festivities[ $key . "_vigil" ] );
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. This last Solemnity takes precedence, therefore it will maintain Vespers II and an evening Mass, while the first Solemnity will not have a Vigil Mass or Vespers I." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year
);
} else {
if( $this->LitSettings->Year === 2022 ){
if( $key === 'SacredHeart' || $key === 'Lent3' || $key === 'Assumption' ){
$coincidingFestivity->event->hasVesperII = false;
$festivity->hasVesperI = true;
$festivity->hasVigilMass = true;
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. As per %s, the first has precedence, therefore the Vigil Mass is confirmed as are I Vespers." ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year,
'<a href="http://www.cultodivino.va/content/cultodivino/it/documenti/responsa-ad-dubia/2020/de-calendario-liturgico-2022.html">' . _( "Decree of the Congregation for Divine Worship" ) . '</a>'
);
}
}
else {
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. We should ask the Congregation for Divine Worship what to do about this!" ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
$coincidingFestivity->event->name,
$this->LitSettings->Year
);
}
else if ( $this->LitSettings->Year === 2022 && ( $key === 'SacredHeart' || $key === 'Lent3' || $key === 'Assumption' ) ) {
$this->handleVigilFestivityCoincidence( $key, $festivity, $festivityGrade, $coincidingFestivity, "YEAR2022" );
}
} else {
if(
//false === ( $key === 'AllSouls' )
//&& false === ( $key === 'AshWednesday' )
false === ( $coincidingFestivity->event->date > $this->festivities[ "PalmSun" ]->date && $coincidingFestivity->event->date < $this->festivities[ "Easter" ]->date )
&& false === ( $coincidingFestivity->event->date > $this->festivities[ "Easter" ]->date && $coincidingFestivity->event->date < $this->festivities[ "Easter2" ]->date )
){

else {
$this->Messages[] = '<span style="padding:3px 6px; font-weight: bold; background-color: #FFC;color:Red;border-radius:6px;">IMPORTANT</span> ' . sprintf(
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. Since the first Solemnity has precedence, it will have Vespers I and a vigil Mass, whereas the last Solemnity will not have either Vespers II or an evening Mass." ),
_( "The Vigil Mass for the %s '%s' coincides with the %s '%s' in the year %d. We should ask the Congregation for Divine Worship what to do about this!" ),
$festivityGrade,
$festivity->name,
$coincidingFestivity->grade,
Expand All @@ -416,6 +421,9 @@ private function calculateVigilMass( string $key, Festivity $festivity ) {
);
}
}
else if ( $this->festivityCanHaveVigil( $coincidingFestivity, null ) ) {
$this->handleVigilFestivityCoincidence( $key, $festivity, $festivityGrade, $coincidingFestivity, true );
}
}
} else {
$this->festivities[ $key ]->hasVigilMass = false;
Expand Down
2 changes: 1 addition & 1 deletion includes/LitCalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class LitCalAPI {

const API_VERSION = '3.3';
const API_VERSION = '3.4';
public APICore $APICore;

private string $CacheDuration = "";
Expand Down

0 comments on commit 0afa39b

Please sign in to comment.