'休息', 'break' => 'Break', 'LUNCH' => '午餐', 'lunch' => 'Lunch', 'DINNER' => '晚餐', 'QA' => '問答時間', 'HAPPY' => '歡樂交流', 'FREE' => '自由演練' ); } function _week_course_text2ary( $s ) { $a = array(); $valid_field_ary = array( 'C.S', #new sub-course 'PS', 'P', 'C', 'C.L', #new speaker(lecturers) 'VA', 'MERGE', 'BREAK', 'LUNCH', 'DINNER', 'QA', 'HAPPY', 'FREE','break','lunch' ); $hard_code_field = _week_course_hard_code_fields(); foreach ( explode( '`', $s ) as $v ) { $v = trim( $v ); foreach ( $valid_field_ary as $field ) { if ( strpos( $v, $field ) === 0 ) { if ( strpos( $v, 'MERGE' ) === 0 ) { preg_match( '/[0-9]+/', $v, $m ); $a['MERGE'] = $m ? $m[0] : 2; #default is 2 } else { $is_hard_codetext = false; foreach ( $hard_code_field as $code => $codetext ) { if ( strpos( $v, $code ) === 0 ) { $a[ $code ] = $codetext; $is_hard_codetext = true; break; } } if ( ! $is_hard_codetext ) { $key = substr( $v, 0, strpos( $v, ' ' ) ); $a[ $key ] = substr( $v, strpos( $v, ' ' ) ); } } } } } return $a; } function _week_course_text( $s, $ary_speakers, $previous_texts = array() ) { # $a = array(); if ( $previous_texts !== FALSE and is_array( $previous_texts ) ) { foreach ( $previous_texts as $text ) { $previous = _week_course_text2ary( $text, FALSE ); # DO NOT up-inherit unset( $previous['VA'] ); unset( $previous['MERGE'] ); unset( $previous['BREAK'] ); unset( $previous['break'] ); unset( $previous['LUNCH'] ); unset( $previous['lunch'] ); unset( $previous['DINNER'] ); unset( $previous['QA'] ); unset( $previous['HAPPY'] ); unset( $previous['FREE'] ); $a = array_merge( $a, $previous ); } } $original_C = isset( $a['C'] ) ? $a['C'] : false; $current_a = _week_course_text2ary( $s ); $IS_NEED_CLEAN_C_ATTR = false; if ( $original_C and isset( $current_a['C'] ) and $current_a['C'] and $current_a['C'] != $original_C ) { // Let's do refresh/clean C.S and C.L value. $IS_NEED_CLEAN_C_ATTR = true; } if ( $IS_NEED_CLEAN_C_ATTR) { unset( $a['C.S'] ); unset( $a['C.L'] ); } $t11= $current_a['C']??NULL; $t22= $current_a['C.S']??NULL; // echo ""; $a = array_merge( $a, $current_a ); // print_r($previous_texts);echo'---'; // print_r($a);echo'
';print_r($ary);exit();
$s = '';
foreach ( $ary as $rowidx => $a ) {
if ( ! $a[0] ) {// The value of $a[0] should show the time.
break;
}
$style = isset( $bgcolor[ $rowidx ] ) && $bgcolor[ $rowidx ] ? ' style="background:' . $bgcolor[ $rowidx ] . '"' : '';
if ( $rowidx === 0 ) { // A row for the title.
$s .= '';
$s .= '' . ( $a[0] == 'DATE' ? '日期' : '' ) . ' ';
$s .= '' . _week_course_date( $a[1] ) . ' ';
if ( isset( $a[2] ) && $a[2] ) {
$s .= '' . _week_course_date( $a[2] ) . ' ';
}
if ( isset( $a[3] ) && $a[3] ) {
$s .= '' . _week_course_date( $a[3] ) . ' ';
}
if ( isset( $a[4] ) && $a[4] ) {
$s .= '' . _week_course_date( $a[4] ) . ' ';
}
if ( isset( $a[5] ) && $a[5] ) {
$s .= '' . _week_course_date( $a[5] ) . ' ';
}
$s .= ' ';
continue;
}
$a1_prevconfigs = array(); # _prevconfigs SHOULD RENAME to _prevtexts
$a2_prevconfigs = array();
$a3_prevconfigs = array();
$a4_prevconfigs = array();
$a5_prevconfigs = array();
for ( $i = 1; $i < $rowidx; $i++ ) {
if ( empty( $ary[ $i ][0] ) or 0 === preg_match( '/[0-9]/', $ary[ $i ][0] ) ) {
continue;
}
$a1_prevconfigs[ $i ] = $ary[ $i ][1];
$a2_prevconfigs[ $i ] = isset( $ary[ $i ][2] ) ? $ary[ $i ][2] : NULL;
$a3_prevconfigs[ $i ] = isset( $ary[ $i ][3] ) ? $ary[ $i ][3] : NULL;
$a4_prevconfigs[ $i ] = isset( $ary[ $i ][4] ) ? $ary[ $i ][4] : NULL;
$a5_prevconfigs[ $i ] = isset( $ary[ $i ][5] ) ? $ary[ $i ][5] : NULL;
}
$td0 = $a[0];
foreach ( range( 1, 5 ) as $tdnum ) {// 5 day in a week
if ( ! isset( $a[ $tdnum ] ) ) {
continue;
}
${'td' . $tdnum} = $a[ $tdnum ];
if ( $td0 != 'DATE' && $td0 != 'WEEKDAY' ) {
${'a' . $tdnum . '_includeprevconfigs'} = _week_course_text( $a[ $tdnum ], $ary_speakers, ${'a' . $tdnum . '_prevconfigs'} );
$tmp = ${'a' . $tdnum . '_includeprevconfigs'};
if ( isset( $tmp['text'] ) ) {
${'td' . $tdnum} = $tmp['text'];
//echo "";
}
#
${'td' . $tdnum . 'attr'} = array(); #default
if ( isset( ${'a' . $tdnum . '_includeprevconfigs'}['conf']['MERGE'] ) ) {
$merge = ${'a' . $tdnum . '_includeprevconfigs'}['conf']['MERGE'];
if ( $merge >= $MERGE_DEFAULT_VALUE ) {
${'td' . $tdnum . 'attr'}[] = 'rowspan=' . $merge;
}
}
${'td' . $tdnum . 'attr'} = ${'td' . $tdnum . 'attr'} ? ' ' . implode( ' ', ${'td' . $tdnum . 'attr'} ) : '';
}
$td_class = ' class=';
$td_class .= strpos( ${'td' . $tdnum}, 'wkplace' ) !== false ? ' haswkplace' : '';
//$td_class .= preg_match('/(休息|午餐|晚餐)/', ${'td' . $tdnum}) !== 0 ? ' bk-blue' : '';
${'td' . $tdnum . 'class'} = $td_class;
}
$NEED_CHECK_MERGE = $rowidx >= ( $START_POSSIBLE_HAS_MERGE_ROWIDX + 1 );
$s .= '' . $td0 . ' ';
//echo "";
if ( ! $NEED_CHECK_MERGE ) {
$s .= '' . $td1 . ' ';
if ( isset( $a[2] ) && $a[2] ) {
$s .= '' . $td2 . ' ';
}
if ( isset( $a[3] ) && $a[3] ) {
$s .= '' . $td3 . ' ';
}
if ( isset( $a[4] ) && $a[4] ) {
$s .= '' . $td4 . ' ';
}
if ( isset( $a[5] ) && $a[5] ) {
$s .= '' . $td5 . ' ';
}
} else {
foreach ( range( 1, 5 ) as $n ) {
if ( ! isset( $a[ $n ] ) || ! $a[ $n ] ) {
continue;
}
$bool_output = true;
for (
//$text_key=count(${'a'.$n.'_prevconfigs'})-1; # because we start index from 1 INSTEAD OF 0
$text_key = count( ${'a' . $n . '_prevconfigs'} );
$text_key >= $START_POSSIBLE_HAS_MERGE_ROWIDX; $text_key-- ) {
$text = ${'a' . $n . '_prevconfigs'}[ $text_key ];
preg_match( '/MERGE/m', $text, $m1 );
preg_match( '/MERGE ([0-9]+)/m', $text, $m2 );
$MERGE = 0;
if ( $m1 && ! $m2 ) {
$MERGE = $MERGE_DEFAULT_VALUE;
} elseif ( $m1 && $m2 ) {
$MERGE = $m2[1];
}
if ( ( $text_key + $MERGE - 1 ) >= $rowidx ) {
$bool_output = false;
}
if ( $MERGE >= $MERGE_DEFAULT_VALUE ) {
break;
}
}
if ( $bool_output ) {
$s .= '' . ${'td' . $n}
//.($bool_output ? 'TRUE' : 'FALSE')
// .'--'.${'td'.$n.'attr'}
// .implode('---', ${'a'.$n.'_prevconfigs'})
. ' ';
}
} // end range(1,5)as$n
}
$s .= ' ';
}
$s .= '';
// if(isset($atts['show_place_mapping']) && $atts['show_place_mapping']){
// $place_mapping = '