Skip to content

Commit

Permalink
Merge pull request #21 from No3x/search
Browse files Browse the repository at this point in the history
Implemented gh-19 search functionality. Closes gh-19
  • Loading branch information
No3x committed Oct 7, 2014
2 parents a263800 + 3d65339 commit 83540fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
22 changes: 17 additions & 5 deletions WPML_Email_Log_List.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function __construct() {
* @see WP_List_Table::no_items()
*/
function no_items() {
_e( 'No ' . $this->_args['singular'] . ' logged yet.' );
_e( 'No ' . $this->_args['singular'] . ' found.' );
return;
}

Expand Down Expand Up @@ -84,9 +84,10 @@ function get_hidden_columns() {
/**
* Prepares the items for rendering
* @since 1.0
* @param string you want to search for
* @see WP_List_Table::prepare_items()
*/
function prepare_items() {
function prepare_items( $search = false ) {
global $wpdb;
$tableName = WPML_Plugin::getTablename( 'mails' );

Expand All @@ -99,16 +100,27 @@ function prepare_items() {

$per_page = $this->get_items_per_page( 'per_page', 25 );
$current_page = $this->get_pagenum();
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM `$tableName`" );
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM `$tableName`;" );

//TODO: make option for default order
$orderby_default = "mail_id";
$order_default = "desc";
$orderby = ( !empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : $orderby_default;
$order = ( !empty($_GET['order'] ) ) ? $_GET['order'] : $order_default;
$offset = ( $current_page-1 ) * $per_page;

$dataset = $wpdb->get_results( "SELECT * FROM `$tableName` ORDER BY $orderby $order LIMIT $per_page OFFSET $offset", ARRAY_A);
$search_query = '';
if( $search ) {
$search = esc_sql( sanitize_text_field( $search ) );
$search_query = sprintf( "
WHERE
(`receiver` LIKE '%%%1\$s%%') OR
(`subject` LIKE '%%%1\$s%%') OR
(`message` LIKE '%%%1\$s%%') OR
(`headers` LIKE '%%%1\$s%%') OR
(`attachments` LIKE '%%%1\$s%%')", $search );
}

$dataset = $wpdb->get_results( "SELECT * FROM `$tableName` $search_query ORDER BY $orderby $order LIMIT $per_page OFFSET $offset;", ARRAY_A);

$this->set_pagination_args( array(
'total_items' => $total_items, // the total number of items
Expand Down
11 changes: 6 additions & 5 deletions WPML_OptionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,7 @@ public function LogMenu() {
?>
<div class="wrap">
<h2><?php echo $this->getPluginDisplayName(); echo ' '; _e('Log', 'wpml'); ?></h2>
<?php
$emailLoggingListTable = new Email_Logging_ListTable();
$emailLoggingListTable->prepare_items();
?>


<div id="wp-mail-logging-modal-wrap">
<div id="wp-mail-logging-modal-backdrop"></div>
<div id="wp-mail-logging-modal-content-wrap">
Expand Down Expand Up @@ -415,7 +411,12 @@ public function LogMenu() {

<form id="email-list" method="get">
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />

<?php
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : false;
$emailLoggingListTable = new Email_Logging_ListTable();
$emailLoggingListTable->prepare_items( $search );
$emailLoggingListTable->search_box( __( 'Search' ), 's' );
$emailLoggingListTable->display();
?>
</form>
Expand Down

0 comments on commit 83540fa

Please sign in to comment.