| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmEntriesListHelper extends FrmListHelper { |
| 7 | + | |
| 7 | 8 | protected $column_name; |
| 8 | 9 | protected $item; |
| 9 | 10 | protected $field; |
| 10 | 11 | |
| @@ -9,48 +10,87 @@ | ||
| 9 | 10 | protected $field; |
| 10 | 11 | |
| 11 | 12 | /** |
| 12 | 13 | * @since 4.07 |
| 14 | + * @var bool|int | |
| 13 | 15 | */ |
| 14 | 16 | public $total_items = 0; |
| 15 | 17 | |
| 18 | + public function __construct( $args ) { | |
| 19 | + parent::__construct( $args ); | |
| 20 | + $this->screen->set_screen_reader_content( | |
| 21 | + array( | |
| 22 | + 'heading_list' => esc_html__( 'Entries list', 'formidable' ), | |
| 23 | + ) | |
| 24 | + ); | |
| 25 | + } | |
| 26 | + | |
| 16 | 27 | /** |
| 17 | 28 | * @return void |
| 18 | 29 | */ |
| 19 | 30 | public function prepare_items() { |
| 20 | - global $per_page; | |
| 31 | + $this->set_per_page(); | |
| 32 | + $s_query = array(); | |
| 21 | 33 | |
| 22 | - $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' ); | |
| 23 | - $form_id = $this->params['form']; | |
| 34 | + $join_form_in_query = false; | |
| 24 | 35 | |
| 25 | - $s_query = array(); | |
| 36 | + $this->items = $this->get_entry_items( $s_query, $join_form_in_query ); | |
| 37 | + $this->set_total_items( $s_query ); | |
| 38 | + $this->prepare_pagination(); | |
| 39 | + } | |
| 26 | 40 | |
| 27 | - if ( $form_id ) { | |
| 28 | - $s_query['it.form_id'] = $form_id; | |
| 29 | - $join_form_in_query = false; | |
| 30 | - } else { | |
| 31 | - $s_query[] = array( | |
| 32 | - 'or' => 1, | |
| 33 | - 'parent_form_id' => null, | |
| 34 | - 'parent_form_id <' => 1, | |
| 35 | - ); | |
| 36 | - $join_form_in_query = true; | |
| 37 | - } | |
| 41 | + protected function set_total_items( $s_query ) { | |
| 42 | + $this->total_items = FrmEntry::getRecordCount( $s_query ); | |
| 43 | + } | |
| 38 | 44 | |
| 39 | - $s = self::get_param( | |
| 45 | + /** | |
| 46 | + * Prepares pagination. | |
| 47 | + * | |
| 48 | + * @since 6.5.4 | |
| 49 | + */ | |
| 50 | + protected function prepare_pagination() { | |
| 51 | + global $per_page; | |
| 52 | + | |
| 53 | + $this->set_pagination_args( | |
| 40 | 54 | array( |
| 41 | - 'param' => 's', | |
| 42 | - 'sanitize' => 'sanitize_text_field', | |
| 55 | + 'total_items' => $this->total_items, | |
| 56 | + 'per_page' => $per_page, | |
| 43 | 57 | ) |
| 44 | 58 | ); |
| 59 | + } | |
| 45 | 60 | |
| 46 | - if ( $s != '' && FrmAppHelper::pro_is_installed() ) { | |
| 47 | - $fid = self::get_param( array( 'param' => 'fid' ) ); | |
| 48 | - $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid ); | |
| 49 | - } | |
| 61 | + /** | |
| 62 | + * Sets the global $per_page variable | |
| 63 | + * | |
| 64 | + * @since 6.5.4 | |
| 65 | + */ | |
| 66 | + protected function set_per_page() { | |
| 67 | + global $per_page; | |
| 68 | + $per_page = $this->get_items_per_page( 'formidable_page_formidable_entries_per_page' ); | |
| 69 | + } | |
| 50 | 70 | |
| 51 | - $s_query = apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) ); | |
| 71 | + /** | |
| 72 | + * @since 6.5.4 | |
| 73 | + * | |
| 74 | + * @param array $s_query | |
| 75 | + * @param bool $join_form_in_query | |
| 76 | + * | |
| 77 | + * @return array | |
| 78 | + */ | |
| 79 | + protected function get_entry_items( &$s_query, &$join_form_in_query ) { | |
| 80 | + global $per_page; | |
| 81 | + $s_query = $this->get_search_query( $join_form_in_query ); | |
| 82 | + $order = $this->get_order_by(); | |
| 83 | + $limit = $this->get_limit( $per_page ); | |
| 52 | 84 | |
| 85 | + return FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * @since 6.5.4 | |
| 90 | + * @return string | |
| 91 | + */ | |
| 92 | + protected function get_order_by() { | |
| 53 | 93 | $orderby = self::get_param( |
| 54 | 94 | array( |
| 55 | 95 | 'param' => 'orderby', |
| 56 | 96 | 'default' => 'id', |
| @@ -55,22 +95,35 @@ | ||
| 55 | 95 | 'param' => 'orderby', |
| 56 | 96 | 'default' => 'id', |
| 57 | 97 | ) |
| 58 | 98 | ); |
| 99 | + $order = self::get_param( | |
| 100 | + array( | |
| 101 | + 'param' => 'order', | |
| 102 | + 'default' => 'DESC', | |
| 103 | + ) | |
| 104 | + ); | |
| 59 | 105 | |
| 106 | + FrmAppController::apply_saved_sort_preference( $orderby, $order ); | |
| 107 | + | |
| 60 | 108 | if ( strpos( $orderby, 'meta' ) !== false ) { |
| 61 | 109 | $order_field_type = FrmField::get_type( str_replace( 'meta_', '', $orderby ) ); |
| 62 | - $orderby .= in_array( $order_field_type, array( 'number', 'scale', 'star' ) ) ? '+0' : ''; | |
| 110 | + | |
| 111 | + if ( in_array( $order_field_type, array( 'number', 'scale', 'star' ), true ) ) { | |
| 112 | + $orderby .= '+0'; | |
| 113 | + } | |
| 63 | 114 | } |
| 64 | 115 | |
| 65 | - $order = self::get_param( | |
| 66 | - array( | |
| 67 | - 'param' => 'order', | |
| 68 | - 'default' => 'DESC', | |
| 69 | - ) | |
| 70 | - ); | |
| 71 | - $order = FrmDb::esc_order( $orderby . ' ' . $order ); | |
| 116 | + return FrmDb::esc_order( $orderby . ' ' . $order ); | |
| 117 | + } | |
| 72 | 118 | |
| 119 | + /** | |
| 120 | + * @since 6.5.4 | |
| 121 | + * | |
| 122 | + * @param int $per_page | |
| 123 | + * @return string | |
| 124 | + */ | |
| 125 | + protected function get_limit( $per_page ) { | |
| 73 | 126 | $page = $this->get_pagenum(); |
| 74 | 127 | $start = (int) self::get_param( |
| 75 | 128 | array( |
| 76 | 129 | 'param' => 'start', |
| @@ -77,22 +130,59 @@ | ||
| 77 | 130 | 'default' => ( $page - 1 ) * $per_page, |
| 78 | 131 | ) |
| 79 | 132 | ); |
| 80 | 133 | |
| 81 | - $limit = FrmDb::esc_limit( $start . ',' . $per_page ); | |
| 82 | - $this->items = FrmEntry::getAll( $s_query, $order, $limit, true, $join_form_in_query ); | |
| 83 | - $total_items = FrmEntry::getRecordCount( $s_query ); | |
| 84 | - $this->total_items = $total_items; | |
| 134 | + return FrmDb::esc_limit( $start . ',' . $per_page ); | |
| 135 | + } | |
| 85 | 136 | |
| 86 | - $this->set_pagination_args( | |
| 137 | + /** | |
| 138 | + * @since 6.5.4 | |
| 139 | + * | |
| 140 | + * @param bool $join_form_in_query | |
| 141 | + * @return array | |
| 142 | + */ | |
| 143 | + protected function get_search_query( &$join_form_in_query ) { | |
| 144 | + $form_id = $this->params['form']; | |
| 145 | + $s_query = array(); | |
| 146 | + | |
| 147 | + if ( $form_id ) { | |
| 148 | + $form_ids = $this->get_form_ids( $form_id ); | |
| 149 | + $s_query['it.form_id'] = count( $form_ids ) > 1 ? $form_ids : $form_ids[0]; | |
| 150 | + } else { | |
| 151 | + $s_query[] = array( | |
| 152 | + 'or' => 1, | |
| 153 | + 'parent_form_id' => null, | |
| 154 | + 'parent_form_id <' => 1, | |
| 155 | + ); | |
| 156 | + $join_form_in_query = true; | |
| 157 | + } | |
| 158 | + | |
| 159 | + $s = self::get_param( | |
| 87 | 160 | array( |
| 88 | - 'total_items' => $total_items, | |
| 89 | - 'per_page' => $per_page, | |
| 161 | + 'param' => 's', | |
| 162 | + 'sanitize' => 'sanitize_text_field', | |
| 90 | 163 | ) |
| 91 | 164 | ); |
| 165 | + | |
| 166 | + if ( $s != '' && FrmAppHelper::pro_is_installed() ) { | |
| 167 | + $fid = self::get_param( array( 'param' => 'fid' ) ); | |
| 168 | + $s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form_id, $fid ); | |
| 169 | + } | |
| 170 | + | |
| 171 | + return apply_filters( 'frm_entries_list_query', $s_query, compact( 'form_id' ) ); | |
| 92 | 172 | } |
| 93 | 173 | |
| 94 | 174 | /** |
| 175 | + * @since 6.5.4 | |
| 176 | + * | |
| 177 | + * @param int|string $form_id | |
| 178 | + * @return array<int> | |
| 179 | + */ | |
| 180 | + protected function get_form_ids( $form_id ) { | |
| 181 | + return array( (int) $form_id ); | |
| 182 | + } | |
| 183 | + | |
| 184 | + /** | |
| 95 | 185 | * @return void |
| 96 | 186 | */ |
| 97 | 187 | public function no_items() { |
| 98 | 188 | $s = self::get_param( |
| @@ -160,8 +250,10 @@ | ||
| 160 | 250 | |
| 161 | 251 | // Override the referrer to prevent it from being used for the screen options. |
| 162 | 252 | echo '<input type="hidden" name="_wp_http_referer" value="" />'; |
| 163 | 253 | |
| 254 | + echo '<label for="form" class="screen-reader-text">' . esc_html__( 'Filter by form', 'formidable' ) . '</label>'; | |
| 255 | + | |
| 164 | 256 | FrmFormsHelper::forms_dropdown( 'form', $form_id, array( 'blank' => __( 'View all forms', 'formidable' ) ) ); |
| 165 | 257 | submit_button( __( 'Filter', 'formidable' ), 'filter_action action', '', false, array( 'id' => 'post-query-submit' ) ); |
| 166 | 258 | echo '</div>'; |
| 167 | 259 | } |
| @@ -180,9 +272,9 @@ | ||
| 180 | 272 | |
| 181 | 273 | $primary_column = ''; |
| 182 | 274 | |
| 183 | 275 | foreach ( $columns as $column_key => $column_display_name ) { |
| 184 | - if ( 'cb' != $column_key && ! in_array( $column_key, $hidden ) ) { | |
| 276 | + if ( 'cb' !== $column_key && ! in_array( $column_key, $hidden ) ) { | |
| 185 | 277 | $primary_column = $column_key; |
| 186 | 278 | break; |
| 187 | 279 | } |
| 188 | 280 | } |
| @@ -190,10 +282,24 @@ | ||
| 190 | 282 | return $primary_column; |
| 191 | 283 | } |
| 192 | 284 | |
| 193 | 285 | /** |
| 286 | + * @since 6.12 | |
| 287 | + * | |
| 288 | + * @param object $item | |
| 194 | 289 | * @return string |
| 195 | 290 | */ |
| 291 | + private static function get_entry_label( $item ) { | |
| 292 | + if ( $item->name ) { | |
| 293 | + return $item->name; | |
| 294 | + } | |
| 295 | + /* translators: %d: Entry id */ | |
| 296 | + return sprintf( __( 'Entry %d', 'formidable' ), $item->id ); | |
| 297 | + } | |
| 298 | + | |
| 299 | + /** | |
| 300 | + * @return string | |
| 301 | + */ | |
| 196 | 302 | public function single_row( $item, $style = '' ) { |
| 197 | 303 | // Set up the hover actions for this user |
| 198 | 304 | $actions = array(); |
| 199 | 305 | $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id; |
| @@ -203,8 +309,10 @@ | ||
| 203 | 309 | $action_links = $this->row_actions( $actions ); |
| 204 | 310 | |
| 205 | 311 | // Set up the checkbox ( because the user is editable, otherwise its empty ) |
| 206 | 312 | $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />"; |
| 313 | + /* translators: %s: Form name */ | |
| 314 | + $checkbox .= "<label for='cb-item-action-{$item->id}'><span class='screen-reader-text'>" . esc_html( sprintf( __( 'Select %s', 'formidable' ), self::get_entry_label( $item ) ) ) . '</span></label>'; | |
| 207 | 315 | |
| 208 | 316 | $r = "<tr id='item-action-{$item->id}'$style>"; |
| 209 | 317 | |
| 210 | 318 | list( $columns, $hidden, , $primary ) = $this->get_column_info(); |
| @@ -242,10 +350,10 @@ | ||
| 242 | 350 | |
| 243 | 351 | $r .= "<td $attributes>"; |
| 244 | 352 | if ( $column_name == $action_col ) { |
| 245 | 353 | $edit_link = admin_url( 'admin.php?page=formidable-entries&frm_action=edit&id=' . $item->id ); |
| 246 | - $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> '; | |
| 247 | - $r .= $action_links; | |
| 354 | + $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> '; | |
| 355 | + $r .= $action_links; | |
| 248 | 356 | } else { |
| 249 | 357 | $r .= $val; |
| 250 | 358 | } |
| 251 | 359 | $r .= '</td>'; |
| @@ -250,9 +358,9 @@ | ||
| 250 | 358 | } |
| 251 | 359 | $r .= '</td>'; |
| 252 | 360 | } |
| 253 | 361 | unset( $val ); |
| 254 | - } | |
| 362 | + }//end foreach | |
| 255 | 363 | $r .= '</tr>'; |
| 256 | 364 | |
| 257 | 365 | return $r; |
| 258 | 366 | } |
| @@ -269,9 +377,9 @@ | ||
| 269 | 377 | /** |
| 270 | 378 | * @param object $item |
| 271 | 379 | */ |
| 272 | 380 | private function column_value( $item ) { |
| 273 | - $col_name = $this->column_name; | |
| 381 | + $col_name = $this->maybe_fix_column_name( $this->column_name ); | |
| 274 | 382 | |
| 275 | 383 | switch ( $col_name ) { |
| 276 | 384 | case 'ip': |
| 277 | 385 | case 'id': |
| @@ -286,9 +394,14 @@ | ||
| 286 | 394 | $date = FrmAppHelper::get_formatted_time( $item->{$col_name} ); |
| 287 | 395 | $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>'; |
| 288 | 396 | break; |
| 289 | 397 | case 'is_draft': |
| 290 | - $val = empty( $item->is_draft ) ? esc_html__( 'No', 'formidable' ) : esc_html__( 'Yes', 'formidable' ); | |
| 398 | + $entry_status = FrmEntriesHelper::get_entry_status_label( $item->is_draft ); | |
| 399 | + $val = sprintf( | |
| 400 | + '<span class="frm-meta-tag frm-entry-status frm-entry-status-%s">%s</span>', | |
| 401 | + sanitize_html_class( $item->is_draft ), | |
| 402 | + esc_html( $entry_status ) | |
| 403 | + ); | |
| 291 | 404 | break; |
| 292 | 405 | case 'form_id': |
| 293 | 406 | $form_id = $item->form_id; |
| 294 | 407 | $user_can_edit_forms = false === FrmAppHelper::permission_nonce_error( 'frm_edit_forms' ); |
| @@ -322,17 +435,32 @@ | ||
| 322 | 435 | * @param mixed $val Column value. |
| 323 | 436 | * @param array $args Contains `item` and `col_name`. |
| 324 | 437 | */ |
| 325 | 438 | $val = apply_filters( 'frm_entries_column_value', $val, compact( 'item', 'col_name' ) ); |
| 326 | - } | |
| 439 | + }//end switch | |
| 327 | 440 | |
| 328 | 441 | return $val; |
| 329 | 442 | } |
| 330 | 443 | |
| 331 | 444 | /** |
| 445 | + * When a form has entries with the 0 item meta value, the values do not appear properly in the entries list. | |
| 446 | + * | |
| 447 | + * @since 6.11.2 | |
| 448 | + * | |
| 449 | + * @param string $column_name | |
| 450 | + * @return string | |
| 451 | + */ | |
| 452 | + private function maybe_fix_column_name( $column_name ) { | |
| 453 | + if ( 0 === strpos( $column_name, '0_' ) ) { | |
| 454 | + $column_name = substr( $column_name, 2 ); | |
| 455 | + } | |
| 456 | + return $column_name; | |
| 457 | + } | |
| 458 | + | |
| 459 | + /** | |
| 460 | + * @param array $actions | |
| 461 | + * @param object $item | |
| 332 | 462 | * @param string $view_link |
| 333 | - * @param array $actions | |
| 334 | - * @param object $item | |
| 335 | 463 | * |
| 336 | 464 | * @return void |
| 337 | 465 | */ |
| 338 | 466 | private function get_actions( &$actions, $item, $view_link ) { |
| @@ -346,9 +474,10 @@ | ||
| 346 | 474 | $actions = apply_filters( 'frm_row_actions', $actions, $item ); |
| 347 | 475 | } |
| 348 | 476 | |
| 349 | 477 | /** |
| 350 | - * @param false $val | |
| 478 | + * @param object $item | |
| 479 | + * @param false $val | |
| 351 | 480 | * |
| 352 | 481 | * @return void |
| 353 | 482 | */ |
| 354 | 483 | private function get_column_value( $item, &$val ) { |
| @@ -393,7 +522,19 @@ | ||
| 393 | 522 | /** |
| 394 | 523 | * @return string |
| 395 | 524 | */ |
| 396 | 525 | protected function confirm_bulk_delete() { |
| 397 | - return __( 'ALL selected entries in this form will be permanently deleted. Want to proceed?', 'formidable' ); | |
| 526 | + return sprintf( | |
| 527 | + /* translators: %1$s: HTML break line, %2$s: HTML bold text */ | |
| 528 | + esc_html__( 'ALL entries in this form will be permanently deleted.%1$sWant to proceed? Type %2$s below.', 'formidable' ), | |
| 529 | + '<br/>', | |
| 530 | + '<b>DELETE ALL</b>' | |
| 531 | + ); | |
| 532 | + } | |
| 533 | + | |
| 534 | + /** | |
| 535 | + * @return string | |
| 536 | + */ | |
| 537 | + protected function loaded_from() { | |
| 538 | + return 'entries-list'; | |
| 398 | 539 | } |
| 399 | 540 | } |