class-api-requests-logs-list-table.php
7 years ago
class-gateway-error-logs-list-table.php
7 years ago
class-spam-logs-list-table.php
6 years ago
class-update-logs-list-table.php
7 years ago
logs.php
6 years ago
class-update-logs-list-table.php
268 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Update Log View Class |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Admin/Reports |
| 7 | * @copyright Copyright (c) 2016, GiveWP |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | * @since 2.0.1 |
| 10 | */ |
| 11 | |
| 12 | // Exit if accessed directly. |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | // Load WP_List_Table if not loaded |
| 18 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 19 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Give_Update_Log_Table List Table Class |
| 24 | * |
| 25 | * Renders the update log list table |
| 26 | * |
| 27 | * @since 2.0.1 |
| 28 | */ |
| 29 | class Give_Update_Log_Table extends WP_List_Table { |
| 30 | /** |
| 31 | * Number of items per page |
| 32 | * |
| 33 | * @var int |
| 34 | * @since 2.0.1 |
| 35 | */ |
| 36 | public $per_page = 30; |
| 37 | |
| 38 | /** |
| 39 | * Get things started |
| 40 | * |
| 41 | * @since 2.0.1 |
| 42 | * @see WP_List_Table::__construct() |
| 43 | */ |
| 44 | public function __construct() { |
| 45 | global $status, $page; |
| 46 | |
| 47 | // Set parent defaults |
| 48 | parent::__construct( array( |
| 49 | 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
| 50 | 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
| 51 | 'ajax' => false, // Does this table support ajax? |
| 52 | ) ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Show the search field |
| 57 | * |
| 58 | * @since 2.0.1 |
| 59 | * @access public |
| 60 | * |
| 61 | * @param string $text Label for the search box |
| 62 | * @param string $input_id ID of the search box |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | public function search_box( $text, $input_id ) { |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Retrieve the table columns |
| 71 | * |
| 72 | * @access public |
| 73 | * @since 2.0.1 |
| 74 | * |
| 75 | * @return array $columns Array of all the list table columns |
| 76 | */ |
| 77 | public function get_columns() { |
| 78 | $columns = array( |
| 79 | 'ID' => __( 'Log ID', 'give' ), |
| 80 | 'date' => __( 'Date', 'give' ), |
| 81 | 'details' => __( 'Process Details', 'give' ), |
| 82 | ); |
| 83 | |
| 84 | return $columns; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * This function renders most of the columns in the list table. |
| 89 | * |
| 90 | * @access public |
| 91 | * @since 2.0.1 |
| 92 | * |
| 93 | * @param array $item Contains all the data of the discount code |
| 94 | * @param string $column_name The name of the column |
| 95 | * |
| 96 | * @return string Column Name |
| 97 | */ |
| 98 | public function column_default( $item, $column_name ) { |
| 99 | switch ( $column_name ) { |
| 100 | case 'ID': |
| 101 | return sprintf( |
| 102 | '<span class="give-item-label give-item-label-gray">%1$s</span> %2$s', |
| 103 | esc_attr( $item[ $column_name ] ), |
| 104 | esc_attr( $item['title'] ) |
| 105 | ); |
| 106 | |
| 107 | default: |
| 108 | return esc_attr( $item[ $column_name ] ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Output Error Message column |
| 114 | * |
| 115 | * @access public |
| 116 | * @since 2.0.1 |
| 117 | * |
| 118 | * @param array $item Contains all the data of the log |
| 119 | * |
| 120 | * @return void |
| 121 | */ |
| 122 | public function column_details( $item ) { |
| 123 | echo Give()->tooltips->render_link( array( |
| 124 | 'label' => __( 'View Update Log', 'give' ), |
| 125 | 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', |
| 126 | 'link' => "#TB_inline?width=640&inlineId=log-details-{$item['ID']}", |
| 127 | 'attributes' => array( |
| 128 | 'class' => 'thickbox give-error-log-details-link button button-small', |
| 129 | ), |
| 130 | ) ); |
| 131 | ?> |
| 132 | <div id="log-details-<?php echo esc_attr( $item['ID'] ); ?>" style="display:none;"> |
| 133 | <?php |
| 134 | |
| 135 | // Print Log Content, if not empty. |
| 136 | if ( ! empty( $item['log_content'] ) ) { |
| 137 | echo sprintf( |
| 138 | '<p><pre>%1$s</pre></div>', |
| 139 | esc_html( $item['log_content'] ) |
| 140 | ); |
| 141 | } |
| 142 | ?> |
| 143 | </div> |
| 144 | <?php |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * Display Tablenav (extended) |
| 150 | * |
| 151 | * Display the table navigation above or below the table even when no items in the logs, so nav doesn't disappear |
| 152 | * |
| 153 | * @see : https://github.com/impress-org/give/issues/564 |
| 154 | * |
| 155 | * @since 1.4.1 |
| 156 | * @access protected |
| 157 | * |
| 158 | * @param string $which |
| 159 | */ |
| 160 | protected function display_tablenav( $which ) { |
| 161 | if ( 'top' === $which ) { |
| 162 | wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
| 163 | } |
| 164 | ?> |
| 165 | <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 166 | |
| 167 | <div class="alignleft actions bulkactions"> |
| 168 | <?php $this->bulk_actions( $which ); ?> |
| 169 | </div> |
| 170 | <?php |
| 171 | $this->extra_tablenav( $which ); |
| 172 | $this->pagination( $which ); |
| 173 | ?> |
| 174 | |
| 175 | <br class="clear"/> |
| 176 | </div> |
| 177 | <?php |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Retrieve the current page number |
| 182 | * |
| 183 | * @access public |
| 184 | * @since 2.0.1 |
| 185 | * |
| 186 | * @return int Current page number |
| 187 | */ |
| 188 | public function get_paged() { |
| 189 | return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Outputs the log views |
| 194 | * |
| 195 | * @param string $which Top or Bottom. |
| 196 | * |
| 197 | * @access public |
| 198 | * @since 2.0.1 |
| 199 | * |
| 200 | * @return void |
| 201 | */ |
| 202 | function bulk_actions( $which = '' ) { |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Gets the log entries for the current view |
| 207 | * |
| 208 | * @access public |
| 209 | * @since 2.0.1 |
| 210 | * |
| 211 | * @return array $logs_data Array of all the Log entires |
| 212 | */ |
| 213 | public function get_logs() { |
| 214 | $logs_data = array(); |
| 215 | $paged = $this->get_paged(); |
| 216 | $log_query = array( |
| 217 | 'log_type' => 'update', |
| 218 | 'paged' => $paged, |
| 219 | 'posts_per_page' => $this->per_page, |
| 220 | ); |
| 221 | |
| 222 | $logs = Give()->logs->get_connected_logs( $log_query ); |
| 223 | |
| 224 | if ( $logs ) { |
| 225 | foreach ( $logs as $log ) { |
| 226 | |
| 227 | $logs_data[] = array( |
| 228 | 'ID' => $log->ID, |
| 229 | 'title' => $log->log_title, |
| 230 | 'date' => $log->log_date, |
| 231 | 'log_content' => $log->log_content, |
| 232 | 'log_date' => $log->log_date, |
| 233 | ); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return $logs_data; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Setup the final data for the table |
| 242 | * |
| 243 | * @access public |
| 244 | * @since 2.0.1 |
| 245 | * @uses Give_Update_Log_Table::get_columns() |
| 246 | * @uses WP_List_Table::get_sortable_columns() |
| 247 | * @uses Give_Update_Log_Table::get_pagenum() |
| 248 | * @uses Give_Update_Log_Table::get_logs() |
| 249 | * @uses Give_Update_Log_Table::get_log_count() |
| 250 | * |
| 251 | * @return void |
| 252 | */ |
| 253 | public function prepare_items() { |
| 254 | $columns = $this->get_columns(); |
| 255 | $hidden = array(); // No hidden columns |
| 256 | $sortable = $this->get_sortable_columns(); |
| 257 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
| 258 | $this->items = $this->get_logs(); |
| 259 | $total_items = Give()->logs->get_log_count( 0, 'update' ); |
| 260 | |
| 261 | $this->set_pagination_args( array( |
| 262 | 'total_items' => $total_items, |
| 263 | 'per_page' => $this->per_page, |
| 264 | 'total_pages' => ceil( $total_items / $this->per_page ), |
| 265 | ) ); |
| 266 | } |
| 267 | } |
| 268 |