class="">
post->menu_order > $b->post->menu_order); }); } elseif ( $params['view_sort'] == 'post_title' ) { usort($unique_events, function($a, $b) { return strcmp($a->post->post_title, $b->post->post_title); }); } } if ( isset( $mptt_shortcode_data[ 'events_data' ][ 'unique_events' ]) && count( $mptt_shortcode_data[ 'events_data' ][ 'unique_events' ] ) < 2 ) { $style = ' style="display:none;"'; } $display_label = $params[ 'hide_label' ] ? 'display: none' : ''; if ( $params[ 'view' ] == 'dropdown_list' ) { ?> post ); } } } /** * Event template * * @param $mptt_shortcode_data * @param mixed $post */ function mptt_shortcode_template_event( $mptt_shortcode_data, $post = 'all' ) { $params = $mptt_shortcode_data[ 'params' ]; $column_events = mptt_get_columns_events( $mptt_shortcode_data, $post ); // Get start / end row index $bounds = mptt_shortcode_get_table_cell_bounds( $column_events, $params ); $hide_empty_rows = $params[ 'hide_empty_rows' ]; $font_size = ! empty( $params[ 'font_size' ] ) ? ' font-size:' . $params[ 'font_size' ] . ';' : ''; $row_height = $params[ 'row_height' ]; $table_class = apply_filters( 'mptt_shortcode_static_table_class', 'mptt-shortcode-table' ) . ' ' . $params[ 'custom_class' ]; $table_class .= Settings::get_instance()->is_plugin_template_mode() ? '' : ' mptt-theme-mode'; $table_layout = $params['table_layout']; if ( !empty($table_layout) && ($table_layout == 'fixed' || $table_layout == 'auto') ) { $table_class .= ' mptt-table-layout-' . $table_layout; } $data_grouped_by_row = mptt_make_data_shortcode( $bounds, $mptt_shortcode_data, $column_events ); ?> get_template_html( 'shortcodes/table-header', array( 'header_items' => $data_grouped_by_row[ 'table_header' ], 'params' => $params ) ); ?> $row ) { if ( ! $row[ 'show' ] && $params[ 'hide_empty_rows' ] ) { continue; } ?> $cell ) { if ( isset( $cell[ 'time_cell' ] ) && filter_var( $cell[ 'time_cell' ], FILTER_VALIDATE_BOOLEAN, array( 'options' => array( 'default' => false ) ) ) ) { ?> $events_list ) { if ( ! empty( $column_events[ $column_id ] ) ) { foreach ( $events_list as $key_events => $item ) { if ( $item->start_index <= $i && $i < $item->end_index ) { return true; } } } } return false; } /** * Get table cell bounds * * @param $column_events * @param $params * * @return array */ function mptt_shortcode_get_table_cell_bounds( $column_events, $params ) { $hide_empty_rows = $params[ 'hide_empty_rows' ]; if ( $hide_empty_rows ) { $min = - 1; $max = - 1; foreach ( $column_events as $events ) { foreach ( $events as $item ) { if ( isset($item->start_index) && isset($item->end_index) ) { $min = ( $min === - 1 ) ? $item->start_index : $min; $max = ( $max === - 1 ) ? $item->end_index : $max; $min = ( $item->start_index < $min ) ? $item->start_index : $min; $max = ( $item->end_index > $max ) ? $item->end_index : $max; } } } } else { $min = 0; $max = 23 / $params[ 'increment' ]; } return array( 'start' => $min, 'end' => $max ); } /** * Content responsive table */ function mptt_shortcode_template_content_responsive_table() { global $mptt_shortcode_data; if ( $mptt_shortcode_data[ 'params' ][ 'responsive' ] ) { ?>

post_title ); ?>

get_template( 'templates-actions/action-sidebar', array( 'post' => $post ) ); } /** * Make data shortcode * * @param $bounds * @param $mptt_shortcode_data * @param $column_events * * @return array */ function mptt_make_data_shortcode( $bounds, $mptt_shortcode_data, $column_events ) { $data = array( 'rows' => array() ); $amount_rows = 23; if ( isset( $mptt_shortcode_data[ 'params' ][ 'increment' ] ) && floatval( $mptt_shortcode_data[ 'params' ][ 'increment' ] ) > 0 ) { $amount_rows = 23 / floatval( $mptt_shortcode_data[ 'params' ][ 'increment' ] ); } $data[ 'table_header' ] = mptt_get_header_row( $mptt_shortcode_data ); foreach ( $column_events as $column_id => $events_list ) { foreach ( $events_list as $event_key => $item ) { if ( isset( $item->resolve ) ) { unset( $item->resolve ); } } } for ( $row_index = $bounds[ 'start' ]; $row_index <= $bounds[ 'end' ]; $row_index ++ ) { $table_time_cell = get_time_cell( $row_index, $amount_rows, $mptt_shortcode_data[ 'params' ][ 'increment' ] ); list( $row_cells, $column_events ) = mptt_get_row_events( $column_events, $row_index ); if ( $mptt_shortcode_data[ 'params' ][ 'group' ] ) { $row_cells = mptt_group_identical_row_events( $row_cells ); } $data[ 'rows' ][ $row_index ][ 'cells' ] = $row_cells; $data[ 'rows' ][ $row_index ][ 'show' ] = mptt_shortcode_row_has_items( $row_index, $column_events ); if ( ! $mptt_shortcode_data[ 'params' ][ 'hide_hrs' ] ) { array_unshift( $data[ 'rows' ][ $row_index ][ 'cells' ], array( 'time_cell' => true, 'title' => date( get_option( 'time_format' ), strtotime( $table_time_cell ) ) ) ); } } return $data; } /** * Get time cell * * @param $row_index * @param $amount_rows * @param $increment * * @return string */ function get_time_cell( $row_index, $amount_rows, $increment ) { $tm = $row_index * $increment; if ( floor( $tm ) == $tm ) { $time = $tm . ':00'; return $time; } else { if ( $amount_rows == 46 ) { $time = floor( $tm ) . ':30'; return $time; } else { $tm_position = explode( '.', $tm ); if ( isset( $tm_position[ 1 ] ) && $tm_position[ 1 ] == 25 ) { $mnts = ':15'; } elseif ( isset( $tm_position[ 1 ] ) && $tm_position[ 1 ] == 5 ) { $mnts = ':30'; } else { $mnts = ':45'; } $time = floor( $tm ) . $mnts; return $time; } } } /** * Add group attribute to event * * @param $bounds * @param $events_array * * @return mixed */ function group_events( $bounds, $events_array ) { $output_array = array(); foreach ( $events_array as $column_id => $events_list ) { if ( ! empty( $events_array[ $column_id ] ) ) { foreach ( $events_list as $key_events => $item ) { if ( $bounds[ 'end' ] <= $item->end_index && $bounds[ 'start' ] >= $item->start_index ) { continue; } else { $key_count = $item->start_index . '_' . $item->event_id . '_' . $item->end_index; if ( ! isset( $output_array[ $key_count ] ) ) { $output_array[ $key_count ] = array( 'count' => 0, 'output' => false ); $output_array[ $key_count ][ 'count' ] ++; } else { $output_array[ $key_count ][ 'count' ] ++; } } } } } return $output_array; } /** * Header row * * @param $mptt_shortcode_data * * @return array */ function mptt_get_header_row( $mptt_shortcode_data ) { $header_array = array( '0' => array( 'output' => false ) ); $show_hrs = ! $mptt_shortcode_data[ 'params' ][ 'hide_hrs' ]; if ( $show_hrs ): $header_array[ 0 ] = array( 'output' => true, 'id' => '', 'title' => '' ); endif; if ( ! empty( $mptt_shortcode_data[ 'events_data' ][ 'column' ] ) ) { foreach ( $mptt_shortcode_data[ 'events_data' ][ 'column' ] as $column ): $header_array[] = array( 'output' => true, 'id' => $column->ID, 'title' => $column->post_title ); endforeach; } return $header_array; } /** * Row events * * @param $column_events * @param $row_index * * @return array */ function mptt_get_row_events( $column_events, $row_index ) { $events = array(); $default_count = 1; $i = 0; foreach ( $column_events as $column_id => $events_list ) { $empty = true; foreach ( $events_list as $event_key => $item ) { if ( isset( $item->resolve ) && $item->resolve ) { continue; } $group = false; if ( ! empty( $current ) ) { if ( ( $item->end_index <= $current[ 'end_index' ] ) //&& $item->end_index == $row_index && $item->start_index == $row_index ) { $group = true; } } if ( $item->start_index == $row_index || $group ) { //create temp event data for generate hash $temp = (array) $item; //clear data before make hash to compare if ( $temp[ 'id' ] ) { unset( $temp[ 'id' ] ); unset( $temp[ 'column_id' ] ); } $event = array( 'id' => $item->id, 'hash' => md5( serialize( $temp ) ), 'start_index' => $item->start_index, 'end_index' => $item->end_index, 'event_start' => $item->event_start, 'event_end' => $item->event_end, 'column_id' => $item->column_id, 'event_id' => $item->event_id, 'event' => true, 'user_id' => $item->user_id, 'description' => trim( $item->description ), 'order' => $event_key, 'hide' => $group ? true : false ); if ( ! $group ) { $events[ $i ][ 'events' ][ $event[ 'hash' ] ] = $event; $events[ $i ][ 'count' ] = $default_count; $events[ $i ][ 'grouped' ] = false; $events[ $i ][ 'column_id' ] = $column_id; $events[ $i ][ 'hide' ] = false; } else { $events[ $i ][ 'hide' ] = false; $events[ $i ][ 'column_id' ] = $column_id; $events[ $i ][ 'events' ][ $event[ 'hash' ] ] = $event; } $column_events[ $column_id ][ $event_key ]->resolve = true; $empty = false; if ( empty( $current ) ) { $current = array( 'start_index' => $item->start_index, 'end_index' => $item->end_index ); } else { $current[ 'start_index' ] = $current[ 'start_index' ] >= $item->start_index ? $item->start_index : $current[ 'start_index' ]; $current[ 'end_index' ] = $current[ 'end_index' ] <= $item->end_index ? $item->end_index : $current[ 'end_index' ]; } } } if ( $empty ) { $events[ $i ][ 'events' ][] = array( 'id' => false, 'start_index' => $row_index, 'end_index' => $row_index, 'column_id' => $column_id, 'event' => true, ); $events[ $i ][ 'count' ] = $default_count; $events[ $i ][ 'column_id' ] = $column_id; $events[ $i ][ 'hide' ] = false; } unset( $current ); $i ++; } $events = sort_events_data_by_order( $events ); return array( $events, $column_events ); } /** * Sort events by order * * @param $events * * @return mixed */ function sort_events_data_by_order( $events ) { foreach ( $events as $cell => $event_data ) { usort( $event_data[ 'events' ], function ( $a, $b ) { if ( $a[ 'order' ] == $b[ 'order' ] ) { return 0; } return ( $a[ 'order' ] < $b[ 'order' ] ) ? - 1 : 1; } ); $events[ $cell ][ 'events' ] = $event_data[ 'events' ]; } return $events; } /** * Get columns events * * @param $mptt_shortcode_data * * @param $post * * @return array */ function mptt_get_columns_events( $mptt_shortcode_data, $post ) { if ( $post === 'all' ) { $column_events = $mptt_shortcode_data[ 'events_data' ][ 'column_events' ]; return $column_events; } else { $column_events = array(); foreach ( $mptt_shortcode_data[ 'events_data' ][ 'column_events' ] as $col_id => $col_events ) { $column_events[ $col_id ] = array_filter( $col_events, function ( $val ) use ( $post ) { return $post->ID == $val->event_id; } ); } return $column_events; } } /** * Checking identical event in cell * * @param $needle * @param $events * * @return bool */ function mptt_check_exists_column( $needle, $events ) { $exist = false; $const_available_difference = 1; foreach ( $events as $key => $event ) { $difference_data = array_diff( $needle, $event ); if ( isset( $difference_data[ 'id' ] ) && ( count( $difference_data ) === $const_available_difference ) ) { $exist = true; break; } } return $exist; } /** * Group event in row * * @param $events_row_data * * @return array|mixed */ function mptt_group_identical_row_events( $events_row_data ) { $length = count( $events_row_data ); for ( $i = 0; $i < $length - 1; $i ++ ) { if ( ! isset( $events_row_data[ ( $i + 1 ) ] ) ) { continue; } $events_current_data = $events_row_data[ $i ]; $events_current_count = count( $events_current_data[ 'events' ] ); $events_next_data = $events_row_data[ ( $i + 1 ) ]; $events_next_count = count( $events_next_data[ 'events' ] ); if ( $events_next_count > 1 || $events_current_count > 1 ) { continue; } else { if ( filter_var( $events_current_data[ 'events' ][ 0 ][ 'id' ], FILTER_VALIDATE_INT ) && filter_var( $events_next_data[ 'events' ][ 0 ][ 'id' ], FILTER_VALIDATE_INT ) ) { $hash_current = $events_current_data[ 'events' ][ 0 ][ 'hash' ]; $hash_next = $events_next_data[ 'events' ][ 0 ][ 'hash' ]; if ( ! isset( $current_data ) ) { $current_data = array( 'key' => $i, 'hash' => $hash_current ); } if ( $hash_current === $hash_next ) { if ( $current_data[ 'hash' ] !== $hash_current ) { $current_data = array( 'key' => $i, 'hash' => $hash_current ); } if ( $current_data[ 'key' ] === $i ) { $events_current_data[ 'count' ] ++; $events_current_data[ 'grouped' ] = true; $events_row_data[ $i ] = $events_current_data; $events_row_data[ $i + 1 ][ 'hide' ] = true; } else { $events_row_data[ $current_data[ 'key' ] ][ 'count' ] ++; $events_row_data[ $i + 1 ][ 'hide' ] = true; } } } } } return $events_row_data; } /** * Check exists grouped attribute * * @param $event_item * * @return string */ function mptt_is_grouped_event_class( $event_item ) { return ( isset( $event_item[ 'grouped' ] ) && $event_item[ 'grouped' ] ) ? 'mptt-grouped-event' : ''; } /** * Grouped by column * * @param $events * * @return array */ function grouped_by_column( $events ) { $data = array(); foreach ( $events as $key => $event ) { if ( ! $event[ 'event' ] ) { $data[] = $event; continue; } if ( isset( $data[ $event[ 'column_id' ] ] ) ) { $data[ $event[ 'column_id' ] ][ 'related_by_column' ][] = $event; } else { $data[ $event[ 'column_id' ] ] = $event; } } return $data; }