2 // $Id: event_database.mysqli.inc,v 1.15 2008/06/30 22:34:46 killes Exp $
9 function event_get_event_load($nid) {
11 $shift = variable_get('date_default_timezone', 0);
13 return db_fetch_object(db_query('SELECT e.event_start, e.event_end, e.timezone, e.has_time, e.has_end_date, tz.offset AS offset, tz.offset_dst AS offset_dst, tz.dst_region, tz.is_dst, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_start_utc, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_end_utc, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_user, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_user, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_site, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_site, tz.name as timezone_name FROM {event} e INNER JOIN {event_timezones} tz ON tz.timezone = e.timezone WHERE nid = %d', (isset($user->timezone) ? $user->timezone : 0), (isset($user->timezone) ? $user->timezone : 0), $shift, $shift, $nid));
17 * @param $first start date
18 * @param $last end date
19 * @param Whether to order the result set on the starting date.
20 * Valid values: FALSE, 'DESC', 'ASC'
21 * @param $rewrite_parameter optional array that is merged into the
22 * fourth argument of db_rewrite_sql.
24 * @return database resource
26 function event_get_events_user($first, $last, $order, $rewrite_parameter = array()) {
28 $shift = variable_get('date_default_timezone', 0);
29 $before_first = event_implode_date(event_date_later(event_explode_date($first), -1));
30 $after_last = event_implode_date(event_date_later(event_explode_date($last), 1));
32 $query = "SELECT n.nid, n.uid, n.title, n.type, e.event_start AS event_start_orig, e.event_end AS event_end_orig, e.timezone, e.has_time, e.has_end_date, tz.offset AS offset, tz.offset_dst AS offset_dst, tz.dst_region, tz.is_dst, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_start_utc, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_end_utc, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_user, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_user, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_site, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_site, tz.name as timezone_name FROM {node} n INNER JOIN {event} e ON n.nid = e.nid INNER JOIN {event_timezones} tz ON tz.timezone = e.timezone WHERE n.status = 1 AND ((e.event_start >= '%s' AND e.event_start <= '%s') OR (e.event_end >= '%s' AND e.event_end <= '%s') OR (e.event_start <= '%s' AND e.event_end >= '%s')) GROUP BY n.nid HAVING (event_start >= '%s' AND event_start <= '%s') OR (event_end >= '%s' AND event_end <= '%s') OR (event_start <= '%s' AND event_end >= '%s')";
36 $query .= " ORDER BY event_start DESC";
39 $query .= " ORDER BY event_start ASC";
43 $timezone = (isset($user->timezone) ? $user->timezone : 0);
44 return db_query(db_rewrite_sql($query, 'n', 'nid', array_merge(array('event' => TRUE, 'event_get_events' => TRUE, 'event_get_events_user' => TRUE), $rewrite_parameter)), $timezone, $timezone, $timezone, $timezone, $shift, $shift, $before_first, $after_last, $before_first, $after_last, $before_first, $after_last, $first, $last, $first, $last, $first, $last);
48 * @param $first start date
49 * @param $last end date
50 * @param Whether to order the result set on the starting date.
51 * Valid values: FALSE, 'DESC', 'ASC'
52 * @param $rewrite_parameter optional array that is merged into the
53 * fourth argument of db_rewrite_sql.
55 * @return database resource
57 function event_get_events_site($first, $last, $order, $rewrite_parameter = array()) {
58 $shift = variable_get('date_default_timezone', 0);
59 $before_first = event_implode_date(event_date_later(event_explode_date($first), -1));
60 $after_last = event_implode_date(event_date_later(event_explode_date($last), 1));
62 $query = "SELECT n.nid, n.uid, n.title, n.type, e.event_start AS event_start_orig, e.event_end AS event_end_orig, e.timezone, e.has_time, e.has_end_date, tz.offset AS offset, tz.offset_dst AS offset_dst, tz.dst_region, tz.is_dst, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_start_utc, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_end_utc, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_user, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_user, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_site, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_site, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end, tz.name as timezone_name FROM {node} n INNER JOIN {event} e ON n.nid = e.nid INNER JOIN {event_timezones} tz ON tz.timezone = e.timezone WHERE n.status = 1 AND ((e.event_start >= '%s' AND e.event_start <= '%s') OR (e.event_end >= '%s' AND e.event_end <= '%s') OR (e.event_start <= '%s' AND e.event_end >= '%s')) GROUP BY n.nid HAVING (event_start >= '%s' AND event_start <= '%s') OR (event_end >= '%s' AND event_end <= '%s') OR (event_start <= '%s' AND event_end >= '%s')";
66 $query .= " ORDER BY event_start DESC";
69 $query .= " ORDER BY event_start ASC";
73 $timezone = (isset($user->timezone) ? $user->timezone : 0);
74 return db_query(db_rewrite_sql($query, 'n', 'nid', array_merge(array('event' => TRUE, 'event_get_events' => TRUE, 'event_get_events_site' => TRUE), $rewrite_parameter)), $timezone, $timezone, $shift, $shift, $shift, $shift, $before_first, $after_last, $before_first, $after_last, $before_first, $after_last, $first, $last, $first, $last, $first, $last);
78 * @param $first start date
79 * @param $last end date
80 * @param Whether to order the result set on the starting date.
81 * Valid values: FALSE, 'DESC', 'ASC'
82 * @param $rewrite_parameter optional array that is merged into the
83 * fourth argument of db_rewrite_sql.
85 * @return database resource
87 function event_get_events_event($first, $last, $order, $rewrite_parameter = array()) {
89 $shift = variable_get('date_default_timezone', 0);
90 $before_first = event_implode_date(event_date_later(event_explode_date($first), -1));
91 $after_last = event_implode_date(event_date_later(event_explode_date($last), 1));
93 $query = "SELECT n.nid, n.uid, n.title, n.type, e.event_start, e.event_start AS event_start_orig, e.event_end, e.event_end AS event_end_orig, e.timezone, e.has_time, e.has_end_date, tz.offset AS offset, tz.offset_dst AS offset_dst, tz.dst_region, tz.is_dst, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_start_utc, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND AS event_end_utc, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_user, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_user, e.event_start - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_start_site, e.event_end - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND AS event_end_site, tz.name as timezone_name FROM {node} n INNER JOIN {event} e ON n.nid = e.nid INNER JOIN {event_timezones} tz ON tz.timezone = e.timezone WHERE n.status = 1 AND ((e.event_start >= '%s' AND e.event_start <= '%s') OR (e.event_end >= '%s' AND e.event_end <= '%s') OR (e.event_start <= '%s' AND e.event_end >= '%s')) GROUP BY n.nid HAVING (event_start >= '%s' AND event_start <= '%s') OR (event_end >= '%s' AND event_end <= '%s') OR (event_start <= '%s' AND event_end >= '%s')";
97 $query .= " ORDER BY event_start DESC";
100 $query .= " ORDER BY event_start ASC";
104 $timezone = (isset($user->timezone) ? $user->timezone : 0);
105 return db_query(db_rewrite_sql($query, 'n', 'nid', array_merge(array('event' => TRUE, 'event_get_events' => TRUE, 'event_get_events_event' => TRUE), $rewrite_parameter)), $timezone, $timezone, $shift, $shift, $before_first, $after_last, $before_first, $after_last, $before_first, $after_last, $first, $last, $first, $last, $first, $last);
109 * @param $time current date
110 * @param $limit number of returned events
111 * @param $types The node types to get. If none given, all
112 * event-enabled types will be retrieved that are configured to show
113 * up in all calendars.
114 * @param $rewrite_parameter optional array that is merged into the
115 * fourth argument of db_rewrite_sql.
117 * @return database resource
119 function event_get_events_upcoming($time, $types, $limit, $rewrite_parameter = array()) {
120 $placeholders = implode(',', array_fill(0, count($types), "'%s'"));
121 $query = "SELECT n.nid, n.uid, n.title, n.type, n.status, n.changed, e.event_start, e.event_end, e.timezone, e.has_time, e.has_end_date, TIMEDIFF(e.event_start, '%s') AS time_left, DATEDIFF(e.event_start, '%s') AS days_left FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND (((e.event_start <> e.event_end) AND ('%s' >= e.event_start AND '%s' < e.event_end)) OR ((e.event_start = e.event_end) AND ('%s' <= e.event_start + INTERVAL %d SECOND)) OR e.event_start >= '%s') AND n.type IN ($placeholders) ORDER BY event_start";
122 return db_query_range(db_rewrite_sql($query, 'n', 'nid', array_merge(array('event' => TRUE, 'event_get_events' => TRUE, 'event_get_events_upcoming' => TRUE, 'event_types' => $types), $rewrite_parameter)), array_merge(array($time, $time, $time, $time, $time, (60 * 60 * 2), $time), $types), 0, $limit);
127 * @ingroup event_support
128 * @param $type either 'start' or 'end'
130 function event_where_user($type = 'start') {
136 $timezone = (isset($user->timezone) ? $user->timezone : 0);
137 return str_replace('%d', (int) $timezone, "(e.event_$type - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND)");
143 * @ingroup event_support
144 * @param $type either 'start' or 'end'
146 function event_where_utc($type = 'start') {
152 return "(e.event_$type - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND)";
158 * @ingroup event_support
159 * @param $type either 'start' or 'end'
161 function event_where_site($type = 'start') {
165 return str_replace('%d', (int) variable_get('date_default_timezone', 0), "(e.event_$type - INTERVAL IF(tz.is_dst, tz.offset_dst, tz.offset) HOUR_SECOND + INTERVAL %d SECOND)");
171 * @ingroup event_support
172 * @param $type either 'start' or 'end'
174 function event_where_event($type = 'start') {
180 return "e.event_$type";