function get_group_courseware($group_id = null)
 {
     if (!$group_id) {
         global $bp;
         $group_id = $bp->groups->current_group->id;
     }
     $group_data['bibliography'] = array();
     $group_data['responses_count'] = 0;
     $group_data['assignment_topics_count'] = 0;
     $group_data['user_grades'] = array();
     $group_data['courses'] = (array) BPSP_Courses::has_courses($group_id);
     $group_data['assignments'] = (array) BPSP_Assignments::has_assignments($group_id);
     $group_data['schedules'] = BPSP_Schedules::has_schedules($group_id);
     $posts = array_merge($group_data['courses'], $group_data['assignments']);
     if ($posts) {
         foreach ($posts as &$post) {
             // Get group bibs
             $group_data['bibliography'] = array_merge($group_data['bibliography'], BPSP_Bibliography::get_bibs($post->ID));
             // Get group responses
             if ($post->post_type == 'assignment') {
                 // Forum threads
                 if (get_post_meta($post->ID, 'topic_link', true) != '') {
                     $group_data['assignment_topics_count'] += 1;
                 }
                 // Responses
                 $post->responses = get_children(array('post_parent' => $post->ID, 'post_type' => 'response'));
                 $group_data['responses_count'] += count($post->responses);
                 // Gradebook
                 $group_data['user_grades'][] = BPSP_Gradebook::load_grade_by_user_id($post->ID, $bp->loggedin_user->id);
             }
         }
     }
     $group_data['bibliography_count'] = count($group_data['bibliography']);
     return $group_data;
 }
 /**
  * toICS()
  *
  * Outputs group schedules in ICS format
  */
 function toICS()
 {
     require_once BPSP_PLUGIN_DIR . '/schedules/iCalcreator.class.php';
     global $bp;
     define('ICAL_LANG', get_bloginfo('language'));
     $cal = new vcalendar();
     $cal->setConfig('unique_id', str_replace('http://', '', get_bloginfo('siteurl')));
     $cal->setConfig('filename', $bp->groups->current_group->slug);
     $cal->setProperty('X-WR-CALNAME', __('Calendar for: ', 'bpsp') . $bp->groups->current_group->name);
     $cal->setProperty('X-WR-CALDESC', $bp->groups->current_group->description);
     $cal->setProperty('X-WR-TIMEZONE', get_option('timezone_string'));
     $schedules = $this->has_schedules();
     $assignments = BPSP_Assignments::has_assignments();
     $entries = array_merge($assignments, $schedules);
     foreach ($entries as $entry) {
         setup_postdata($entry);
         $e = new vevent();
         if ($entry->post_type == "schedule") {
             $date = getdate(strtotime($entry->start_date));
         } elseif ($entry->post_type == "assignment") {
             $date = getdate(strtotime($entry->post_date));
         }
         $dtstart['year'] = $date['year'];
         $dtstart['month'] = $date['mon'];
         $dtstart['day'] = $date['mday'];
         $dtstart['hour'] = $date['hours'];
         $dtstart['min'] = $date['minutes'];
         $dtstart['sec'] = $date['seconds'];
         $e->setProperty('dtstart', $dtstart);
         $e->setProperty('description', get_the_content() . "\n\n" . $entry->permalink);
         if (!empty($entry->location)) {
             $e->setProperty('location', $entry->location);
         }
         if ($entry->post_type == "assignment") {
             $entry->end_date = $entry->due_date;
         }
         // make assignments compatible with schedule parser
         if (!empty($entry->end_date)) {
             $date = getdate(strtotime($entry->end_date));
             $dtend['year'] = $date['year'];
             $dtend['month'] = $date['mon'];
             $dtend['day'] = $date['mday'];
             $dtend['hour'] = $date['hours'];
             $dtend['min'] = $date['minutes'];
             $dtend['sec'] = $date['seconds'];
             $e->setProperty('dtend', $dtend);
         } else {
             $e->setProperty('duration', 0, 1, 0);
         }
         // Assume it's an one day event
         $e->setProperty('summary', get_the_title($entry->ID));
         $e->setProperty('status', 'CONFIRMED');
         $cal->setComponent($e);
     }
     header("HTTP/1.1 200 OK");
     die($cal->returnCalendar());
 }