We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Help with ajax/json api countdown

How Do I?

jaygreentree's avatar
jaygreentree
9 posts
3 years ago
jaygreentree's avatar jaygreentree

I’m currently building/rebuilding a church website. I have a decent understanding of EE and how it works. My question: I need to make a date field repeat weekly but am not sure if this is possible. I have managed to get far enough to have a channel for this that can be edited manually during development: the json code I am currently using is below

{exp:channel:entries channel="countdown" orderby="date" sort="desc" show_future_entries="no" limit="1"} 
{"meta": {"status": 200 }, "response": {"item": {"isLive": false, "eventStartTime": "{event_start_time format="%Y-%m-%d %g:%i:%s"}" }}}
{/exp:channel:entries}

If this requires a paid add-on that is currently not an option.

       
Rob Allen's avatar
Rob Allen
3,105 posts
3 years ago
Rob Allen's avatar Rob Allen

The only addon I know that can handle repeating events is the Calendar module - https://expressionengine.com/add-ons/calendar - not cheap but may solve your problem.

       
jaygreentree's avatar
jaygreentree
9 posts
3 years ago
jaygreentree's avatar jaygreentree

Thanks Rob unfortunately that is not an option. It is a great plugin though.

I did have a thought but not sure if it can be converted to EE code. On an old website I did using Rock RMS I was able to create a webrequest that could pull from an existing api. The code from that can be found on Github:

This allowed for the data to be cached in the database for Rock saving the need for constant requests to the api

       
Andy McCormick's avatar
Andy McCormick
322 posts
3 years ago
Andy McCormick's avatar Andy McCormick

@jaygreentree did you ever get anywhere with this? Happy to help, but I’m not grasping what you would what the final output to be after a few weeks.

       
jaygreentree's avatar
jaygreentree
9 posts
3 years ago
jaygreentree's avatar jaygreentree

Andy this is for a countdown. I’m trying to automate the json data to repopulate for the same time/day each week (Sunday at 10am MST). the output example

{ "meta": { "status": 200 }, "response": { "item": { "isLive": false, "eventStartTime": "2022-03-06 10:00:00" } } }

Currently I’m using a content channel but that requires manually editing. My template code is on github if you’re willing to take a look

       
Andy McCormick's avatar
Andy McCormick
322 posts
3 years ago
Andy McCormick's avatar Andy McCormick

When do you want this to update to the next date. For example if it currently returns 2022-03-06 10:00:00 then when would you want it to return 2022-03-13 10:00:00 ?

I would probably just write an add-on that uses either a text file or database table to store the last date. Then check that date compared to the current time. if the difference is X then update to show the next Sunday’s time and update the time stamp in your text file or database.

       
jaygreentree's avatar
jaygreentree
9 posts
3 years ago
jaygreentree's avatar jaygreentree

Services would be 10am-12pm between those times the countdown shows a link to the livestream. (if communication would be easier I am on the eecms slack.) I appreciate your time/assistance.

       
lucusdam's avatar
lucusdam
2 posts
one year ago
lucusdam's avatar lucusdam

While ExpressionEngine doesn’t offer built-in functionality to automatically repeat dates in channels, here are a couple of approaches you can consider without paid add-ons:

1. Manual Updates:

This approach is best for a limited number of repeating events. You can manually create entries with the desired dates throughout the week. This might be suitable for a small church calendar with few recurring events.

2. Template Logic with a Scheduled Task:

This method involves more technical steps but automates date updates:

  • Template Logic:

    • Modify your template to handle future dates. Instead of directly displaying {event_start_time}, create a conditional statement that checks if the date is within the current week.
    • If the date falls within the current week, display it as usual. Otherwise, you can display a message like “Coming Up” or leave the space blank.
  • Scheduled Task:

    • Use a server-side scheduling tool (like cron jobs) to run a script periodically (e.g., daily).
    • This script can update the event_start_time field in your channel entries for the following week. You can achieve this using the ExpressionEngine Channel API or a custom script interacting with your database.

Here’s a basic outline of the script logic:

php
// Get the current date and calculate the beginning of the next week
$today = new DateTime();
$nextWeekStart = $today->modify('next sunday');

// Fetch existing entries for the "countdown" channel
$entries = // Fetch entries using Channel API

// Loop through entries and update dates for next week
foreach ($entries as $entry) {
  $newDate = $entry->event_start_time->add(new DateInterval('P7D')); // Add 7 days
  if ($newDate >= $nextWeekStart) {
    // Update the entry's event_start_time with the new date
    $entry->update(array('event_start_time' => $newDate));
  }
}

Remember:

  • This approach requires some development knowledge and server-side scripting capabilities.
  • Ensure proper error handling and security measures in your script.
  • Consider testing the script thoroughly before deploying it on your live site.

If these approaches seem too complex, you might explore community Geometry Dash forums or consult ExpressionEngine development resources for alternative solutions or potential free add-ons that might align with your requirements.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.