1
I noticed that the Upcoming 30 day events block would show repeating events more than once and that the sort order looked odd. The get_thisMonth_events function in minical.php seems to be the source of the problem. The original version performed the following steps:
1 - query agendax_events
2 - load results into the event array
3 - query agendax_event_repeats
4 - append the second query results onto the event array
Here are the problems that I see. The repeating events show up in both queries, hence the duplicates. The second query wasn't sorted by date. The appending places non-repeating events before repeating events.
My change retrieves all events in a single step that are sorted by date. Here is my updated logic:
function get_thisMonth_events() {
global $xoopsDB;
$events = array();
$ONE_DAY = 86400;
$userTimestamp = xoops_getUserTimestamp(time());
$date = date("Ymd", $userTimestamp);
$date30days = date("Ymd", $userTimestamp+30*$ONE_DAY);
$query = 'SELECT id, title, date FROM '.$xoopsDB->prefix("agendax_events").' LEFT JOIN '.$xoopsDB->prefix("agendax_event_repeats").' ON id=event_id'.' WHERE approved=1 AND (event_end=0 OR event_end is NULL OR event_end <='.$date30days.') AND date<='.$date30days.' ORDER BY date ASC';
$result = $xoopsDB->queryF($query);
$numrows = $xoopsDB->getRowsNum($result);
while ( $row = $xoopsDB->fetchArray($result) ) {
$events[] = $row;
}
return $events;
}
There are other functions in minical.php that follow the same logic. I updated them as well.
FYI, the original query had 'event_end=NULL' in it. This does not work as expected as it evaluates to null, not true or false. 'event_end is null' will return true if the column contains a null. Nulls in SQL are tricky this way!
wjue, thanks for putting Agenda-x out in the community. It is a great module.