/**
  * Get search results based on query.
  *
  * @todo Needs to be updated to handle the AJAX requests.
  *
  */
 function prepare_items($wp_crm_search = false)
 {
     global $role, $usersearch;
     if (!isset($this->all_items)) {
         $this->all_items = WP_CRM_F::user_search($wp_crm_search);
     }
     //** Get User IDs */
     foreach ($this->all_items as $object) {
         $this->user_ids[] = $object->ID;
     }
     //** Do pagination  */
     if ($this->_args['per_page'] != -1) {
         $this->item_pages = array_chunk($this->all_items, $this->_args['per_page']);
         $total_chunks = count($this->item_pages);
         //** figure out what page chunk we are on based on iDisplayStart
         $this_chunk = $this->_args['iDisplayStart'] / $this->_args['per_page'];
         //** Get page items */
         $this->items = $this->item_pages[$this_chunk];
         if (is_array($this->items)) {
             foreach ($this->items as $object) {
                 $this->page_user_ids[] = $object->ID;
             }
         }
     } else {
         $this->items = $this->all_items;
     }
 }
Exemple #2
0
 /**
  * Loads currently requested user into global variable
  *
  * Ran on admin_init. Currently only applicable to the user profile page in order to load metaboxes early based on available user data.
  *
  * @since 0.1
  *
  */
 static function csv_export($wp_crm_search = '')
 {
     global $wpdb, $wp_crm;
     //** Export filename */
     $file_name = "wp-crm-export-" . date("Y-m-d") . ".csv";
     //** Get table columns to know what is NOT meta data */
     $table_columns = $wpdb->get_col("SHOW COLUMNS FROM {$wpdb->users}");
     //** Get users in order to filter */
     $results = WP_CRM_F::user_search($wp_crm_search);
     //** Build CSV cols */
     foreach ($wp_crm['data_structure']['attributes'] as $_attr_key => $attr_data) {
         $display_columns[$_attr_key] = $attr_data['title'];
     }
     //** Loop users */
     foreach ($results as $result) {
         //** Get data of table cols */
         $primary = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID = {$result->ID}", ARRAY_A);
         //** Flush */
         $user = array();
         //** Loop data attributes */
         foreach ($wp_crm['data_structure']['attributes'] as $_attr_key => $attr_data) {
             //** If key is from table cols - just use it's value */
             if (in_array($_attr_key, $table_columns)) {
                 $value = $primary[$_attr_key];
             } else {
                 //** Otherwice - if attribute has options then process it is an array of values */
                 if (!empty($attr_data['has_options'])) {
                     //** Flush */
                     $values = array();
                     //** Loop options key */
                     foreach ($attr_data['option_keys'] as $option_key => $meta_key) {
                         //** If something found as checked/selected */
                         if ($v = get_user_meta($result->ID, $meta_key, true)) {
                             //** If type of attribute is text but it has options  */
                             if ($attr_data['input_type'] === 'text') {
                                 //** Use both values to not confuse */
                                 $values[] = $attr_data['option_labels'][$option_key] . ' (' . $v . ')';
                             } else {
                                 //** Otherwice - just use label of option since we need only it */
                                 $values[] = $attr_data['option_labels'][$option_key];
                             }
                         }
                     }
                     //** Implode with comma all stuff we found chacked or selected */
                     $value = implode(',', $values);
                 } else {
                     //** If doen't have options then just use meta value */
                     $value = get_user_meta($result->ID, $_attr_key, true);
                 }
             }
             $user[$_attr_key] = $value;
         }
         $users[] = $user;
     }
     header("Content-type: application/csv");
     header("Content-Disposition: attachment; filename={$file_name}");
     header("Pragma: no-cache");
     header("Expires: 0");
     echo implode(',', $display_columns) . "\n";
     foreach ($users as $user) {
         unset($this_row);
         foreach ($display_columns as $meta_key => $meta_label) {
             $this_row[] = '"' . $user[$meta_key] . '"';
         }
         echo implode(",", $this_row) . "\n";
     }
 }
 /**
  * Loads currently requested user into global variable
  *
  * Ran on admin_init. Currently only applicable to the user profile page in order to load metaboxes early based on available user data.
  *
  * @since 0.1
  *
  */
 static function csv_export($wp_crm_search = '')
 {
     global $wpdb, $wp_crm;
     $file_name = "wp-crm-export-" . date("Y-m-d") . ".csv";
     $meta_keys = $wp_crm['data_structure']['meta_keys'];
     $primary_columns = $wpdb->get_col("SHOW COLUMNS FROM {$wpdb->users}");
     $results = WP_CRM_F::user_search($wp_crm_search);
     foreach ($results as $result) {
         $primary = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID = {$result->ID}", ARRAY_A);
         foreach ($meta_keys as $meta_key => $meta_label) {
             $meta_key_labels[] = $meta_label;
             if (in_array($meta_key, $primary_columns)) {
                 $value = $primary[$meta_key];
             } else {
                 $value = get_user_meta($result->ID, $meta_key, true);
             }
             if (!empty($value)) {
                 $display_columns[$meta_key] = $meta_label;
             }
             $user[trim($meta_key)] = trim($value);
         }
         $users[] = $user;
     }
     header("Content-type: application/csv");
     header("Content-Disposition: attachment; filename={$file_name}");
     header("Pragma: no-cache");
     header("Expires: 0");
     echo implode(',', $display_columns) . "\n";
     foreach ($users as $user) {
         unset($this_row);
         foreach ($display_columns as $meta_key => $meta_label) {
             $this_row[] = '"' . $user[$meta_key] . '"';
         }
         echo implode(",", $this_row) . "\n";
     }
 }
Exemple #4
0
 /**
  * Get search results based on query.
  *
  * @todo user_search() should be removed from here since this is a "general" function
  *
  */
 function prepare_items($wp_crm_search = false, $args = array())
 {
     $args = wp_parse_args($args, array('order_by' => 'user_registered', 'sort_order' => 'DESC'));
     if (!isset($this->all_items)) {
         $this->all_items = WP_CRM_F::user_search($wp_crm_search, $args);
     }
     //** Do pagination  */
     if ($this->_args['per_page'] != -1) {
         $this->item_pages = array_chunk($this->all_items, $this->_args['per_page']);
         //** figure out what page chunk we are on based on iDisplayStart
         $this_chunk = $this->_args['iDisplayStart'] / $this->_args['per_page'];
         //** Get page items */
         $this->items = !empty($this->item_pages[$this_chunk]) ? $this->item_pages[$this_chunk] : array();
     } else {
         $this->items = $this->all_items;
     }
 }
 /**
  * Get search results based on query.
  *
  * @todo Needs to be updated to handle the AJAX requests.
  *
  */
 function prepare_items($wp_crm_search = false, $args = array())
 {
     global $role, $usersearch;
     $args = wp_parse_args($args, array('order_by' => 'user_registered', 'sort_order' => 'DESC'));
     if (!isset($this->all_items)) {
         $this->all_items = WP_CRM_F::user_search($wp_crm_search, $args);
     }
     //** Get User IDs */
     foreach ($this->all_items as $object) {
         $this->user_ids[] = $object->ID;
     }
     //** Do pagination  */
     if ($this->_args['per_page'] != -1) {
         $this->item_pages = array_chunk($this->all_items, $this->_args['per_page']);
         $total_chunks = count($this->item_pages);
         //** figure out what page chunk we are on based on iDisplayStart
         $this_chunk = $this->_args['iDisplayStart'] / $this->_args['per_page'];
         //** Get page items */
         $this->items = !empty($this->item_pages[$this_chunk]) ? $this->item_pages[$this_chunk] : array();
         if (is_array($this->items)) {
             foreach ($this->items as $object) {
                 $this->page_user_ids[] = $object->ID;
             }
         }
     } else {
         $this->items = $this->all_items;
     }
 }