Use new code style
This commit is contained in:
@ -40,19 +40,21 @@ class Customer_List_Table extends Base_List_Table {
|
||||
'list' => __('List View'),
|
||||
);
|
||||
|
||||
$args = wp_parse_args($args, array(
|
||||
'singular' => __('Customer', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Customers', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_customer'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
));
|
||||
$args = wp_parse_args(
|
||||
$args,
|
||||
array(
|
||||
'singular' => __('Customer', 'wp-ultimo'), // singular name of the listed records
|
||||
'plural' => __('Customers', 'wp-ultimo'), // plural name of the listed records
|
||||
'ajax' => true, // does this table support ajax?
|
||||
'add_new' => array(
|
||||
'url' => wu_get_form_url('add_new_customer'),
|
||||
'classes' => 'wubox',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct($args);
|
||||
|
||||
} // end __construct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the extra search field when the search element is present.
|
||||
@ -66,46 +68,40 @@ class Customer_List_Table extends Base_List_Table {
|
||||
|
||||
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : false;
|
||||
|
||||
if (!empty($search)) {
|
||||
if ( ! empty($search)) {
|
||||
|
||||
// Search relevant users
|
||||
$user_ids = get_users(array(
|
||||
'number' => -1,
|
||||
'search' => '*' . $search . '*',
|
||||
'fields' => 'ids',
|
||||
));
|
||||
$user_ids = get_users(
|
||||
array(
|
||||
'number' => -1,
|
||||
'search' => '*' . $search . '*',
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
// No results, go back
|
||||
if (empty($user_ids)) {
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// Finally, include these user IDs in the customers query.
|
||||
$_filter_fields['user_id__in'] = $user_ids;
|
||||
|
||||
unset($_filter_fields['search']);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$_filter_fields['type'] = 'customer';
|
||||
|
||||
if (wu_request('filter', 'all') === 'vip') {
|
||||
|
||||
$_filter_fields['vip'] = 1;
|
||||
|
||||
} elseif (wu_request('filter', 'all') === 'online') {
|
||||
|
||||
$_filter_fields['last_login_query'] = array(
|
||||
'after' => '-3 minutes',
|
||||
);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $_filter_fields;
|
||||
|
||||
} // end get_extra_query_fields;
|
||||
}
|
||||
/**
|
||||
* Displays the content of the name column.
|
||||
*
|
||||
@ -123,21 +119,26 @@ class Customer_List_Table extends Base_List_Table {
|
||||
);
|
||||
|
||||
// Check if user exists
|
||||
if (!$user) {
|
||||
|
||||
if ( ! $user) {
|
||||
$actions = array(
|
||||
'delete' => sprintf('<a title="%s" class="wubox" href="%s">%s</a>', __('Delete', 'wp-ultimo'), wu_get_form_url('delete_modal', $url_atts), __('Delete', 'wp-ultimo')),
|
||||
);
|
||||
|
||||
return sprintf('<strong>#%s</strong> - %s', $item->get_user_id(), __('User not found', 'wp-ultimo')) . $this->row_actions($actions);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$customer_id = sprintf('<a href="?page=wp-ultimo-edit-customer&id=%s"><strong>#%s</strong></a>', $item->get_id(), $item->get_id());
|
||||
|
||||
$customer_user = sprintf('<a href="%s">%s</a>', wu_network_admin_url('wp-ultimo-edit-customer', array(
|
||||
'id' => $item->get_id(),
|
||||
)), $user->display_name);
|
||||
$customer_user = sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
wu_network_admin_url(
|
||||
'wp-ultimo-edit-customer',
|
||||
array(
|
||||
'id' => $item->get_id(),
|
||||
)
|
||||
),
|
||||
$user->display_name
|
||||
);
|
||||
|
||||
// Concatenate the two blocks
|
||||
$title = "<strong>$customer_user</strong>";
|
||||
@ -159,7 +160,7 @@ class Customer_List_Table extends Base_List_Table {
|
||||
'delete_modal',
|
||||
array(
|
||||
'model' => 'customer',
|
||||
'id' => $item->get_id()
|
||||
'id' => $item->get_id(),
|
||||
)
|
||||
),
|
||||
__('Delete', 'wp-ultimo')
|
||||
@ -169,8 +170,7 @@ class Customer_List_Table extends Base_List_Table {
|
||||
$actions = array_filter($actions);
|
||||
|
||||
return $title . $desc . $this->row_actions($actions);
|
||||
|
||||
} // end column_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the customer photo and special status.
|
||||
@ -185,20 +185,23 @@ class Customer_List_Table extends Base_List_Table {
|
||||
$html = '<div class="wu-status-container">';
|
||||
|
||||
if ($item->is_vip()) {
|
||||
|
||||
$html .= sprintf('<span class="wu-tag wu-customer-vip">%s</span>', __('VIP', 'wp-ultimo'));
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
$html .= get_avatar($item->get_user_id(), 36, 'identicon', '', array(
|
||||
'force_display' => true,
|
||||
));
|
||||
$html .= get_avatar(
|
||||
$item->get_user_id(),
|
||||
36,
|
||||
'identicon',
|
||||
'',
|
||||
array(
|
||||
'force_display' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
} // end column_customer_status;
|
||||
}
|
||||
/**
|
||||
* Returns the number of memberships owned by this customer.
|
||||
*
|
||||
@ -220,8 +223,7 @@ class Customer_List_Table extends Base_List_Table {
|
||||
);
|
||||
|
||||
return $subscription_count . $this->row_actions($actions);
|
||||
|
||||
} // end column_memberships;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of columns for this particular List Table.
|
||||
@ -242,8 +244,7 @@ class Customer_List_Table extends Base_List_Table {
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
||||
} // end get_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the item display for grid mode.
|
||||
@ -255,12 +256,14 @@ class Customer_List_Table extends Base_List_Table {
|
||||
*/
|
||||
public function single_row_grid($item) {
|
||||
|
||||
wu_get_template('base/customers/grid-item', array(
|
||||
'item' => $item,
|
||||
'table' => $this,
|
||||
));
|
||||
|
||||
} // end single_row_grid;
|
||||
wu_get_template(
|
||||
'base/customers/grid-item',
|
||||
array(
|
||||
'item' => $item,
|
||||
'table' => $this,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filters for this page.
|
||||
@ -269,46 +272,46 @@ class Customer_List_Table extends Base_List_Table {
|
||||
*/
|
||||
public function get_filters(): array {
|
||||
|
||||
$filters = $this->get_schema_columns(array(
|
||||
'searchable' => true,
|
||||
'date_query' => true,
|
||||
), 'or');
|
||||
$filters = $this->get_schema_columns(
|
||||
array(
|
||||
'searchable' => true,
|
||||
'date_query' => true,
|
||||
),
|
||||
'or'
|
||||
);
|
||||
|
||||
$labels = $this->get_columns();
|
||||
|
||||
$filters = array_map(function($item) use ($labels) {
|
||||
$filters = array_map(
|
||||
function ($item) use ($labels) {
|
||||
|
||||
$label = wu_get_isset($labels, $item->name);
|
||||
$label = $label ? sprintf('%s (%s)', $item->label, $item->name) : $item->name;
|
||||
$label = wu_get_isset($labels, $item->name);
|
||||
$label = $label ? sprintf('%s (%s)', $item->label, $item->name) : $item->name;
|
||||
|
||||
$filter_type = 'text';
|
||||
$rule = 'is';
|
||||
$filter_type = 'text';
|
||||
$rule = 'is';
|
||||
|
||||
if ($item->date_query === true) {
|
||||
if ($item->date_query === true) {
|
||||
$filter_type = 'date';
|
||||
$rule = 'is_after';
|
||||
} elseif (in_array(strtolower((string) $item->name), array('smallint'), true)) {
|
||||
$filter_type = 'bool';
|
||||
$rule = 'is_true';
|
||||
}
|
||||
|
||||
$filter_type = 'date';
|
||||
$rule = 'is_after';
|
||||
|
||||
} elseif (in_array(strtolower((string) $item->name), array('smallint'), true)) {
|
||||
|
||||
$filter_type = 'bool';
|
||||
$rule = 'is_true';
|
||||
|
||||
} // end if;
|
||||
|
||||
return array(
|
||||
'field' => $item->name,
|
||||
'label' => $label,
|
||||
'type' => $filter_type,
|
||||
'rule' => $rule,
|
||||
'value' => wu_request($item->name, ''),
|
||||
);
|
||||
|
||||
}, $filters);
|
||||
return array(
|
||||
'field' => $item->name,
|
||||
'label' => $label,
|
||||
'type' => $filter_type,
|
||||
'rule' => $rule,
|
||||
'value' => wu_request($item->name, ''),
|
||||
);
|
||||
},
|
||||
$filters
|
||||
);
|
||||
|
||||
return array_values($filters);
|
||||
|
||||
} // end get_filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pre-selected filters on the filter bar.
|
||||
@ -321,9 +324,11 @@ class Customer_List_Table extends Base_List_Table {
|
||||
return array(
|
||||
'all' => array(
|
||||
'field' => 'filter',
|
||||
'url' => add_query_arg(array(
|
||||
'filter' => 'all'
|
||||
)),
|
||||
'url' => add_query_arg(
|
||||
array(
|
||||
'filter' => 'all',
|
||||
)
|
||||
),
|
||||
'label' => __('All Customers', 'wp-ultimo'),
|
||||
'count' => 0,
|
||||
),
|
||||
@ -340,8 +345,7 @@ class Customer_List_Table extends Base_List_Table {
|
||||
'count' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the last login.
|
||||
@ -354,13 +358,9 @@ class Customer_List_Table extends Base_List_Table {
|
||||
public function column_last_login($item) {
|
||||
|
||||
if ($item->is_online()) {
|
||||
|
||||
return '<span class="wu-inline-block wu-mr-1 wu-rounded-full wu-h-2 wu-w-2 wu-bg-green-500"></span>' . __('Online', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $this->_column_datetime($item->get_last_login());
|
||||
|
||||
} // end column_last_login;
|
||||
|
||||
} // end class Customer_List_Table;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user