示例#1
0
 /** Get all Products */
 public static function get_all($orderby, $order, $pagenum, $per_page, $dm, $ft)
 {
     global $wpdb;
     $limit = ($pagenum - 1) * $per_page;
     $query = 'SELECT * FROM ' . self::table_name . ' ';
     // filtering
     $filter = '';
     if ($dm != '0') {
         $current_time = date("Y-m-d h:i a");
         $local_time = strtotime($current_time) + intval(get_option('gmt_offset')) * 60 * 60;
         $start_date = date('Y-m-d', $local_time);
         list($year, $month, $day) = explode('-', $start_date);
         if ($dm == 'last_month') {
             $month = intval($month) - 1;
         } elseif ($dm == 'last_month_3') {
             $month = intval($month) - 3;
         } elseif ($dm == 'last_month_6') {
             $month = intval($month) - 6;
         } elseif ($dm == 'last_year') {
             $year = intval($year) - 1;
         }
         if ($month <= 0) {
             $month = intval($month) + 12;
             $year = $year - 1;
         }
         $compare_date = sprintf("%04d-%02d-00", $year, $month);
         $filter .= "where date >= '{$compare_date}' ";
     }
     if ($ft != '0') {
         if ($dm != '0') {
             $filter .= "and status = '{$ft}' ";
         } else {
             $filter .= "where status = '{$ft}' ";
         }
     }
     $query1 = 'Select count(*) from ' . self::table_name . ' ' . $filter;
     self::$found_count = $wpdb->get_var($query1);
     $query .= $filter;
     $query .= 'ORDER BY ' . $orderby . ' ' . $order . ' ';
     $query .= 'LIMIT ' . $limit . ',' . $per_page . ';';
     $results = $wpdb->get_results($query, ARRAY_A);
     if (!is_array($results)) {
         $results = array();
         self::$found_count = 0;
         return $results;
     }
     return $results;
 }