Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date and day filter for images #124

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions lib/teksttv.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use WP_Query;
use WP_REST_Response;
use DateTime;

class TekstTVAPI
{
Expand Down Expand Up @@ -126,8 +127,11 @@ private function get_article_slides($block)

// Skip if the post's expiration date has passed
$end_date = get_field('post_kabelkrant_datum_uit', get_the_ID());
if (!empty($end_date) && strtotime($end_date) < current_time('timestamp')) {
continue;
if (!empty($end_date)) {
$end_date_obj = DateTime::createFromFormat('d/m/Y', $end_date);
if ($end_date_obj && $end_date_obj->getTimestamp() < current_time('timestamp')) {
continue;
}
}

// Skip if this post isn't for TekstTV
Expand Down Expand Up @@ -190,13 +194,44 @@ private function get_primary_category_image($post_id)
return get_the_post_thumbnail_url($post_id, 'large');
}

// Generate an image slide from a block
// Generate an image slide from a block with day and date filtering
private function get_image_slide($block)
{
$current_timestamp = current_time('timestamp');

// Check date range if 'datum_in' or 'datum_uit' is set
if (!empty($block['datum_in'])) {
$start_date = DateTime::createFromFormat('d/m/Y', $block['datum_in']);
if ($start_date && $current_timestamp < $start_date->getTimestamp()) {
// Current date is before the start date
return null;
}
}

if (!empty($block['datum_uit'])) {
$end_date = DateTime::createFromFormat('d/m/Y', $block['datum_uit']);
if ($end_date && $current_timestamp > $end_date->getTimestamp()) {
// Current date is after the end date
return null;
}
}

// Check day filter if 'dagen' is set
if (!empty($block['dagen'])) {
$today = date('N'); // 1 (Monday) to 7 (Sunday)
$allowed_days = $block['dagen']; // Array of strings ["1", "2", ..., "7"]

if (!in_array((string)$today, $allowed_days, true)) {
// Today is not in the allowed days
return null;
}
}

// If all checks pass, return the image slide
if (!empty($block['afbeelding']) && !empty($block['afbeelding']['url'])) {
return [
'type' => 'image',
'duration' => intval($block['seconden']) * 1000,
'duration' => intval($block['seconden']) * 1000, // Convert to milliseconds
'url' => $block['afbeelding']['url'],
];
}
Expand Down
80 changes: 62 additions & 18 deletions streekomroep-acf-json/group_66c5010145df1.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "30",
"width": "20",
"class": "",
"id": ""
},
Expand All @@ -129,8 +129,32 @@
"max_height": "",
"max_size": "",
"mime_types": "",
"allow_in_bindings": 1,
"preview_size": "thumbnail"
},
{
"key": "field_669d49c2261cd",
"label": "Seconden",
"name": "seconden",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "15",
"class": "",
"id": ""
},
"default_value": 10,
"min": "",
"max": "",
"allow_in_bindings": 1,
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
},
{
"key": "field_669d49968fbc3",
"label": "Datum in",
Expand All @@ -141,13 +165,14 @@
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "27.5",
"width": "15",
"class": "",
"id": ""
},
"display_format": "d\/m\/Y",
"return_format": "d\/m\/Y",
"first_day": 1
"first_day": 1,
"allow_in_bindings": 1
},
{
"key": "field_669d49a58fbc4",
Expand All @@ -159,35 +184,54 @@
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "27.5",
"width": "15",
"class": "",
"id": ""
},
"display_format": "d\/m\/Y",
"return_format": "d\/m\/Y",
"first_day": 1
"first_day": 1,
"allow_in_bindings": 1
},
{
"key": "field_669d49c2261cd",
"label": "Seconden",
"name": "seconden",
"key": "field_671ab2972f163",
"label": "Dagen",
"name": "dagen",
"aria-label": "",
"type": "number",
"type": "checkbox",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "15",
"width": "30",
"class": "",
"id": ""
},
"default_value": 10,
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
"choices": {
"1": "ma",
"2": "di",
"3": "wo",
"4": "do",
"5": "vr",
"6": "za",
"7": "zo"
},
"default_value": [
"ma",
"di",
"wo",
"do",
"vr",
"za",
"zo"
],
"return_format": "value",
"allow_custom": 0,
"allow_in_bindings": 0,
"layout": "horizontal",
"toggle": 0,
"save_custom": 0,
"custom_choice_button_text": "Nieuwe keuze toevoegen"
}
],
"min": "",
Expand Down Expand Up @@ -320,5 +364,5 @@
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1727807462
"modified": 1729803241
}
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* Theme Name: Streekomroep
* Description: This is a WordPress theme made for Streekomroep ZuidWest in the Netherlands. It's made using Timber and Tailwind CSS and provides functionality for regional news, radio and television broadcasts.
* Author: Streekomroep ZuidWest
* Version: 1.10.0-beta5
* Version: 1.10.0-beta6
*/