0

ワードプレスでジムのウェブサイトを作っているのですが、彼らはレッスンと時間を追加できるタイムテーブル プラグインを求めていました。

タイムテーブルが機能し、適切な日時に適切なレッスンが表示されますが、別の要件もありました。その時間のレッスンがない場合、その時間のテーブル行を表示したくないということです。例を次に示します。

        Monday   |   Tuesday  |    etc
9.00    
9.15    Fitness
9.30    
9.45   
10.00
10.15
10.45
11.00
11.15              Another lesson

この例では、 10.00 と 11.00 の間にレッスンはありません。だから私は 9.00 から 9.45 だけを表示し、時間 10 ですべての行を非表示にし、11.00 で再び開始するので、次のようになります。

        Monday   |   Tuesday  |    etc
9.00    
9.15    Fitness
9.30    
9.45   
11.00
11.15              Another lesson

ただし、これを行う方法がわかりません。タイムテーブルのデータを収集するコードと、テーブルを生成するコードを作成しました。テーブルを生成するコードは次のとおりです。

 $table  = '<table>';
        $table .=   '<thead>';
        $table .=       '<tr>';
        $table .=           '<th></th>';
        foreach($this->arDays as $day => $id){
            $table .= '<th>'.$day.'</th>';
            // Display the days on top of the table.
        }
        $table .=       '</tr>';
        $table .= '</thead>';
        $table .= '<tbody>';
        foreach($arData['times'] as $time){

            // I think here should be a check if we have to display the table rows, 
            // how ??

            // Make a column with all the times
            $table .=   '<tr>';             
            $table .=       '<td>'.date('H:i',$time).'</td>';
            foreach($this->arDays as $day => $id){
                // Then foreach time, foreach day check if there are lessons
                $table .= '<td>';
                // There is a lesson, display it in the timetable
                if(!empty($arData[$day][$time])){
                   $arTimetable = $arData[$day][$time];
                   foreach($arTimetable as $oTimetable){
                       $table .= $oTimetable->oLesson->name;
                   }
                }
                $table .=   '</td>';
            }
            $table .= '</tr>';
        }

        $table .=   '</tbody>';
        $table .= '</table>';

        echo $table;

テーブル行を表示する必要があるかどうかをチェックするチェックを追加する必要があると思われる場所にコメントを追加しました。

誰かが私を助けてくれることを願っています!

ありがとう!!

編集:

これは、私のデータ配列が毎日どのように見えるかです:

Array
(
    [monday] => Array
    (
        [1382086800] => Array
            (
            )

        [1382087700] => Array
            (
            )

        [1382088600] => Array
            (
            Lesson Object
            )

配列内の毎日には、その日のすべての時間が含まれます (12 時間 / 15 分)

4

2 に答える 2

1

1) 変数を追加して、行にレッスンが含まれているかどうかを格納します

2) 別の変数を使用して行の HTML を一時的に格納する

3) レッスンが存在する場合は、一時 HTML を追加します。

詳細修正

...
$table .= '<tbody>';
foreach($arData['times'] as $time){
    $rowHasLesson = false; //(1)
    //$table .=   '<tr>'; //(2)
    $tableRow = '<tr>'; //(2)
    $tableRow .= '<td>'.date('H:i',$time).'</td>';
    ...
    foreach($this->arDays as $day => $id){
        ...
        if(!empty($arData[$day][$time])){
            $rowHasLesson = true; //(1)
            ...
            $tableRow .= 'YOUR DATA'; //(2)
        }
    //$table .= '</tr>';
    $tableRow .= '</tr>';
    if( $rowHasLesson ){ //(3)
        $table .= $tableRow;
    }
    ...
}
$table .=   '</tbody>';
...
于 2013-10-18T08:21:20.440 に答える
1

内部でこれを試してください(これがうまくいくことを願っています)

foreach($arData['times'] as $time)

:

    $column = false;
    // Make a column with all the times
    foreach($this->arDays as $day => $id){
        // Then foreach time, foreach day check if there are lessons

        // There is a lesson, display it in the timetable
        if(!empty($arData[$day][$time])){
           if ($column === false){
               $table .=   '<tr>';             
               $table .=   '<td>'.date('H:i',$time).'</td>';
               $table .= '<td>';
               $column = true;
           } else { 
               $table .= '<td>';
           }
           $arTimetable = $arData[$day][$time];
           foreach($arTimetable as $oTimetable){
               if ($column) $table .= $oTimetable->oLesson->name;
           }
        }
        if ($column) $table .=   '</td>';
    }
    if ($column) table .= '</tr>';
于 2013-10-18T08:02:50.590 に答える