I have my events stored in the “projects” folder. Each folder have a date_from and date_to fields. Now I want to get every dates between these two dates.
Example : for the project A from 01.02.2017 to 03.02.2017, I want to get this : 01.02.2017/02.02.2017/03.02.2017.
After that, some project can have only one date, for exemple from 01.02.2017 to 01.02.2017
My final project consist to link these values to the calendar plugin by Bastien instead of using the MolocLab plugin calendar (that is not necessary for my back end).
My feeling is that I could use a “controller” system (like filters) but I don’t know how to.
Thank you. I found an elegant solution with DatePeriod (PHP > 5.3)
<?php
$begin = new DateTime($project->date_from('Y-m-d') );
$end = new DateTime($project->date_to('Y-m-d'));
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
foreach ( $period as $dt )
echo $dt->format( "Y-m-d" );
?>
I could get every duration between two dates.
How can I store them to display into my calendar ? Like a filtering system, do I need to build a controller ? I just want to get every events by clicking on the day link of my calendar
I must admit that I don’t quite understand what you mean. There seem to be two things, one is storing the dates (but you have already stored the dates, haven’t you) and the other filtering.
Sorry my fault. I understood I had to change $day to $date
I changed to <a href="<?php echo url('/' . url::paramsToString(['date' => $day])) ?>"> but it has the same effect.
The $day variable, as previously, produce the correct URL, but it doens’t return the correct project with my actual controller. Every projects are still contained into every dates.
Hi,
I would like to ask you a last question about this excellent script. To achieve my project, I have to redirect my page by default to the date of today.
Does a default parameter already exist for this case ?
I’m using the script from texnixe bellow, and the bastian calendar plugin. Inside, an active class already activate the date of today, How can I use it ?