When it comes down to it, I have no clue how to work with dates other than storing and retrieving them from a database. I'm trying to make a page that displays all the events for the week categorized by the day of the week. When It's all said and done it should look something like this:
Previous Week Next Week
+------------------------------+
| Monday, June 8 |
+------------------------------+
9:00am - Event 1
10:00am - Event 2
+------------------------------+
| Tuesday, June 9 |
+------------------------------+
9:00am - Event 3
10:00am - Event 4
//...
+------------------------------+
| Sunday, June 14 |
+------------------------------+
9:00am - Event 13
10:00am - Event 14
Here's what I have done so far:
I have this DataObject:
class Events extends DataObject {
private static $db = array (
'EventTitle' => 'Varchar',
'EventDate' => 'Date',
'EventTime' => 'Time'
)
//...
I have this php file:
//...
class CalendarPage_Controller extends Page_Controller {
private $StartDate = //should default to today's date;
private function SetStartDateToMonday() {
//While $StartDate != Monday
//$StartDate--
}
public function getDates() {
SetStartDateToMonday();
return array(
//$StartDate,
//$StartDate + 1,
//$StartDate + 2,
//$StartDate + 3,
//$StartDate + 4,
//$StartDate + 5,
//$StartDate + 6
)
}
public function getEvents($date) {
return Events::get()
->filter(array(
'EventDate' => $date //I don't know if this will work or not
))
->sort(array(
'EventTime' => 'asc'
));
}
public function PreviousWeek(SS_HTTPRequest $request) {
//$startDate = $request->param('ID') - 1week
}
public function NextWeek(SS_HTTPRequest $request) {
//$startDate = $request->param('ID') + 1week
}
}
I have this template page:
//...
<a href="PreviousWeek/"<!-- This page's StartDate -->>Previous Week</a>
<a href="NextWeek/<!-- This page's StartDate -->">Next Week</a>
<% Loop getDates() %>
<h5><!-- $me variable if that is correct --></h5>
<table>
<% Loop getEvents(<!-- $me -->) %>
<tr>
<td>$EventTime.Nice</td>
<td>$EventTitle</td>
</tr>
<% End_Loop >
</table>
<% End_Loop >
As you can see my Controller class is a mess. I have a general idea how to make things work but I'm getting caught up in my lack of knowledge on PHP/Silverstripe functions and syntax. I've tried cutting it down to the bare bones to just make a list of dates using a start date of today and having no events and couldn't make that work. I've tried just listing events for today's date and that hasn't worked. I've been working on this for days looking at the Silverstripe API/documentation googling questions, and looking over Date() and DateTime() code from PHP, and event Date and SS_DateTime from Silverstripe and I'm flat out stuck and overwhelmed. I would love some input/ideas to help me out.
I know there are modules out there that I can use to accomplish what I want; but I'm still trying to learn the ins and outs of Silverstripe so that's why I'm going through all this fuss. Thanks for the help!