I figured out how to display the group calendar embedded in a view:

$output = og_calendar_page($gid[0]);

However, if there are upcoming events for the next 4 months, this page will show monthly calendars for the next 4 months. How can I restrict this to show just the calendar for the current month?

Thanks!

Comments

darren oh’s picture

Category: support » feature
Status: Active » Postponed

There is no way to do this at this time. If you rewrite the module to allow it, please post a patch here.

somebodysysop’s picture

Basically, all I did was copy and edit og_calendar_page to get the current month. Take a look. If it looks ok, then I'll create a patch. Thanks.

/**
 * Modification - limited to current month ONLY
 *
 * views either all group events or a specific group's calendar
 */
function og_calendar_page_current($gid = NULL) {
  if ($gid) {
    $group = node_load($gid);
    $nodes = array();
    og_set_group_context($group);
    $bc[] = l(t('Home'), '');
    $bc[] = l(t('Groups'), 'og');
    $bc[] = l($group->title, "node/$gid");
    drupal_set_breadcrumb($bc);

    // Maintains group theme for og calendar view
  	og_set_theme($gid);

	// Basically, modified og_calendar_page and added code to get the parameters for the current month:

		// Get today's date in YYYY-MM-DD format.  This format is easiest for me to work with.
			$todays_date = date("Y-m-d", time()); 
		// Get todays year, month and day values
			list($year, $month, $day) = split("-", $todays_date);
		// The year to use for end date year;
			$next_year = $year;
		// The month to use for end date month;	
			$next_month = $month+1;
		// Check to make sure we update end date to next year if current month is 12	
			if ($next_month == 13) {
    	 		$next_month = 1;
      			$next_year = $year + 1;
			}
		// Make sure we put leading zero in if month < 10
			if ($next_month < 10) $next_month = '0' . $next_month;
		// Start date is the first of this month
			$start_date = $year . "-" . $month . "-01";
		// End date is the first of next month
			$end_date = $next_year . "-" . $next_month . "-01";
		// Now, we create the unix format start and end dates
  			$parts = explode("-",$start_date);
		  	$start_date_unix = mktime(12,0,0,$parts[1],$parts[2],$parts[0]);
  			$parts = explode("-",$end_date);
		  	$end_date_unix = mktime(12,0,0,$parts[1],$parts[2],$parts[0]);

    // View only events from this group limited by above timeframe (start date / end date)
    $sql = "SELECT e.nid, e.event_start, e.event_end FROM {event} e INNER JOIN {node} n ON n.nid = e.nid";
    $sql = db_rewrite_sql($sql, 'n', 'nid', array('og_nid' => $gid));
    $result = db_query($sql, $gid);
    while ($nid = db_fetch_object($result)) {
      $event = node_load($nid->nid);
	  // We need to get the event start date so we know how to set the timeframe;
		  $event_start = $nid->event_start;
		  $event_end = $nid->event_end;
      // Get only event nodes that fall within the timeframe
      	if ($event_start >= $start_date_unix && $event_start < $end_date_unix) {
      		if (isset($event->nid)) {
        		$nodes[$event->nid] = $event;
		      }
		  }
    	}
    if (count($nodes)) {
      $output = event_get_calendar('month', $nodes, 'og_calendar', t('@name calendar', array('@name' => $group->title)));
      $output .= theme('event_ical_link', 'event/ical/'. $node->filter);

      // Add RSS feed and icon to events page
      drupal_add_link(array(
        'rel' => 'alternate',
        'type' => 'application/rss+xml',
        'title' => t('RSS'),
        'href' => url('event/feed', NULL, NULL, TRUE)
      ));
      $output .= theme('feed_icon', url('event/feed'));

      return $output;
    }
    else {
      return t('No (visible) events for the @name group were found!', array('@name' => $group->title));
    }
  }
  else {
    // Redirect to the main event page
    drupal_goto('event');
  }
}
darren oh’s picture

I think the reason OG Calendar was left this way was that there are no back and forward buttons to allow past and future months to be browsed. If your patch provides these and it works, I'll accept it.

somebodysysop’s picture

StatusFileSize
new4.08 KB

Here is the og_calendar patch with allows viewing of single month as well as previous/next month paging. It works for me. Please let me know what you think.

You call it like this: /og_calendar_curr/

darren oh’s picture

Status: Postponed » Needs review
somebodysysop’s picture

That's

/og_calendar_curr/$gid

darren oh’s picture

StatusFileSize
new5.03 KB

Thanks for your work. I redid the patch as a replacement for og_calendar_page(). I also started working on only displaying previous and next links when there are events in past or future months. Have a look and see if you can improve it.

darren oh’s picture

Status: Needs review » Fixed

I got it working well enough to be committed. Fixed in CVS commit 62858.

Anonymous’s picture

Status: Fixed » Closed (fixed)