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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
<?php
namespace hji\users\utils;
use \hji\common\utils\HTTP;
use \hji\users\abstracts\UserAdminTable;
use \hji\users\controllers\Settings;
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
class UserListTable extends UserAdminTable
{
public $data;
function __construct($sectionBaseUrl, $dataModel = false)
{
parent::__construct($sectionBaseUrl, $dataModel);
$this->setViews();
}
function getData()
{
$options = $this->getSearchOptions();
$keyword = HTTP::getParameter('s');
$options['keyword'] = ($keyword) ? $keyword : array();
$options['summary'] = true;
if ($this->get('timeframe'))
{
$options['createdDate'] = $this->get('timeframe');
}
$result = $this->dataModel->searchUsers($options);
if (isset($result->users))
{
return $result;
}
else
{
return $this->resultError($result, $filters = null, $options);
}
}
function column_default($item, $column_name)
{
switch($column_name)
{
case 'name':
return sprintf('<a href="?page=%s&action=%s&email=%s">%s</a>', $_REQUEST['page'],'view', $item['email'], $item['name']);
break;
case 'email':
return $item[$column_name];
break;
case 'phone':
return (isset($item[$column_name])) ? $item[$column_name] : 'N/A';
case 'totalFavorites':
case 'totalOffMarket':
case 'totalSearches':
return (isset($item[$column_name])) ? $item[$column_name] : 0;
case 'createdDate':
case 'lastActive':
if (isset($item[$column_name]) && !empty($item[$column_name]))
{
return \hji\common\utils\WPHelper::toDateTime($item[$column_name]);
}
return 'N/A';
default:
return print_r($item, true) ;
}
}
function get_columns()
{
$columns = array(
'name' => __('Name', 'hji-users'),
'email' => __('Email', 'hji-users'),
'phone' => __('Phone', 'hji-users'),
'totalFavorites' => __('Favorites', 'hji-users'),
'totalOffMarket' => __('Off Market', 'hji-users'),
'totalSearches' => __('Saved Searches', 'hji-users'),
'createdDate' => __('Registered', 'hji-users'),
'lastActive' => __('Last Active', 'hji-users'),
);
return $columns;
}
function get_sortable_columns()
{
$sortable_columns = array(
'name' => array('name',false),
'email' => array('email',false),
'createdDate' => array('createdDate',false),
'lastActive' => array('lastActive',false),
);
return $sortable_columns;
}
function column_name($item)
{
$viewUrl = Settings::sectionUrl(array(
'action' => 'view',
'email' => $item['email'],
'tab' => 'user'
));
$editUrl = Settings::sectionUrl(array(
'action' => 'edit',
'email' => $item['email'],
'tab' => 'user'
));
$deleteUrl = Settings::sectionUrl(array(
'action' => 'delete',
'email' => $item['email']
));
$actions = array(
'edit' => sprintf('<a href="%s">Edit</a>',$editUrl),
'delete' => sprintf('<a href="%s" onclick=\'return confirm("Are you sure you want to delete this user: %s (%s)?");\'>Delete</a>', wp_nonce_url($deleteUrl, 'deleteUser_' . $item['email']), $item['name'], $item['email']),
);
$img = (isset($item['attributes']['Profile']['photo']) && !empty($item['attributes']['Profile']['photo'])) ?
'<div class="hji-user-photo" style="background-image: url(' . $item['attributes']['Profile']['photo'] . ')"></div>': '';
$name = (!empty($item['name'])) ? $item['name'] : 'Anonymous';
$link = sprintf('<a href="%s">%s<strong>%s</strong></a>', $viewUrl, $img, $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 = json_decode(json_encode($data->users), true);
$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);
}
}