update
This commit is contained in:
@@ -376,18 +376,40 @@ class Rest_Controller extends \WP_REST_Controller {
|
||||
|
||||
$is_global_mode = ( 'global' === Settings::get_ical_sync_mode() );
|
||||
|
||||
// Build yacht_id → color map (deterministic by ascending yacht_id).
|
||||
$yacht_posts = get_posts(
|
||||
// Build yacht_id → color map (admin-selected `_yacht_color` lub fallback z palety po ID).
|
||||
$yacht_posts_full = get_posts(
|
||||
array(
|
||||
'post_type' => 'yacht',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
$color_map = self::get_yacht_color_palette( $yacht_posts );
|
||||
$yacht_ids = array();
|
||||
foreach ( $yacht_posts_full as $yp ) {
|
||||
$yacht_ids[] = (int) $yp->ID;
|
||||
}
|
||||
$color_map = self::get_yacht_color_palette( $yacht_ids );
|
||||
|
||||
// Build name/alias → yacht_id map (lowercase keys, sorted by length DESC for longest match).
|
||||
$name_map = array();
|
||||
foreach ( $yacht_posts_full as $yp ) {
|
||||
$title = mb_strtolower( trim( (string) $yp->post_title ) );
|
||||
if ( '' !== $title ) {
|
||||
$name_map[ $title ] = (int) $yp->ID;
|
||||
}
|
||||
$alias = mb_strtolower( trim( (string) \YachtBooking\Yacht::get_gcal_alias( $yp->ID ) ) );
|
||||
if ( '' !== $alias ) {
|
||||
$name_map[ $alias ] = (int) $yp->ID;
|
||||
}
|
||||
}
|
||||
uksort(
|
||||
$name_map,
|
||||
function( $a, $b ) {
|
||||
return mb_strlen( $b ) - mb_strlen( $a );
|
||||
}
|
||||
);
|
||||
|
||||
// Query bookings overlapping [start, end] with status confirmed or pending.
|
||||
$bookings = get_posts(
|
||||
@@ -437,15 +459,6 @@ class Rest_Controller extends \WP_REST_Controller {
|
||||
$source = (string) get_post_meta( $booking_id, '_booking_source', true );
|
||||
$is_global_event = ( 0 === $yacht_id || \YachtBooking\Integrations\ICal\ICal_Import::GLOBAL_CALENDAR_SOURCE === $source );
|
||||
|
||||
// Color: zachowane z poprzedniej logiki (per-yacht paleta lub kolor global).
|
||||
if ( $is_global_mode || $is_global_event ) {
|
||||
$color = self::GLOBAL_EVENT_COLOR;
|
||||
$y_id = 0;
|
||||
} else {
|
||||
$color = isset( $color_map[ $yacht_id ] ) ? $color_map[ $yacht_id ] : self::GLOBAL_EVENT_COLOR;
|
||||
$y_id = $yacht_id;
|
||||
}
|
||||
|
||||
// Title: raw SUMMARY z _booking_notes (iCal) lub customer_name (frontend).
|
||||
// Klient świadomie cofa privacy z 09-04 — tytuły rezerwacji widoczne publicznie.
|
||||
if ( in_array( $source, $ical_sources, true ) ) {
|
||||
@@ -457,6 +470,26 @@ class Rest_Controller extends \WP_REST_Controller {
|
||||
}
|
||||
$title = sanitize_text_field( $title );
|
||||
|
||||
// Color resolution:
|
||||
// - per-yacht event (yacht_id > 0): admin color or palette fallback
|
||||
// - global event (yacht_id = 0): match yacht name/alias anywhere in title (longest wins)
|
||||
if ( ! $is_global_event ) {
|
||||
$color = isset( $color_map[ $yacht_id ] ) ? $color_map[ $yacht_id ] : self::GLOBAL_EVENT_COLOR;
|
||||
$y_id = $yacht_id;
|
||||
} else {
|
||||
$color = self::GLOBAL_EVENT_COLOR;
|
||||
$y_id = 0;
|
||||
$title_lower = mb_strtolower( $title );
|
||||
foreach ( $name_map as $needle => $matched_id ) {
|
||||
if ( '' !== $needle && false !== mb_strpos( $title_lower, $needle ) ) {
|
||||
if ( isset( $color_map[ $matched_id ] ) ) {
|
||||
$color = $color_map[ $matched_id ];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Split na N eventów per dzień (allDay = każdy event mieści się w jednej komórce).
|
||||
// Iteracja od start_date do end_date INCLUSIVE — pierwszy i ostatni dzień
|
||||
// mają half-day visual (yacht odbierany / zwracany w południe).
|
||||
@@ -562,7 +595,8 @@ class Rest_Controller extends \WP_REST_Controller {
|
||||
$map = array();
|
||||
|
||||
foreach ( $ids as $i => $yacht_id ) {
|
||||
$map[ $yacht_id ] = $palette[ $i % $count ];
|
||||
$admin_color = \YachtBooking\Yacht::get_color( $yacht_id );
|
||||
$map[ $yacht_id ] = '' !== $admin_color ? $admin_color : $palette[ $i % $count ];
|
||||
}
|
||||
|
||||
return $map;
|
||||
|
||||
Reference in New Issue
Block a user