private static function where_for_args($args) { global $wpdb; extract($args); $wheres = array(); $owner_where = self::owner_where_for_args($args); if (!empty($owner_where)) { $wheres[] = $owner_where; } // Specific IDs if (!empty($id)) { $wheres[] = 'id IN (' . implode(',', (array) $wpdb->escape($id)) . ')'; } // Specific Plan IDs if (!empty($plan_id)) { $wheres[] = 'plan_id IN (' . implode(',', (array) $wpdb->escape($plan_id)) . ')'; } // Filters if ($filter) { $filter = '%' . like_escape($filter) . '%'; $wheres[] = $wpdb->prepare("(label LIKE %s OR note LIKE %s)", $filter, $filter); } // Next Email Time if ($next_email_time) { $wheres[] = $wpdb->prepare('0 < next_email_time AND next_email_time <= %d', $next_email_time); } // Date if ($date) { if (is_array($date)) { list($start_date, $end_date) = $date; $start_time = BfoxReadingSchedule::time($start_date); $end_time = BfoxReadingSchedule::time($end_date); $wheres[] = $wpdb->prepare("((start_time BETWEEN %d AND %d) OR (end_time BETWEEN %d AND %d) OR (%d BETWEEN start_time AND end_time) OR (%d BETWEEN start_time AND end_time))", $start_time, $end_time, $start_time, $end_time, $start_time, $end_time); } else { // Check if the date starts after the start time and before the end time // The end time is adjusted by one day so that if it ends on that day, it will still return $time = self::time($date); $wheres[] = $wpdb->prepare('(start_time <= %d AND %d <= end_time)', $time, $time - 24 * 60 * 60); } } return implode(' AND ', $wheres); }