>, total: int} */ public function list_for_admin( int $page, int $per_page, ?string $actor = null, ?string $subject = null ): array { $page = max( 1, $page ); $per_page = min( 200, max( 1, $per_page ) ); $offset = ( $page - 1 ) * $per_page; $where = [ '1=1' ]; $params = []; if ( null !== $actor && '' !== $actor ) { $where[] = '(`actor_label` LIKE %s OR `actor_type` = %s)'; $params[] = '%' . $this->db->esc_like( $actor ) . '%'; $params[] = $actor; } if ( null !== $subject && '' !== $subject ) { $where[] = '`subject_type` = %s'; $params[] = $subject; } $where_sql = implode( ' AND ', $where ); $count_sql = $this->db->prepare( 'SELECT COUNT(*) FROM %i WHERE ' . $where_sql, $this->table( 'activity_log' ), ...$params ); $total = is_string( $count_sql ) ? (int) $this->db->get_var( $count_sql ) : 0; $list_params = $params; $list_params[] = $per_page; $list_params[] = $offset; $list_sql = $this->db->prepare( 'SELECT * FROM %i WHERE ' . $where_sql . ' ORDER BY `created_at` DESC, `id` DESC LIMIT %d OFFSET %d', $this->table( 'activity_log' ), ...$list_params ); $rows = is_string( $list_sql ) ? $this->db->get_results( $list_sql, ARRAY_A ) : []; if ( ! is_array( $rows ) ) { $rows = []; } $items = []; foreach ( $rows as $row ) { if ( ! is_array( $row ) ) { continue; } $changes = $this->decode_meta( is_string( $row['changes'] ?? null ) ? (string) $row['changes'] : null ); $items[] = [ 'id' => (int) $row['id'], 'actor' => (string) ( $row['actor_label'] ?? $row['actor_type'] ?? '' ), 'subject' => trim( (string) ( $row['subject_type'] ?? '' ) . ' ' . (string) ( $row['subject_id'] ?? '' ) ), 'action' => (string) ( $row['summary'] ?? $row['action'] ?? '' ), 'at' => (string) $row['created_at'], 'changes' => $changes, ]; } return [ 'items' => $items, 'total' => $total, ]; } }