public function controls() { global $wpdb; $inc_obj = new q2w3_include_obj($this->plugin_id); // count number of sub filters $count_filters = $wpdb->get_results('SELECT count(DISTINCT ' . $inc_obj->status->col_name . ') FROM ' . $inc_obj->table(), ARRAY_N); if ($count_filters[0][0]) { $count_filters = $count_filters[0][0]; } else { return false; } // if no data to be filtered return false // Add additional 'Select All' sub filter $filters['all'] = __('All', $this->plugin_id); $filters += $inc_obj->status->input_values; $count_filters++; $i = 0; $res = ''; if (key_exists(self::VAR_NAME, $_GET)) { $cur_filter = $_GET[self::VAR_NAME]; } else { $cur_filter = false; } foreach ($filters as $filter_key => $filter_name) { // sub filter cycle $condition = 'WHERE ' . $inc_obj->status->col_name . ' = ' . $filter_key; if ($filter_key == 'all') { $condition = false; } // total records for sub filter $count = $wpdb->get_results('SELECT count(*) FROM ' . $inc_obj->table() . ' ' . $condition, ARRAY_N); if ($count[0][0] > 0) { $i++; if ($i < $count_filters) { $separator = '|'; } else { $separator = ''; } $link = q2w3_table_func::change_qstring(self::VAR_NAME, $filter_key); // change filter id $link = $_SERVER['PHP_SELF'] . '?' . q2w3_table_func::change_qstring(q2w3_table_page_filter::VAR_NAME, '', $link); // reset page to number 1 if ($cur_filter == $filter_key || !$cur_filter && $filter_key == 'all') { $selected = ' class="current"'; } else { $selected = false; } $res .= '<div style="float: left"><a href="' . $link . '"' . $selected . '>' . $filter_name . ' <span class="count">(' . $count[0][0] . ')</span></a>' . $separator . '</div>' . PHP_EOL; } } if ($res) { $ul = '<div class="subsubsub">' . PHP_EOL; $ul .= $res; $ul .= '</div>' . PHP_EOL; $ul .= '<div style="clear: left;"></div>' . PHP_EOL; $this->inc_obj = $inc_obj; $this->filters = $filters; } return $ul; }
/** * @param integer $page Current page number in a cycle * @param integer $cur_page Current page selected by user * @param string $var_name $_GET variable name * @return string Button html */ protected function page_button($page, $cur_page, $var_name) { if ($page == $cur_page) { $res = '<span class="page-numbers current">' . $page . '</span> '; } else { $res = '<a class="page-numbers" href="?' . q2w3_table_func::change_qstring($var_name, $page) . '">' . $page . '</a> '; } return $res; }
/** * Returns table rows html * * @return string */ protected function table_rows() { $columns = $this->get_columns_names(); $col_num = count($columns); array_unshift($columns, 'id'); $columns = implode(',', $columns); $where = false; if (is_array($this->filters)) { foreach ($this->filters as $filter) { if ($filter_sql = $filter->sql()) { $where[] = $filter->sql(); } } $where = @implode(' AND ', $where); if ($where) { $where = 'WHERE ' . $where; } } if ($this->group_by) { $group_by = 'GROUP BY ' . $this->group_by; } else { $group_by = false; } if ($this->order_by) { $order_by = 'ORDER BY ' . $this->order_by; } else { $order_by = false; } $conditions = 'FROM ' . $this->object->table() . ' ' . $where . ' ' . $group_by . ' ' . $order_by; if ($this->enable_page_filter) { $this->page_filter = new q2w3_table_page_filter($this->plugin_id); $limit_start = $this->page_filter->cur_page() * $this->rows_per_page - $this->rows_per_page; $limit = 'LIMIT ' . $limit_start . ',' . $this->rows_per_page; $tmp_rows = $this->wpdb->get_results('SELECT count(*) ' . $conditions, ARRAY_N); $this->total_rows = $tmp_rows[0][0]; } $data = $this->wpdb->get_results('SELECT ' . $columns . ' ' . $conditions . ' ' . $limit, ARRAY_A); //status, location, priority if (!empty($data)) { if (count($data) == 1 && $this->page_filter->cur_page() == ceil($this->total_rows / $this->rows_per_page)) { $this->last_record = true; } $i = 0; $res = ''; foreach ($data as $row) { $this->object->load_values_from_array($row, 'db2text'); $row_id = $this->object->id->val; $i++; if ($i & 1) { $class = 'class="alternate"'; } else { $class = false; } $res .= '<tr ' . $class . '>' . PHP_EOL; if ($this->enable_bulk_actions) { $res .= '<th scope="row" class="check-column"><input type="checkbox" name="checked[' . $row_id . ']" value="" class="q2w3_table_checkbox" /></th>' . PHP_EOL; $col_num++; } $propertie_link = get_option('siteurl') . '/wp-admin/admin.php'; foreach ($this->object as $propertie => $definition) { if ($definition->table_view) { if ($propertie == 'title') { $res .= '<td><a href="' . $propertie_link . '?' . q2w3_table_func::change_qstring('id', $row_id) . '" class="row-title">' . $definition->val . '</a>' . $this->row_actions($this->object, $row) . '</td>' . PHP_EOL; } else { $res .= '<td>' . $definition->val . '</td>' . PHP_EOL; } } } $res .= '</tr>' . PHP_EOL; } } else { $res = '<tr><td></td><td colspan="' . $col_num . '">' . __('No data', $this->plugin_id) . '</td></tr>' . PHP_EOL; } return $res; }