id = $id;
$this->previewPopup = $popupPreviewId;
parent::__construct(array(
'singular'=> 'wp_'.$id, //singular label
'plural' => 'wp_'.$id.'s', //plural label
'ajax' => false
));
}
public function setId($id)
{
$this->id = $id;
}
public function setRowsPerPage($rowsPerPage)
{
$this->rowsPerPage = $rowsPerPage;
}
public function setColumns($columns)
{
$this->columns = $columns;
}
public function getColumns()
{
return $this->columns;
}
public function setDisplayColumns($displayColumns)
{
$this->displayColumns = $displayColumns;
}
public function setSortableColumns($sortableColumns)
{
$this->sortableColumns = $sortableColumns;
}
public function setTablename($tablename)
{
$this->tablename = $tablename;
}
public function setInitialSort($orderableColumns)
{
$this->initialOrder = $orderableColumns;
}
public function get_columns()
{
return $this->displayColumns;
}
public function setIsVisibleExtraNav($isVisibleExtraNav)
{
$this->isVisibleExtraNav = $isVisibleExtraNav;
}
public function getIsVisibleExtraNav()
{
return $this->isVisibleExtraNav;
}
public function getNavPopupsConditions()
{
return '';
}
public function prepare_items()
{
global $wpdb;
$table = $this->tablename;
$query = 'SELECT '.implode(', ', $this->columns).' FROM '.$table;
$this->customizeQuery($query);
$totalItems = count($wpdb->get_results($query)); //return the total number of affected rows
if ($this->previewPopup) {
$totalItems -= 1;
}
$perPage = $this->rowsPerPage;
$totalPages = ceil($totalItems/$perPage);
$orderby = isset($_GET['orderby']) ? sanitize_sql_orderby($_GET['orderby']) : 'ASC';
$order = isset($_GET['order']) ? sanitize_sql_orderby($_GET['order']) : '';
if (isset($this->initialOrder) && empty($order)) {
foreach ($this->initialOrder as $key => $value) {
$order = $value;
$orderby = $key;
}
}
if (!empty($orderby) && !empty($order)) {
$query .= ' ORDER BY '.$orderby.' '.$order;
}
$paged = isset($_GET["paged"]) ? (int)$_GET["paged"] : '';
if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
$paged = 1;
}
//adjust the query to take pagination into account
if (!empty($paged) && !empty($perPage)) {
$offset = ($paged - 1) * $perPage;
$query .= ' LIMIT '.(int)$offset.','.(int)$perPage;
}
$this->set_pagination_args(array(
"total_items" => $totalItems,
"total_pages" => $totalPages,
"per_page" => $perPage,
));
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$items = $wpdb->get_results($query, ARRAY_N);
/*Remove popup data when its class does not exist.*/
$this->customizeRowsData($items);
$this->items = $items;
}
public function customizeRowsData(&$items) {
}
public function get_sortable_columns() {
return $this->sortableColumns;
}
public function display_rows()
{
//get the records registered in the prepare_items method
$records = $this->items;
//get the columns registered in the get_columns and get_sortable_columns methods
list($columns, $hidden) = $this->get_column_info();
foreach($records as $key => $rec) {
echo '
';
$this->customizeRow($rec);
foreach ($rec as $k => $item) {
if (0 === $k) {
echo '
'.$item.'
';
} else {
echo '
'.stripslashes($item).'
';
}
}
echo '
';
}
}
public function customizeRow(&$row)
{
}
public function customizeQuery(&$query)
{
}
public function __toString()
{
$this->prepare_items(); ?>
getIsVisibleExtraNav();
if (!$isVisibleExtraNav) {
return '';
}
?>