function add_events(&$query) { foreach ($query->posts as $p) { if (empty($p->ec3_schedule)) { continue; } $begin_datetime = $this->begin_dateobj->to_mysqldate(); foreach ($p->ec3_schedule as $event) { $dob = ec3_mysql2date(max($event->start, $begin_datetime)); // Find $limit_dob - the day after the end of this event. $limit_dob = ec3_mysql2date($event->end); $limit_dob->increment_day(); if ($this->limit_dateobj->less_than($limit_dob)) { $limit_dob = $this->limit_dateobj; } // Loop over all the days of this event. for (; $dob->less_than($limit_dob); $dob->increment_day()) { $day =& $this->_get_day($dob->to_mysqldate()); $day->add_event($event); } } } }
/** Generates an array of all 'ec3_Day's between the start of * begin_month & end_month. Indexed by day_id. * month_id is in the form: ec3_<year_num>_<month_num> */ function ec3_util_calendar_days($begin_month_id, $end_month_id) { $begin_date = date('Y-m-d 00:00:00', ec3_dayid2php($begin_month_id)); $end_date = date('Y-m-d 00:00:00', ec3_dayid2php($end_month_id)); global $ec3, $wpdb; $sql = "SELECT DISTINCT\r\n id,\r\n post_title,\r\n GREATEST(start,'{$begin_date}') AS start_date,\r\n LEAST(end,'{$end_date}') AS end_date,\r\n allday,\r\n 1 AS is_event\r\n FROM {$wpdb->posts},{$ec3->schedule}\r\n WHERE post_status='publish'\r\n AND post_type='post'\r\n AND post_id=id\r\n AND end>='{$begin_date}'\r\n AND start<'{$end_date}'"; if (!$ec3->show_only_events) { // We are interested in normal posts, as well as events. $sql = "( {$sql} ) UNION\r\n ( SELECT DISTINCT\r\n id,\r\n post_title,\r\n post_date AS start_date,\r\n post_date AS end_date,\r\n 0 AS allday,\r\n 0 AS is_event\r\n FROM {$wpdb->posts}\r\n WHERE post_status='publish'\r\n AND post_type='post'\r\n AND post_date>='{$begin_date}'\r\n AND post_date<'{$end_date}'\r\n AND post_date<NOW()\r\n )"; } $sql .= ' ORDER BY id, allday DESC, start_date, is_event DESC'; $calendar_entries = $wpdb->get_results($sql); $calendar_days = array(); // result if (!$calendar_entries) { return $calendar_days; } // In advanced mode, we don't want to show events as blog posts in the cal. $ignore_post_ids = array(); if ($ec3->advanced && !$ec3->show_only_events) { foreach ($calendar_entries as $ent) { if ($ent->is_event) { $ignore_post_ids[] = $ent->id; } } } $current_post_id = 0; $current_day_id = ''; $time_format = get_option('time_format'); $allday = str_replace(' ', ' ', __('all day', 'ec3')); // #160==nbsp foreach ($calendar_entries as $ent) { if (!$ent->is_event && in_array($ent->id, $ignore_post_ids)) { continue; } if ($current_post_id != $ent->id) { $current_post_id = $ent->id; $current_day_id = ''; } $date = ec3_mysql2date($ent->start_date); $end_date = ec3_mysql2date($ent->end_date); while (true) { $day_id = $date->day_id(); if ($current_day_id == $day_id) { break; } $current_day_id = $day_id; if (empty($calendar_days[$day_id])) { $calendar_days[$day_id] = new ec3_Day(); } if ($ent->allday) { $time = $allday; } else { $time = mysql2date($time_format, $ent->start_date); } //?? Should only record start time on FIRST day. $calendar_days[$day_id]->add_post($ent->post_title, $time, $ent->is_event); if ($date->to_unixdate() == $end_date->to_unixdate()) { break; } $date->increment_day(); } } return $calendar_days; }