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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / Logging / FileV2 / FileListTable.php
woocommerce / src / Internal / Admin / Logging / FileV2 Last commit date
File.php 2 years ago FileController.php 1 year ago FileExporter.php 2 years ago FileListTable.php 2 years ago SearchListTable.php 2 years ago
FileListTable.php
335 lines
1 <?php
2 declare( strict_types = 1 );
3
4 namespace Automattic\WooCommerce\Internal\Admin\Logging\FileV2;
5
6 use Automattic\WooCommerce\Internal\Admin\Logging\PageController;
7
8 use WP_List_Table;
9
10 /**
11 * FileListTable class.
12 */
13 class FileListTable extends WP_List_Table {
14 /**
15 * The user option key for saving the preferred number of files displayed per page.
16 *
17 * @const string
18 */
19 public const PER_PAGE_USER_OPTION_KEY = 'woocommerce_logging_file_list_per_page';
20
21 /**
22 * Instance of FileController.
23 *
24 * @var FileController
25 */
26 private $file_controller;
27
28 /**
29 * Instance of PageController.
30 *
31 * @var PageController
32 */
33 private $page_controller;
34
35 /**
36 * FileListTable class.
37 *
38 * @param FileController $file_controller Instance of FileController.
39 * @param PageController $page_controller Instance of PageController.
40 */
41 public function __construct( FileController $file_controller, PageController $page_controller ) {
42 $this->file_controller = $file_controller;
43 $this->page_controller = $page_controller;
44
45 parent::__construct(
46 array(
47 'singular' => 'log-file',
48 'plural' => 'log-files',
49 'ajax' => false,
50 )
51 );
52 }
53
54 /**
55 * Render message when there are no items.
56 *
57 * @return void
58 */
59 public function no_items(): void {
60 esc_html_e( 'No log files found.', 'woocommerce' );
61 }
62
63 /**
64 * Retrieves the list of bulk actions available for this table.
65 *
66 * @return array
67 */
68 protected function get_bulk_actions(): array {
69 return array(
70 'export' => esc_html__( 'Download', 'woocommerce' ),
71 'delete' => esc_html__( 'Delete permanently', 'woocommerce' ),
72 );
73 }
74
75 /**
76 * Get the existing log sources for the filter dropdown.
77 *
78 * @return array
79 */
80 protected function get_sources_list(): array {
81 $sources = $this->file_controller->get_file_sources();
82 if ( is_wp_error( $sources ) ) {
83 return array();
84 }
85
86 sort( $sources );
87
88 return $sources;
89 }
90
91 /**
92 * Displays extra controls between bulk actions and pagination.
93 *
94 * @param string $which The location of the tablenav being rendered. 'top' or 'bottom'.
95 *
96 * @return void
97 */
98 protected function extra_tablenav( $which ): void {
99 $all_sources = $this->get_sources_list();
100
101 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
102 $current_source = File::sanitize_source( wp_unslash( $_GET['source'] ?? '' ) );
103
104 ?>
105 <div class="alignleft actions">
106 <?php if ( 'top' === $which ) : ?>
107 <label for="filter-by-source" class="screen-reader-text"><?php esc_html_e( 'Filter by log source', 'woocommerce' ); ?></label>
108 <select name="source" id="filter-by-source">
109 <option<?php selected( $current_source, '' ); ?> value=""><?php esc_html_e( 'All sources', 'woocommerce' ); ?></option>
110 <?php foreach ( $all_sources as $source ) : ?>
111 <option<?php selected( $current_source, $source ); ?> value="<?php echo esc_attr( $source ); ?>">
112 <?php echo esc_html( $source ); ?>
113 </option>
114 <?php endforeach; ?>
115 </select>
116 <?php
117 submit_button(
118 __( 'Filter', 'woocommerce' ),
119 '',
120 'filter_action',
121 false,
122 array(
123 'id' => 'logs-filter-submit',
124 )
125 );
126 ?>
127 <?php endif; ?>
128 </div>
129 <?php
130 }
131
132 /**
133 * Set up the column header info.
134 *
135 * @return void
136 */
137 public function prepare_column_headers(): void {
138 $this->_column_headers = array(
139 $this->get_columns(),
140 get_hidden_columns( $this->screen ),
141 $this->get_sortable_columns(),
142 $this->get_primary_column(),
143 );
144 }
145
146 /**
147 * Prepares the list of items for displaying.
148 *
149 * @return void
150 */
151 public function prepare_items(): void {
152 $per_page = $this->get_items_per_page(
153 self::PER_PAGE_USER_OPTION_KEY,
154 $this->get_per_page_default()
155 );
156
157 $defaults = array(
158 'per_page' => $per_page,
159 'offset' => ( $this->get_pagenum() - 1 ) * $per_page,
160 );
161 $file_args = wp_parse_args(
162 $this->page_controller->get_query_params( array( 'order', 'orderby', 'source' ) ),
163 $defaults
164 );
165
166 $total_items = $this->file_controller->get_files( $file_args, true );
167 if ( is_wp_error( $total_items ) ) {
168 printf(
169 '<div class="notice notice-warning"><p>%s</p></div>',
170 esc_html( $total_items->get_error_message() )
171 );
172
173 return;
174 }
175
176 $total_pages = ceil( $total_items / $per_page );
177 $items = $this->file_controller->get_files( $file_args );
178
179 $this->items = $items;
180
181 $this->set_pagination_args(
182 array(
183 'per_page' => $per_page,
184 'total_items' => $total_items,
185 'total_pages' => $total_pages,
186 )
187 );
188 }
189
190 /**
191 * Gets a list of columns.
192 *
193 * @return array
194 */
195 public function get_columns(): array {
196 $columns = array(
197 'cb' => '<input type="checkbox" />',
198 'source' => esc_html__( 'Source', 'woocommerce' ),
199 'created' => esc_html__( 'Date created', 'woocommerce' ),
200 'modified' => esc_html__( 'Date modified', 'woocommerce' ),
201 'size' => esc_html__( 'File size', 'woocommerce' ),
202 );
203
204 return $columns;
205 }
206
207 /**
208 * Gets a list of sortable columns.
209 *
210 * @return array
211 */
212 protected function get_sortable_columns(): array {
213 $sortable = array(
214 'source' => array( 'source' ),
215 'created' => array( 'created' ),
216 'modified' => array( 'modified', true ),
217 'size' => array( 'size' ),
218 );
219
220 return $sortable;
221 }
222
223 /**
224 * Render the checkbox column.
225 *
226 * @param File $item The current log file being rendered.
227 *
228 * @return string
229 */
230 public function column_cb( $item ): string {
231 ob_start();
232 ?>
233 <input
234 id="cb-select-<?php echo esc_attr( $item->get_file_id() ); ?>"
235 type="checkbox"
236 name="file_id[]"
237 value="<?php echo esc_attr( $item->get_file_id() ); ?>"
238 />
239 <label for="cb-select-<?php echo esc_attr( $item->get_file_id() ); ?>">
240 <span class="screen-reader-text">
241 <?php
242 printf(
243 // translators: 1. a date, 2. a slug-style name for a file.
244 esc_html__( 'Select the %1$s log file for %2$s', 'woocommerce' ),
245 esc_html( gmdate( get_option( 'date_format' ), $item->get_created_timestamp() ) ),
246 esc_html( $item->get_source() )
247 );
248 ?>
249 </span>
250 </label>
251 <?php
252 return ob_get_clean();
253 }
254
255 /**
256 * Render the source column.
257 *
258 * @param File $item The current log file being rendered.
259 *
260 * @return string
261 */
262 public function column_source( $item ): string {
263 $log_file = $item->get_file_id();
264 $single_file_url = add_query_arg(
265 array(
266 'view' => 'single_file',
267 'file_id' => $log_file,
268 ),
269 $this->page_controller->get_logs_tab_url()
270 );
271 $rotation = '';
272 if ( ! is_null( $item->get_rotation() ) ) {
273 $rotation = sprintf(
274 ' &ndash; <span class="post-state">%d</span>',
275 $item->get_rotation()
276 );
277 }
278
279 return sprintf(
280 '<a class="row-title" href="%1$s">%2$s</a>%3$s',
281 esc_url( $single_file_url ),
282 esc_html( $item->get_source() ),
283 $rotation
284 );
285 }
286
287 /**
288 * Render the created column.
289 *
290 * @param File $item The current log file being rendered.
291 *
292 * @return string
293 */
294 public function column_created( $item ): string {
295 $timestamp = $item->get_created_timestamp();
296
297 return gmdate( 'Y-m-d', $timestamp );
298 }
299
300 /**
301 * Render the modified column.
302 *
303 * @param File $item The current log file being rendered.
304 *
305 * @return string
306 */
307 public function column_modified( $item ): string {
308 $timestamp = $item->get_modified_timestamp();
309
310 return gmdate( 'Y-m-d H:i:s', $timestamp );
311 }
312
313 /**
314 * Render the size column.
315 *
316 * @param File $item The current log file being rendered.
317 *
318 * @return string
319 */
320 public function column_size( $item ): string {
321 $size = $item->get_file_size();
322
323 return size_format( $size );
324 }
325
326 /**
327 * Helper to get the default value for the per_page arg.
328 *
329 * @return int
330 */
331 public function get_per_page_default(): int {
332 return $this->file_controller::DEFAULTS_GET_FILES['per_page'];
333 }
334 }
335