News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

ssi_recentEvents list issues

Started by jeff260z, July 30, 2008, 12:10:38 AM

Previous topic - Next topic

jeff260z

I'm using the ssi_recentEvents to list the upcoming events from my calender. I'd like the list to generate the closest event first followed by the next event by event date. I can't seem to get it to list in anything but most recent posted event first.

This is my code.

$eventlist = ssi_recentEvents(7, 'array');echo '<ul>';foreach ($eventlist as $mday => $array){  foreach ($array as $event)  {    echo '<li>', $event['start_date'] , ' - ' , $event['link'];    if ($event['can_edit'])      echo ' <a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';  }}
?>

[SiNaN]

That function just gets the evet that is happenning in the day you are.

This modification should do the trick:

Find and delete:

cal.startDate <= '" . strftime('%Y-%m-%d', forum_time(false)) . "'
AND


Find:

ORDER BY cal.startDate DESC

Replace:

ORDER BY cal.startDate ASC

I suggest you copying the function, changing its name and then making the changes on the one you've copied so that it wouldn't cause difficulties in upgrading.
Former SMF Core Developer | My Mods | SimplePortal

jeff260z

Do I have to modify the ssi.php or can I some how do this with modifying my code on my page?

[SiNaN]

Former SMF Core Developer | My Mods | SimplePortal

jeff260z

#4
So I copy the ssi_recentEvents function and rename it then call it in my code from my webpage?

Why wouldn't this function do this out of the box? Logically you would want the closest event to be listed first and the furthest event away to be listed last or do I not understand the function?

ccbtimewiz

Quote from: jeff260z on July 31, 2008, 08:17:57 PM
So I copy the ssi_recentEvents function and rename it then call it in my code from my webpage?

Edit it in ssi.php, then require() it in your php document. Then parse it out with echo()

jeff260z

So I copy this

// Show the most recent events.
function ssi_recentEvents($max_events = 7, $output_method = 'echo')
{
global $db_prefix, $user_info, $scripturl, $modSettings, $txt, $sc, $ID_MEMBER;

// Find all events which are happening in the near future that the member can see.
$request = db_query("
SELECT
cal.ID_EVENT, cal.startDate, cal.endDate, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, t.ID_FIRST_MSG
FROM {$db_prefix}calendar AS cal
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = cal.ID_BOARD)
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = cal.ID_TOPIC)
WHERE cal.endDate >= '" . strftime('%Y-%m-%d', forum_time(false)) . "'
AND (cal.ID_BOARD = 0 OR $user_info[query_see_board])
ORDER BY cal.startDate DESC
LIMIT $max_events", __FILE__, __LINE__);
$return = array();
$duplicates = array();
while ($row = mysql_fetch_assoc($request))
{
// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
if (!empty($duplicates[$row['title'] . $row['ID_TOPIC']]))
continue;

// Censor the title.
censorText($row['title']);

if ($row['startDate'] < strftime('%Y-%m-%d', forum_time(false)))
$date = strftime('%Y-%m-%d', forum_time(false));
else
$date = $row['startDate'];

$return[$date][] = array(
'id' => $row['ID_EVENT'],
'title' => $row['title'],
'can_edit' => allowedTo('calendar_edit_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('calendar_edit_own')),
'modify_href' => $scripturl . '?action=' . ($row['ID_BOARD'] == 0 ? 'calendar;sa=post;' : 'post;msg=' . $row['ID_FIRST_MSG'] . ';topic=' . $row['ID_TOPIC'] . '.0;calendar;') . 'eventid=' . $row['ID_EVENT'] . ';sesc=' . $sc,
'href' => $row['ID_BOARD'] == 0 ? '' : $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => $row['ID_BOARD'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['title'] . '</a>',
'start_date' => $row['startDate'],
'end_date' => $row['endDate'],
'is_last' => false
);

// Let's not show this one again, huh?
$duplicates[$row['title'] . $row['ID_TOPIC']] = true;
}
mysql_free_result($request);

foreach ($return as $mday => $array)
$return[$mday][count($array) - 1]['is_last'] = true;

if ($output_method != 'echo' || empty($return))
return $return;

// Well the output method is echo.
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4'] . '</span> ';
foreach ($return as $mday => $array)
foreach ($array as $event)
{
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';

echo '
' . $event['link'] . (!$event['is_last'] ? ', ' : '');
}
}


and paste it to the SSI.php and rename it say as ssi_recentEvents_ASC and make the changes you suggested.

Then in my webpage code call it like this

$eventlist = ssi_recentEvents_ASC(7, 'array');echo '<ul>';foreach ($eventlist as $mday => $array){  foreach ($array as $event)  {    echo '<li>', $event['start_date'] , ' - ' , $event['link'];    if ($event['can_edit'])      echo ' <a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';  }}?>

jeff260z


ok I copied and renamed the ssi_recentEvents function and renamed it to ssi_recentEvents_ASC then just changed

ORDER BY cal.startDate DESC

to

ORDER BY cal.startDate ASC

I didn't delete the

cal.startDate <= '" . strftime('%Y-%m-%d', forum_time(false)) . "' AND

Code. It seems to be working fine. Is it necessary to delete this code?

ccbtimewiz

If it working fine for you, there is no need to alter the code further.  :)

jeff260z

Thanks guys. Really appreciate the feedback and help.

[SiNaN]

Not at all, you're welcome. Marked the topic as solved. ;)
Former SMF Core Developer | My Mods | SimplePortal

Advertisement: