Skip to content

Commit

Permalink
Merge pull request #80 from Liturgical-Calendar/development
Browse files Browse the repository at this point in the history
Allow diocesan overrides
  • Loading branch information
JohnRDOrazio authored Jan 23, 2022
2 parents 0f1902e + 3b3822c commit 5cf653c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# Check-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Update source file translation strings
id: update_pot
run: |
sudo apt-get install -y gettext
xgettext --from-code=UTF-8 --add-comments='translators:' --keyword="pgettext:1c,2" -o i18n/litcal.pot includes/LitCalAPI.php includes/LitMessages.php includes/FestivityCollection.php includes/enums/LitColor.php includes/enums/LitCommon.php includes/enums/LitGrade.php
echo "::set-output name=POT_LINES_CHANGED::$(git diff -U0 | grep '^[+|-][^+|-]' | grep -Ev '^[+-]"POT-Creation-Date' | tee >(wc -l))"
- name: Push changes # push the output folder to your repo
# push the output folder to your repo
- name: Push changes
if: ${{ steps.update_pot.outputs.POT_LINES_CHANGED > 0 }}
uses: actions-x/commit@v4
with:
Expand Down
3 changes: 3 additions & 0 deletions LitCalDiocesanData.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ private function writeDiocesanCalendar() {
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;
}
$this->RESPONSE->Calendar = json_encode( $CalData );
if( property_exists( $this->DATA, 'group' ) ) {
$this->RESPONSE->Group = strip_tags( $this->DATA->group );
Expand Down
69 changes: 50 additions & 19 deletions includes/LitCalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,9 @@ private function initParameterData() {
}
}


private function loadLocalCalendarData() : 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
if( file_exists( "nations/index.json" ) ){
$this->GeneralIndex = json_decode( file_get_contents( "nations/index.json" ) );
if( property_exists( $this->GeneralIndex, $this->LitSettings->DiocesanCalendar ) ){
$diocesanDataFile = $this->GeneralIndex->{$this->LitSettings->DiocesanCalendar}->path;
$this->LitSettings->NationalCalendar = $this->GeneralIndex->{$this->LitSettings->DiocesanCalendar}->nation;
if( file_exists( $diocesanDataFile ) ){
$this->DiocesanData = json_decode( file_get_contents( $diocesanDataFile ) );
}
}
}
}

if( $this->LitSettings->NationalCalendar !== null ){
switch( $this->LitSettings->NationalCalendar ){
private function updateSettingsBasedOnNationalCalendar() : void {
if( $this->LitSettings->NationalCalendar !== null ) {
switch( $this->LitSettings->NationalCalendar ) {
case 'VATICAN':
$this->LitSettings->Epiphany = Epiphany::JAN6;
$this->LitSettings->Ascension = Ascension::THURSDAY;
Expand All @@ -161,6 +145,53 @@ private function loadLocalCalendarData() : void {
}
}

private function updateSettingsBasedOnDiocesanCalendar() : void {
if( $this->LitSettings->DiocesanCalendar !== null && $this->DiocesanData !== null ) {
if( property_exists( $this->DiocesanData, "Overrides" ) ) {
foreach( $this->DiocesanData->Overrides as $key => $value ) {
switch( $key ) {
case "Epiphany":
if( Epiphany::isValid( $value ) ) {
$this->LitSettings->Epiphany = $value;
}
break;
case "Ascension":
if( Ascension::isValid( $value ) ) {
$this->LitSettings->Ascension = $value;
}
break;
case "CorpusChristi":
if( CorpusChristi::isValid( $value ) ) {
$this->LitSettings->CorpusChristi = $value;
}
break;
}
}
}
}
}


private function loadLocalCalendarData() : 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
if( file_exists( "nations/index.json" ) ){
$this->GeneralIndex = json_decode( file_get_contents( "nations/index.json" ) );
if( property_exists( $this->GeneralIndex, $this->LitSettings->DiocesanCalendar ) ){
$diocesanDataFile = $this->GeneralIndex->{$this->LitSettings->DiocesanCalendar}->path;
$this->LitSettings->NationalCalendar = $this->GeneralIndex->{$this->LitSettings->DiocesanCalendar}->nation;
if( file_exists( $diocesanDataFile ) ){
$this->DiocesanData = json_decode( file_get_contents( $diocesanDataFile ) );
}
}
}
}

$this->updateSettingsBasedOnNationalCalendar();
$this->updateSettingsBasedOnDiocesanCalendar();
}

private function cacheFileIsAvailable() : bool {
$cacheFilePath = "engineCache/v" . str_replace( ".", "_", self::API_VERSION ) . "/";
$cacheFileName = md5( serialize( $this->LitSettings) ) . $this->CacheDuration . "." . strtolower( $this->LitSettings->ReturnType );
Expand Down

0 comments on commit 5cf653c

Please sign in to comment.