Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mgm_coupon_used_users($coupon_id = NULL){
- global $wpdb;
- @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '2048M' ) );
- $users = array();
- if(!is_null($coupon_id)){
- $start = 0;
- $limit = 1000;
- $qry = "SELECT count(DISTINCT {$wpdb->users}.ID) ";
- $qry .= "FROM {$wpdb->users} ";
- $qry .= "INNER JOIN {$wpdb->usermeta} ON ( {$wpdb->users}.ID = {$wpdb->usermeta}.user_id ) ";
- $qry .= "INNER JOIN {$wpdb->usermeta} AS mt1 ON ( {$wpdb->users}.ID = mt1.user_id ) ";
- $qry .= "INNER JOIN {$wpdb->usermeta} AS mt2 ON ( {$wpdb->users}.ID = mt2.user_id ) ";
- $qry .= "WHERE 1 = 1 AND (({$wpdb->usermeta}.meta_key = '_mgm_user_register_coupon' AND CAST( {$wpdb->usermeta}.meta_value AS UNSIGNED ) = '{$coupon_id}') ";
- $qry .= "OR (mt1.meta_key = '_mgm_user_upgrade_coupon' AND CAST( mt1.meta_value AS UNSIGNED ) = '{$coupon_id}') ";
- $qry .= "OR (mt2.meta_key = '_mgm_user_extend_coupon' AND CAST( mt2.meta_value AS UNSIGNED ) = '{$coupon_id}')) ";
- $count = $wpdb->get_var($qry);
- if($count) {
- // read again
- for( $i = $start; $i < $count; $i = $i + $limit ) {
- $users = array_merge($users, (array)mgm_patch_partial_coupon_used_users($i, $limit, $coupon_id));
- //a small delay of 0.01 second
- usleep(10000);
- }
- }
- }
- return $users;
- }
- /**
- * patch partial coupon used users
- */
- function mgm_patch_partial_coupon_used_users($start, $limit,$coupon_id = NULL) {
- global $wpdb;
- $results = array();
- if(!is_null($coupon_id)){
- $qry = "SELECT DISTINCT SQL_CALC_FOUND_ROWS {$wpdb->users}.ID, {$wpdb->users}.display_name, {$wpdb->users}.user_email, {$wpdb->users}.user_login, ";
- $qry .= "(SELECT t.meta_value FROM {$wpdb->usermeta} t WHERE t.user_id = {$wpdb->users}.ID AND t.meta_key = 'mgm_member_options') mgm_member_options ";
- $qry .= "FROM {$wpdb->users} ";
- $qry .= "INNER JOIN {$wpdb->usermeta} ON ( {$wpdb->users}.ID = {$wpdb->usermeta}.user_id ) ";
- $qry .= "INNER JOIN {$wpdb->usermeta} AS mt1 ON ( {$wpdb->users}.ID = mt1.user_id ) ";
- $qry .= "INNER JOIN {$wpdb->usermeta} AS mt2 ON ( {$wpdb->users}.ID = mt2.user_id ) ";
- $qry .= "WHERE 1 = 1 AND (({$wpdb->usermeta}.meta_key = '_mgm_user_register_coupon' AND CAST( {$wpdb->usermeta}.meta_value AS UNSIGNED ) = '{$coupon_id}') ";
- $qry .= "OR (mt1.meta_key = '_mgm_user_upgrade_coupon' AND CAST( mt1.meta_value AS UNSIGNED ) = '{$coupon_id}') ";
- $qry .= "OR (mt2.meta_key = '_mgm_user_extend_coupon' AND CAST( mt2.meta_value AS UNSIGNED ) = '{$coupon_id}')) ";
- $qry .= "ORDER BY user_login ASC LIMIT ". $start.",".$limit;
- $results = $wpdb->get_results($qry);
- return $results;
- }
- return $results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement