public static function get($args = array(), &$total_row_count = null) { global $wpdb; $schedules = array(); $where = self::where_for_args($args); if (!empty($where)) { extract($args); if ($per_page) { $found_rows = 'SQL_CALC_FOUND_ROWS'; $limit = $wpdb->prepare('LIMIT %d, %d', ($page - 1) * $per_page, $per_page); } else { $limit = $found_rows = ''; } if ($next_email_time) { $order_by = 'next_email_time ASC'; } else { $order_by = 'start_time DESC'; } $results = (array) $wpdb->get_results("SELECT {$found_rows} * FROM " . self::$table_name . " WHERE {$where} ORDER BY {$order_by} {$limit}"); if ($found_rows) { $total_row_count = $wpdb->get_var('SELECT FOUND_ROWS()'); } $latest_reading_ids = array(); $plan_ids = array(); foreach ($results as $_schedule) { $schedule = new BfoxReadingSchedule($_schedule); $plan_ids[] = $schedule->plan_id; if ($cache_latest_readings) { $latest_reading_ids[$schedule->revision_id][] = (int) $schedule->latest_reading_id(); } $schedules[$_schedule->id] = $schedule; } unset($results); if (!empty($latest_reading_ids)) { $readings = BfoxReadingPlan::get_readings(array('reading_ids' => $latest_reading_ids)); foreach ($schedules as $schedule) { $schedule->latest_reading($readings[$schedule->revision_id]); } } BfoxReadingPlan::cache('schedule', $schedules); BfoxReadingPlan::cache_plan_ids($plan_ids); } return array_keys($schedules); }