repository = $repository; parent::__construct( [ 'plural' => esc_html__( 'Logs', 'wpforms-lite' ), 'singular' => esc_html__( 'Log', 'wpforms-lite' ), ] ); } /** * Items per page. * * @since 1.6.3 */ const PER_PAGE = 10; /** * Whether the table has items to display or not. * * @since 1.6.3 * * @return bool */ public function has_items() { // We can't use the empty function because it doesn't work with Countable object. return (bool) count( $this->items ); } /** * Prepares the data to feed WP_Table_List. * * @since 1.6.3 */ public function prepare_items() { $offset = $this->get_items_offset(); $search = $this->get_request_search_query(); $types = $this->get_items_type(); $this->items = $this->repository->records( self::PER_PAGE, $offset, $search, $types ); $total_items = $this->get_total(); $this->set_pagination_args( [ 'total_items' => $total_items, 'per_page' => self::PER_PAGE, 'total_pages' => ceil( $total_items / self::PER_PAGE ), ] ); } /** * Return the type of records * * @since 1.6.3 * * @return string */ private function get_items_type() { return filter_input( INPUT_GET, 'log_type', FILTER_SANITIZE_STRING ); } /** * Returns the number of items to offset/skip for this current view. * * @since 1.6.3 * * @return int */ private function get_items_offset() { $current_page = $this->get_pagenum(); return 1 < $current_page ? self::PER_PAGE * ( $current_page - 1 ) : 0; } /** * Return the search filter for this request, if any. * * @since 1.6.3 * * @return string */ private function get_request_search_query() { return filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING ); } /** * Column log_id. * * @since 1.6.3 * * @param \WPForms\Logger\Record $item List table item. * * @return int|string */ public function column_log_id( $item ) { return sprintf( '%1$d', absint( $item->get_id() ) ); } /** * Column log_title. * * @since 1.6.3 * * @param \WPForms\Logger\Record $item List table item. * * @return int|string */ public function column_log_title( $item ) { return sprintf( '%2$s', absint( $item->get_id() ), esc_html( $item->get_title() ) ); } /** * Column message. * * @since 1.6.3 * * @param \WPForms\Logger\Record $item List table item. * * @return int|string */ public function column_message( $item ) { return esc_html( $this->crop_message( $item->get_message() ) ); } /** * Column form_id. * * @since 1.6.3 * * @param \WPForms\Logger\Record $item List table item. * * @return int|string */ public function column_form_id( $item ) { return absint( $item->get_form_id() ); } /** * Column types. * * @since 1.6.3 * * @param \WPForms\Logger\Record $item List table item. * * @return int|string */ public function column_types( $item ) { return esc_html( implode( ', ', $item->get_types( 'label' ) ) ); } /** * Column date. * * @since 1.6.3 * * @param \WPForms\Logger\Record $item List table item. * * @return int|string */ public function column_date( $item ) { return esc_html( $item->get_date() ); } /** * Crop message for preview on list table. * * @since 1.6.3 * * @param string $message Message. * * @return string */ private function crop_message( $message ) { return wp_html_excerpt( $message, 97, '...' ); } /** * Prepares the _column_headers property which is used by WP_Table_List at rendering. * It merges the columns and the sortable columns. * * @since 1.6.3 */ private function prepare_column_headers() { $this->_column_headers = [ $this->get_columns(), [], [], ]; } /** * Returns the columns names for rendering. * * @since 1.6.3 * * @return array */ public function get_columns() { return [ 'log_id' => __( 'Log ID', 'wpforms-lite' ), 'log_title' => __( 'Log Title', 'wpforms-lite' ), 'message' => __( 'Message', 'wpforms-lite' ), 'form_id' => __( 'Form ID', 'wpforms-lite' ), 'types' => __( 'Types', 'wpforms-lite' ), 'date' => __( 'Date', 'wpforms-lite' ), ]; } /** * Header before log table. * * @since 1.6.3 */ private function header() { ?>