Created
July 2, 2019 12:28
-
-
Save neilgilmour/54d2fb3bbeeb9fa4f67879647e8364cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controllers; | |
use Sober\Controller\Controller; | |
class TemplateProgramme extends Controller | |
{ | |
public function tabs() | |
{ | |
$y = date('Y'); | |
$jj = 'Jan-Jun '; | |
$jd = 'Jul-Dec '; | |
$sjj = '01 Jan '; | |
$ejj = '30 Jun '; | |
$sjd = '01 Jul '; | |
$ejd = '31 Dec '; | |
// are we in the first or second half of the year? | |
if(date('m') <= 6) { // it's currently Jun ar earlier, so we start with the Jan-Jun Programme. | |
$tabs = [ | |
[ | |
'title' => $jj . $y, | |
'start' => $sjj . $y, | |
'end' => $ejj . $y, | |
'contents' => [], | |
], | |
[ | |
'title' => $jd . ($y - 1), | |
'start' => $sjd . ($y - 1), | |
'end' => $ejd . ($y - 1), | |
'contents' => [], | |
], | |
[ | |
'title' => $jj . ($y - 1), | |
'start' => $sjj . ($y - 1), | |
'end' => $ejj . ($y - 1), | |
'contents' => [], | |
], | |
[ | |
'title' => $jd . ($y - 2), | |
'start' => $sjd . ($y - 2), | |
'end' => $ejd . ($y - 2), | |
'contents' => [], | |
], | |
[ | |
'title' => $jj . ($y - 2), | |
'start' => $sjj . ($y - 2), | |
'end' => $ejj . ($y - 2), | |
'contents' => [], | |
], | |
[ | |
'title' => $jd . ($y - 3), | |
'start' => $sjd . ($y - 3), | |
'end' => $ejd . ($y - 3), | |
'contents' => [], | |
], | |
]; | |
} else { //it's currently July or later, so we start with the Jul-Dec Programme | |
$tabs = [ | |
[ | |
'title' => $jd . $y, | |
'start' => $sjd . $y, | |
'end' => $ejd . $y, | |
'contents' => [], | |
], | |
[ | |
'title' => $jj . $y, | |
'start' => $sjj . $y, | |
'end' => $ejj . $y, | |
'contents' => [], | |
], | |
[ | |
'title' => $jd . ($y - 1), | |
'start' => $sjd . ($y - 1), | |
'end' => $ejd . ($y - 1), | |
'contents' => [], | |
], | |
[ | |
'title' => $jj . ($y - 1), | |
'start' => $sjj . ($y - 1), | |
'end' => $ejj . ($y - 1), | |
'contents' => [], | |
], | |
[ | |
'title' => $jd . ($y - 2), | |
'start' => $sjd . ($y - 2), | |
'end' => $ejd . ($y - 2), | |
'contents' => [], | |
], | |
[ | |
'title' => $jj . ($y - 2), | |
'start' => $sjj . ($y - 2), | |
'end' => $ejj . ($y - 2), | |
'contents' => [], | |
], | |
]; | |
}; | |
} | |
public function programme() | |
{ | |
$programme = get_posts([ | |
'posts_per_page' => -1, | |
'post_type' => 'programme', | |
'order' => 'ASC', | |
'orderby' => 'meta_value', | |
'meta_key' => 'field_prog_start_date', | |
'meta_type' => 'DATETIME' | |
]); | |
return array_map(function ($post) { | |
return [ | |
'start' => get_field('field_prog_start_date', $post), | |
'end' => get_field('field_prog_finish_date', $post), | |
'title' => $post->post_title, | |
'info' => get_field('field_prog_description', $post), | |
'link' => get_field('field_prog_location', $post), | |
]; | |
}, $programme); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment