cn_data = $data; } /** * Prepare the items for the table to process. * * @return void */ public function prepare_items() { // prepare items $items = []; // no data? if ( ! empty( $this->cn_data ) ) { foreach ( $this->cn_data as $no => $consent_log ) { $categories = []; if ( $consent_log->ev_essential ) $categories[] = esc_html__( 'Basic Operations', 'cookie-notice' ); if ( $consent_log->ev_functional ) $categories[] = esc_html__( 'Content Personalization', 'cookie-notice' ); if ( $consent_log->ev_analytics ) $categories[] = esc_html__( 'Site Optimization', 'cookie-notice' ); if ( $consent_log->ev_marketing ) $categories[] = esc_html__( 'Ad Personalization', 'cookie-notice' ); // get current date $timestamp = new DateTime( $consent_log->timestamp ); // get deuration in days $duration = (int) $consent_log->ev_eventdetails_expiry; if ( $duration === 30 ) $duration = __( '1 month', 'cookie-notice' ); elseif ( $duration === 90 ) $duration = __( '3 months', 'cookie-notice' ); elseif ( $duration === 182 ) $duration = __( '6 months', 'cookie-notice' ); elseif ( $duration === 365 ) $duration = __( '1 year', 'cookie-notice' ); elseif ( $duration === 730 ) $duration = __( '2 years', 'cookie-notice' ); $items[] = [ 'consent_id' => $consent_log->ev_eventdetails_consentid, 'consent_level' => sprintf( __( 'Level %d', 'cookie-notice' ), $consent_log->ev_consentlevel ), 'consent_categories' => implode( ', ', $categories ), 'consent_duration' => $duration, 'consent_time' => $timestamp->format( get_option( 'time_format' ) ) . ' ' . __( 'GMT', 'cookie-notice' ), 'consent_ip_address' => $consent_log->rj_ip ]; } } // count items $noi = count( $items ); $per_page = 10; $this->set_pagination_args( [ 'total_items' => $noi, 'total_pages' => (int) ceil( $noi / $per_page ), 'per_page' => $per_page ] ); $this->_column_headers = [ $this->get_columns(), [], $this->get_sortable_columns(), '' ]; $this->items = $items; } /** * Define columns in listing table. * * @return array */ public function get_columns() { $columns = [ 'consent_id' => __( 'Consent ID', 'cookie-notice' ), 'consent_level' => __( 'Consent Level', 'cookie-notice' ), 'consent_categories' => __( 'Categories', 'cookie-notice' ), 'consent_duration' => __( 'Duration', 'cookie-notice' ), 'consent_time' => __( 'Time', 'cookie-notice' ), 'consent_ip_address' => __( 'IP address', 'cookie-notice' ) ]; return $columns; } /** * Define sortable columns. * * @return array */ public function get_sortable_columns() { return []; } /** * Define what data to show on each column of the table. * * @param array $item * @param string $column_name * * @return string */ public function column_default( $item, $column_name ) { return esc_html( $item[$column_name] ); } /** * Generate table navigation. * * @param string $which * * @return void */ protected function display_tablenav( $which ) { parent::display_tablenav( $which ); } /** * Generate content for a single row of the table. * * @param array $item * * @return void */ public function single_row( $item ) { $this->cn_item_number++; echo '