Events list - advance dates

8 posts by 2 authors in: Forums > CMS Builder
Last Post: May 20   (RSS)

I have a live stream function, so events are put into a list with a publishDate and removeDate, these have to be put in manually each week. Is there a way we can have an 'advance a week' button. This would advance every livestream event on by seven calendar days. This would reduce the need to manually advance each event (for both its start time and end time).

Thank you in advance.

Hi MercerDesign,

Yea, you could make a plugin for that.  

So you want to advance the publishDate and removeDate by a week for ALL the records in a section?  Is that right?

And why do you need to do that?  I'm wondering if there's a simpler solution.

Thanks!

Dave Edis - Senior Developer
interactivetools.com

Hi MercerDesign, 

Can you help me understand why they're updating those dates at all?  You have livestreams that repeat weekly and you want them shown at some times but not other times?  I'm just wondering if publish/removeDate is the best way to accomplish that.  Can you tell me more? 

Dave Edis - Senior Developer
interactivetools.com

They have files that are linked to the events, so they only want the file visible when each LiveStream is scheduled, so the Publish and Remove is timed to when the LiveStream is showing.

By Dave - May 19 - edited: May 19

Hi MercerDesign, 

Be sure to backup your database first, then you could try a script like this:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

// load viewer library
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = ['','../','../../','../../../','../../../../']; 
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// Increment dates by one week
$baseTable = "livestreams"; // don't include table prefix
$fields    = ['publishDate', 'removeDate'];

// Move date fields forward 7 days when date is defined
foreach ($fields as $field) {
    $query = "UPDATE `:table`
                 SET `:field` = DATE_ADD(`:field`, INTERVAL :increment WEEK)
               WHERE `:field` != :zeroDate AND `:field` IS NOT NULL";
    DB::query($query, [
        ':table'     => DB::getFullTable($baseTable),  // adds prefix if needed
        ':field'     => $field,
        ':increment' => 1,
        ':zeroDate'  => "0000-00-00 00:00:00",
    ]);
}

echo "All publish and remove dates have been incremented by one week.\n";

And then, if that works, add a link to it somewhere convenient in the CMS.  Note that you might need to update the "Load viewer library" code to match your server.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

Also, for anyone wanting to understand more about PHP, MySQL, or ZenDB (our database library).  If you go to chatgpt.com and select the o3 model, just paste in this query and it will explain it to you and answer any questions: 

Here's some code that uses https://github.com/interactivetools-com/ZenDB/
Can you explain it to me step by step.

[COPY/PASTE CODE HERE]

Dave Edis - Senior Developer
interactivetools.com

Thank you, that works.