diff -upNr og_calendar/og_calendar.info drupal-5.1/modules/og_calendar/og_calendar.info --- og_calendar/og_calendar.info 1970-01-01 01:00:00.000000000 +0100 +++ drupal-5.1/modules/og_calendar/og_calendar.info 2007-01-30 02:34:43.000000000 +0000 @@ -0,0 +1,5 @@ +; $Id: og_calendar.info$ +name = Organic groups calendars +description = Displays a calendar for groups. +dependencies = og event +package = Organic groups diff -upNr og_calendar/og_calendar.module drupal-5.1/modules/og_calendar/og_calendar.module --- og_calendar/og_calendar.module 2006-09-12 17:47:31.000000000 +0100 +++ drupal-5.1/modules/og_calendar/og_calendar.module 2007-02-07 23:38:03.000000000 +0000 @@ -80,6 +80,65 @@ function og_calendar_page($gid = NULL) { } +function og_calendar_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $block[0]["info"] = t('Group Events'); + return $block; + } else if ($op == 'view') { + $time = time() - (2 * 60 * 60); + $limit = 6; + if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) { + $node = node_load(arg(1)); + } + if ($node->type == 'group') { + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.type, n.status, n.moderate, n.changed, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid INNER JOIN {node_access} node_access ON node_access.nid = e.nid INNER JOIN {og} og on og.nid = node_access.gid WHERE og.nid = %d AND n.status = 1 AND n.moderate = 0 AND e.event_start >= %d ORDER BY event_start'), array($node->nid, $time)); + while (($node = db_fetch_object($result)) && $limit) { + $minutesleft = floor(($node->event_start - time()) / 60); + if ($minutesleft < 0) { + $timeleft = t('NOW'); + } + else if ($minutesleft < 60) { + $timeleft = format_plural($minutesleft, '1 minute', '@count minutes'); + } + else if ($minutesleft >= 60 && $minutesleft < (24 * 60)) { + $timeleft = format_plural(floor($minutesleft / 60), '1 hour', '@count hours'); + } + else if ($minutesleft >= (24 * 60)) { + $days = floor($minutesleft / (24 * 60)); + // hours remainder + $hours = ($minutesleft % (24 * 60)) / 60; + // hours left in the day + $hours_left = 24 - date('G', time()); + // see if the remainder of hours on the event date is greater than the hours left in today, if so increase the days by one so that the days remaining mimics the date rather than how many 24 hour periods there are between now and then. + if ($hours > $hours_left) { + $days++; + } + $timeleft = format_plural($days, '1 day', '@count days'); + } + $node->timeleft = $timeleft; + $ctype = module_invoke('flexinode', 'load_content_type', substr($node->type, 10)); + $node->typename = ($ctype->name ? $ctype->name : $node->type); + if ($node->status) { + $items[] = theme('event_upcoming_item', $node); + $limit--; + } + } + if(!$items) { + $items[] = t('No upcoming events available'); + } + $output = theme('event_upcoming_block', $items); + $output .= theme('event_more_link', 'og_calendar/'.arg(1)); + if ($output == '') { + // no group events + return; + } + $block['subject'] = 'Group events'; + $block['content'] = $output; + return $block; + } + } +} + /** * Implementation of hook_og_create_links(). */