1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
<?php
namespace hji\users\utils;
use \hji\common\utils\HTTP;
use \hji\users\abstracts\UserAdminTable;
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
class UserSearchesTable extends UserAdminTable
{
protected $baseUrl;
protected $dataModel;
protected $vars;
function __construct($sectionBaseUrl, $dataModel = false)
{
parent::__construct($sectionBaseUrl, $dataModel);
}
function getData()
{
$email = HTTP::getParameter('email');
$options = $this->getSearchOptions();
$result = $this->dataModel->searchSearches($email, $options);
if (isset($result->searches))
{
return $result;
}
else
{
return $this->resultError($result, $filters = null, $options);
}
}
function column_default($item, $column_name)
{
switch($column_name)
{
case 'name':
return $item->$column_name;
case 'market':
return strtoupper($item->$column_name);
case 'summary':
$output = '- N/A -';
if (!empty($item->$column_name))
{
$output = '';
foreach($item->$column_name as $filter)
{
$output .= '<div>' . esc_attr($filter->label) . ': ' . esc_attr($filter->value) . '</div>';
}
}
return $output;
case 'alerts':
return '<input class="alert-switch" value="' . $item->id . '" type="checkbox"' . checked(@$item->$column_name, true, false) . '>';
default:
return print_r($item, true) ;
}
}
function get_columns()
{
$columns = array(
'name' => __('Name', 'hji-users'),
'market' => __('Market', 'hji-users'),
'summary' => __('Search Criteria', 'hji-users'),
'alerts' => __('Alerts', 'hji-users'),
);
return $columns;
}
function get_sortable_columns()
{
$sortable_columns = array(
'name' => array('name',false),
'market' => array('market',false),
'alerts' => array('alerts',false),
);
return $sortable_columns;
}
function column_name($item)
{
$searchURL = (isset($item->searchUrl) && !empty($item->searchUrl)) ? esc_attr($item->searchUrl) : null;
$link = !is_null($searchURL) ? sprintf('<a href="%s" target="_blank">%s</a>', $searchURL, esc_attr($item->name)) : esc_attr($item->name);
$actions = array(
'delete' => sprintf('<a href="javascript:;" onclick="delSearch(\'%s\', \'%s\');">Delete</a>', $item->id, esc_attr($item->name))
);
return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
}
function prepare_items()
{
$data = $this->getData();
if (is_wp_error($data))
{
return $data;
}
$this->items = $data->searches;
$this->_column_headers = $this->get_column_info();
$pagination = array(
'total_items' => $data->total,
'total_pages' => $data->paging->count,
'per_page' => $data->paging->size,
);
$this->set_pagination_args($pagination);
}
function get_items_per_page( $option, $default = 50 )
{
return parent::get_items_per_page($option, $default);
}
}