0

特定の会場の特定の日 (今日) の合計イベントをカウントできるようにしようとしています。24 時間の時間を使用して、foreach ループ内でその日の最後のイベントを見つけようとしました。その後、その日の最後のイベントの end_time が現在よりも短い場合、「今日のスケジュールされたすべてのイベントが終了しました」というテキストを表示します。

私の問題は、xml データに 14 日間のすべての部屋のすべてのイベントが含まれており、正しいカウントが得られないことです。foreach 内に if ステートメントがいくつかあります。

if xml space id == room id, then if xml event start_date equals today, then if ($i < $numItems) if event end time is greater than now, それらのイベントを表示

これらの条件が満たされたときにレコードの数が必要です...イベントが今日の日付で、url を介して渡される roomID と同じ部屋にある場合。foreach の前に my $numItems = $count($arr) を配置すると、あまりにも多くのレコードがカウントされ、foreach 内にカウントを配置すると、常に 1 のカウントのみが返されます。

$arr = $this->data['events'];
$numItems = count($arr);
$i = 1;
foreach ($arr as $key => $reservation){
if ((int)$reservation->space_reservation->space_id == $roomID) 
{
//test today's date
        $resDT = date('m/d/y',strtotime($reservation->reservation_start_dt));
        if ($resDT == date('m/d/y'))
            {
            if ($i < $numItems)
            {
            $repst = substr($reservation->event_start_dt,11,5);
            $repet = substr($reservation->event_end_dt,11,5);

                if ( (date('H:i',strtotime($repet))) > (date('H:i')) )
                    {
                    echo '<h2>' .$reservation->event_name. '</h2> ';
                    echo '<span class="dates">' .date('m/d/y',strtotime($reservation->event_start_dt)). ' </span> ';
                    echo '<span class="times">' .date('g:i a',strtotime($repst)). ' - ';
                    echo date('g:i a',strtotime($repet)). '</span> ';
                    echo '<br />';
                    } // ends if event end date has passed

            //echo '<span style="color:#FFF200;">'.$i.'</span>';
            echo '<br />';
            }
//if $i equals last record
            elseif ($i === $numItems) {
                // test if last event ends show
                if ( (date('g:i a',strtotime($repet))) < (date('g:i: a')) ){
                echo '<span style="color:#FFF200;">All scheduled meetings/events have concluded for today. </span><br /><br />';
                }
            }
            $i++;
            } // ends if

    } // ends if
} // ends for each
4

2 に答える 2

1

次のコードは、これらのいずれかを出力します。

  1. 特定の部屋のみの今日のすべての未完了のイベント。
  2. 「本日予定されていたイベントはすべて終了しました。」何も残っていない場合。

必要に応じて使用できるように、2 つのカウンターを追加しました。

  • $totalEventsToday - 指定された部屋で今日予定されているすべてのイベントをカウントします。
  • $unfinishedEventsToday - 終了日時がまだ過ぎていない特定のルームで今日予定されているイベントをカウントします。

コードは次のとおりです。

$today                 = date('m/d/y');
$events                = $this->data['events'];
$totalEventsToday      = 0;
$unfinishedEventsToday = 0;

// Check all reservations/events
foreach ($events as $reservation) {

    // Process reservation/events for the given room only
    if ((int) $reservation->space_reservation->space_id == $roomID) 
    {
        // Process reservation/events for today only
        $resDT = date('m/d/y', strtotime($reservation->reservation_start_dt));
        if ($resDT == $today)
        {
            $totalEventsToday++;

            $repst = substr($reservation->event_start_dt,11,5);
            $repet = substr($reservation->event_end_dt,11,5);

            // Process unfinished event
            if ((date('H:i',strtotime($repet))) > (date('H:i')))
            {
                $unfinishedEventsToday++;

                echo '<h2>' .$reservation->event_name. '</h2> ';
                echo '<span class="dates">' .date('m/d/y',strtotime($reservation->event_start_dt)). ' </span> ';
                echo '<span class="times">' .date('g:i a',strtotime($repst)). ' - ';
                echo date('g:i a',strtotime($repet)). '</span> ';
                echo '<br />';
            } // ends if unfinished event
         } // ends if today
    } // ends if room
} // ends for each

// Test if there aren't any unfinished events left for today
if (!$unfinishedEvents){
    echo '<span style="color:#FFF200;">All scheduled meetings/events have concluded for today. </span><br /><br />';
}
于 2013-04-16T15:56:43.447 に答える