get('user'); if(!$user->isRegistered()) { $this->redirect('/login/'); return FALSE; } return TRUE; } function formatDay($day) { return $day > 6 ? abs(6 - $day + 1) : $day; } function parseEvents(&$todays_events, &$events, &$num_cols, $today, $is_tutor) { while($events->next()) { $event = &$events->current(); // figure out the number of days this event spans over.. this // should only be a max of 2, but whatever. $num_days = 1; if($event->get('start_day_of_week') != $event->get('end_day_of_week')) { // not best solution if($event->get('end_day_of_week') < $event->get('start_day_of_week')) { $num_days = (6 - $event->get('start_day_of_week') + 1) + (6 - (6 - ($event->get('end_day_of_week') + 1))); } else { $num_days = $event->get('end_day_of_week') - $event->get('start_day_of_week'); } } // loop over the days and only deal with today for($d = $event->get('start_day_of_week'); $d < $event->get('start_day_of_week') + $num_days; $d++) { $day = $this->formatDay($d); if($day == $today) { $start_hour = ($event->get('start_day_of_week') == $today) ? $event->get('start_hour_of_day') : 0; $end_hour = ($event->get('end_day_of_week') == $today) ? $event->get('end_hour_of_day') : 23; $start_mins = ($event->get('start_day_of_week') == $today) ? $event->get('start_mins_of_hour') : 0; $end_mins = ($event->get('end_day_of_week') == $today) ? $event->get('end_mins_of_hour') : 0; $event_info = array( 'event_id' => $event->getId(), 'subject_name' => $event->get('subject_name'), 'description' => $event->get('description'), 'num_rows' => 1, 'display' => 1, 'row_class' => ($is_tutor ? 'schedule_tutoring' : 'schedule_tutored') ); $null_event = array( 'event_id' => $event->getId(), 'display' => 0, ); $row = ''; $start_row = ''; $column = 0; $num_rows = 0; for($h = $start_hour; $h <= $end_hour; $h++) { if($h == $start_hour) { if($start_mins < 30) { $row = $h.'00'; $column = isset($todays_events[$row]) ? count($todays_events[$row]) : 0; if(isset($todays_events[$h.'30'][$column])) { $h = $start_hour; // set the loop to restart $column++; } } else { $row = $h.'30'; $column = isset($todays_events[$row]) ? count($todays_events[$row]) : 0; } } else if($h == $end_hour) { if($end_mins != 0) { if(isset($todays_events[$h.'00'][$column]) || ($end_mins > 30 && isset($todays_events[$h.'30'][$column]))) { $h = $start_hour; // set the loop to restart $column++; } } } else { if(isset($todays_events[$h.'00'][$column]) || isset($todays_events[$h.'30'][$column])) { $h = $start_hour; // set the loop to restart $column++; } } } for($h = $start_hour; $h <= $end_hour; $h++) { if($h == $start_hour) { if($start_mins < 30) { $row = $h.'00'; $start_row = $row; $todays_events[$row][$column] = $event_info; $row = $h.'30'; $todays_events[$row][$column] = $null_event; $num_rows += 2; } else { $row = $h.'30'; $start_row = $row; $todays_events[$row][$column] = $event_info; $num_rows++; } } else if($h == $end_hour) { if($end_mins != 0) { $todays_events[$h.'00'][$column] = $null_event; $num_rows++; if($end_mins > 30) { $todays_events[$h.'30'][$column] = $null_event; $num_rows++; } } } else { $todays_events[$h.'00'][$column] = $null_event; $todays_events[$h.'30'][$column] = $null_event; $num_rows += 2; } // make sure we know how many concurrent cols (events) // we need to prepare for if(isset($todays_events[$h.'00']) && count($todays_events[$h.'00']) > $num_cols) { $num_cols++; } } $todays_events[$start_row][$column]['num_rows'] = $num_rows; $todays_events[$start_row][$column]['height'] = $num_rows * 20 - 6 - 6 - 1; // 6 for margin, 6 for padding, 1 for border } else { continue; } } } } function index(&$registry, &$request, &$response) { if(!$this->commonCheck($registry, $request, $response)) { return; } $user = &$registry->get('user'); $todays_events = array(); $finder = &$this->getFinder('scheduled_events'); $today = date("w"); $num_cols = 1; // get events where we're tutoring // AND wt_event_info.next_occur > ? AND wt_event_info.next_occur < ? // time()-86400, time()+86400, $sql = 'wt_scheduled_events.tutor_id=? '; $sql .= 'AND ((wt_scheduled_events.start_day_of_week>=? AND wt_scheduled_events.end_day_of_week<=6) '; $sql .= 'OR (wt_scheduled_events.end_day_of_week<=? AND wt_scheduled_events.end_day_of_week>=0))'; $events = &$finder->findAllWhere($sql, array($user->getId(), $today, $today)); $this->parseEvents($todays_events, $events, $num_cols, $today, $is_tutor = TRUE); // get events where we're being tutored $sql = 'wt_scheduled_events.user_id=? '; $sql .= 'AND ((wt_scheduled_events.start_day_of_week>=? AND wt_scheduled_events.end_day_of_week<=6) '; $sql .= 'OR (wt_scheduled_events.end_day_of_week<=? AND wt_scheduled_events.end_day_of_week>=0))'; $events = &$finder->findAllWhere($sql, array($user->getId(), $today, $today)); $this->parseEvents($todays_events, $events, $num_cols, $today, $is_tutor = FALSE); //print_r($todays_events);// exit; $hours = array_pad(array(), 48, array('hour'=>0,'day'=>0,)); $hours = &new FAArrayIterator($hours); $i = 0; $h = 0; // hours 0-23 $curr_hour = 1; $am_or_pm = 'am'; // go over the 24 hour period, separated into 48 30 min sections while($hours->next()) { $hour = &$hours->current(); $mins = ($i++ % 2 == 0 ? '00' : '30'); $cols = array(); if(isset($todays_events[$h.$mins])) { $cols = $todays_events[$h.$mins]; } // pad the array $cols = array_pad($cols, $num_cols, array('event_id' => 0, 'display' => 1)); // just a nice display for the time of the current row $hour['time'] = $curr_hour .':'. $mins . $am_or_pm; // deal with the change from AM to PM if($curr_hour % 12 == 0 && $i % 2 == 0) { $curr_hour = 0; $am_or_PM = 'pm'; } // increment the current hour only if we // have gone past the half hour point if($i % 2 == 0) { $h++; $curr_hour++; } // add concurrent scheduled tutoring sessions // as columns $hour['cols'] = &new FAArrayIterator($cols); } $table_width = ++$num_cols * 150 + 10; $table_width = $table_width < 300 ? '450' : $table_width; $response->assignRef('hours', $hours); $response->assign('table_width', $table_width); $response->assignRef('wtuser', $user); $response->assign('page_title', 'Schedule'); $response->assign('content', '/schedule/layout_default.html'); $this->setLayout('layout_default.html'); } } ?>