Cache for valid child Ad objects after backend checks. */ private array $valid_child_ads = []; /** @var Ad[] Store the winning ads of the current render cycle */ public array $last_rendered_ads = []; /** * Gets the (default) GroupType object. * @return Group|null */ public function get_type_object(): ?object { // For now, groups have a single default type. return GroupTypeRegistry::get()->get_by_id( 'default' ); } /** * Gets the raw ad IDs and weights assigned to this group. * * @return array [ ad_id => weight ] */ public function get_raw_ad_data(): array { $data = $this->get_meta( 'ads_with_weights', [] ); return is_array( $data ) ? array_map( 'intval', $data ) : []; } /** * Whether Refresh can never change what is shown: fixed order and no tie between the last shown and the first hidden ad. * * @return bool */ public function has_static_refresh(): bool { if ( ! $this->get_meta( 'refresh', false ) || $this->get_meta( 'random', false ) ) { return false; } $weights = array_map( static fn( $weight ) => max( 1, $weight ), array_values( $this->get_raw_ad_data() ) ); $limit = (int) $this->get_meta( 'visible_ads', 1 ); if ( ! $weights || $limit <= 0 || $limit >= count( $weights ) ) { return (bool) $weights; } rsort( $weights ); return $weights[ $limit - 1 ] > $weights[ $limit ]; } /** * Gets the processed and backend-valid Ad objects for this group. * This cache is populated by processBackendData(). * * @return array Array of Ad objects, keyed by Ad ID. */ public function get_valid_ads(): array { // Ensure data has been processed before returning. if ( ! $this->backend_processed ) { $this->processBackendData(); } return $this->valid_child_ads; } /** * Max. number of ads in grid mode (columns x rows), shared by SSR and the JS config. * * @return int */ public function get_grid_limit(): int { // Default 2 rows, like the admin field. return max( 1, (int) $this->get_meta( 'columns', 3 ) ) * max( 1, (int) $this->get_meta( 'rows', 2 ) ); } /** * Responsive grid CSS scoped to this group (min width, full-width breakpoint), shared by SSR and the JS config. * * @return string CSS rules without