/** * @return FramesView View class. */ function GetMyCalendar(&$Sources, $DateRange = NULL, $Filter = NULL) { $CI =& get_instance(); $range = $CI->date_uri->ReadUri($DateRange, TRUE); $now = new Academic_time(time()); if (!$range['valid']) { $DateRange = $this->mDefaultRange; $range = $CI->date_uri->ReadUri($DateRange, TRUE); assert($range['valid']); } $start = $range['start']; $end = $range['end']; $days = Academic_time::DaysBetweenTimestamps($start->Timestamp(), $end->Timestamp()); $this->mDateRange = $DateRange; $CI->main_frame->SetTitleParameters(array('range' => $range['description'])); if ($days > 7) { return $this->GetWeeks($Sources, $DateRange, $Filter, $range['format']); } elseif ($days > 1) { return $this->GetDays($Sources, $DateRange, $Filter, $range['format']); } else { return $this->GetDay($Sources, $DateRange, $Filter, $range['format']); } }
function range() { if (!CheckPermissions($this->mPermission)) { return; } $this->pages_model->SetPageCode($this->mRangePageCode); $this->_SetupMyCalendar(); $this->mPaths->SetCalendarMode('range'); $this->SetupCategories(); $date_range = array_key_exists('Range', $this->mData) ? $this->mData['Range'] : $this->mDefaultRange; $filter = array_key_exists('Filter', $this->mData) ? $this->mData['Filter'] : NULL; $date_range_split = explode(':', $date_range); $this->mPaths->SetDefaultRange($date_range_split[0]); $this->load->library('date_uri'); $range = $this->date_uri->ReadUri($date_range, TRUE); $now = new Academic_time(time()); if (!$range['valid']) { $date_range = $this->mDefaultRange; $range = $this->date_uri->ReadUri($date_range, TRUE); assert($range['valid']); } $start = $range['start']; $end = $range['end']; $days = Academic_time::DaysBetweenTimestamps($start->Timestamp(), $end->Timestamp()); $this->mDateRange = $date_range; $Organisation_names = 'Yorker'; if (is_array($this->mStreams)) { $org_names = array(); foreach ($this->mStreams as $org_info) { $org_names[] = $org_info['name']; } $Organisation_names = implode(', ', $org_names); } $this->main_frame->SetTitleParameters(array('range' => $range['description'], 'organisation' => $Organisation_names)); /// @todo it seems to be calling ReadUri twice, once in this function and once in each callee. if ($days > 7) { $range_view = $this->GetWeeks($this->mMainSource, $date_range, $filter, $range['format']); } elseif ($days > 1) { $range_view = $this->GetDays($this->mMainSource, $date_range, $filter, $range['format']); } else { $range_view = $this->GetDay($this->mMainSource, $date_range, $filter, $range['format']); } if (is_array($this->mStreams)) { $range_view->SetData('streams', $this->mStreams); $range_view->SetData('Path', $this->mPaths); } $range_view->SetData('Permissions', $this->mPermissions); $this->main_frame->SetContent($range_view); $this->main_frame->Load(); }
function Load() { /// Process the data before loading $this->ProcessEvents($this->mData, $this->mCategories); /// Make some links if (NULL !== $this->mPaths && NULL !== $this->mRangeFormat && NULL !== $this->mStartTime && NULL !== $this->mEndTime) { $days = Academic_time::DaysBetweenTimestamps($this->mStartTime, $this->mEndTime); $start = new Academic_time($this->mStartTime); $end = new Academic_time($this->mEndTime); $now = new Academic_time(time()); $try_again = TRUE; if (0 === $start->AcademicDay() && 0 === $end->AcademicDay()) { $CI =& get_instance(); $terms_apart = ($end->AcademicYear() - $start->AcademicYear()) * 6 + $end->AcademicTerm() - $start->AcademicTerm(); // don't really need to scroll in years if (FALSE && $terms_apart >= 6) { $this->SetData('ForwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() + 1, $start->AcademicTerm(), $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() + 1, $end->AcademicTerm(), $end->AcademicWeek()))); $this->SetData('BackwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() - 1, $start->AcademicTerm(), $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() - 1, $end->AcademicTerm(), $end->AcademicWeek()))); $try_again = FALSE; } elseif ($terms_apart > 0) { $this->SetData('ForwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() + (5 === $start->AcademicTerm() ? 1 : 0), ($start->AcademicTerm() + 1) % 6, $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() + (5 === $start->AcademicTerm() ? 1 : 0), ($end->AcademicTerm() + 1) % 6, $end->AcademicWeek()))); $this->SetData('BackwardUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($start->AcademicYear() - (0 === $start->AcademicTerm() ? 1 : 0), ($start->AcademicTerm() + 5) % 6, $start->AcademicWeek()), $CI->academic_calendar->Academic($end->AcademicYear() - (0 === $start->AcademicTerm() ? 1 : 0), ($end->AcademicTerm() + 5) % 6, $end->AcademicWeek()))); $try_again = FALSE; } $this->SetData('NowUrl', $this->GenerateRangeUrl($CI->academic_calendar->Academic($now->AcademicYear(), $now->AcademicTerm(), 1), $CI->academic_calendar->Academic($now->AcademicYear() + (5 === $start->AcademicTerm() ? 1 : 0), ($now->AcademicTerm() + 1) % 6, 1))); $this->SetData('NowUrlLabel', 'This term'); } if ($try_again) { $now = $now->Midnight(); if ($days >= 7) { $forward_jump = '1week'; $now = $now->BackToMonday(); $this->SetData('NowUrlLabel', 'This week'); } else { $forward_jump = '1day'; $this->SetData('NowUrlLabel', 'Today'); } $this->SetData('ForwardUrl', $this->GenerateRangeUrl($start->Adjust($forward_jump), $end->Adjust($forward_jump))); $this->SetData('BackwardUrl', $this->GenerateRangeUrl($start->Adjust('-' . $forward_jump), $end->Adjust('-' . $forward_jump))); $this->SetData('NowUrl', $this->GenerateRangeUrl($now, $now->Adjust('+' . $forward_jump))); } } parent::Load(); }
/** * @brief Perform tests on the academic calendar functions. * @return The number of errors detected. * * Runs through every day in the academic calendar checking that the term * number and week number functions are correct and that days are * consecutive when calculated using Academic_calendar::Academic. */ function PerformTests() { // Store the previous date so can see how many days have elapsed $prev_date = 0; $errors = 0; // Go through academic years for ($year = 2004; $year < 2012; ++$year) { // Go through all 6 academic terms for ($term_counter = 0; $term_counter < 6; ++$term_counter) { // Go through every week in the term $term_days = Academic_time::LengthOfAcademicTerm($year, $term_counter); $term_day = 0; $dow_counter = Academic_time::DayOfStartOfAcademicTerm($year, $term_counter) + 1; for ($week_counter = 1; $term_day < $term_days; ++$week_counter) { // Go through every day in the week for ($dow_counter = $dow_counter; $dow_counter <= 7 && $term_day < $term_days; ++$dow_counter) { // Create a date object from academic year/term/week/day_of_week $actime = $this->Academic($year, $term_counter, $week_counter, $dow_counter); // Create a date object from academic year/term/day_of_term $actime2 = $this->AcademicDayOfTerm($year, $term_counter, $term_day); // Detect any inconsistencies $error_detected = FALSE; // Do Academic and AcademicDayOfTerm give the same result? if ($actime != $actime2) { echo '!!Academic and AcademicDayOfTerm give different results!!<br/>'; ++$errors; $error_detected = TRUE; } // Has more than one day elapsed? if (0 !== $prev_date && 1 !== Academic_time::DaysBetweenTimestamps($prev_date->Timestamp(), $actime->Timestamp())) { echo '!!days not consecutive!!<br/>'; ++$errors; $error_detected = TRUE; } // Is the calculated academic year consistent? if ($year != $actime->AcademicYear()) { echo '!!year doesn\'t match!!<br/>'; ++$errors; $error_detected = TRUE; } // Is the calculated academic term consistent? if ($term_counter != $actime->AcademicTerm()) { echo '!!term doesn\'t match!!<br/>'; ++$errors; $error_detected = TRUE; } // Is the calculated academic week consistent? if ($week_counter != $actime->AcademicWeek()) { echo '!!week doesn\'t match!!<br/>'; ++$errors; $error_detected = TRUE; } if ($error_detected) { // an error has been detected so print date information if (0 !== $prev_date) { // starting with previous date echo ' prev date: ' . $prev_date->Format(DATE_RFC822) . '<br/>'; //*/ // elapsed days echo ' days between: ' . Academic_time::DaysBetweenTimestamps($prev_date->Timestamp(), $actime->Timestamp()) . '<br/>'; //*/; } // academic date input echo ' Year: ' . $year . ', Term: ' . $term_counter . ', Week: ' . $week_counter . ', Day of week: ' . $dow_counter . ', Day of term: ' . $term_day . '<br/>'; //*/ // standard date output echo ' date1: ' . $actime->Format(DATE_RFC822) . '<br/>'; //*/ echo ' date2: ' . $actime2->Format(DATE_RFC822) . '<br/>'; //*/ // gregorian & academic date output echo ' date: ' . $actime->DayOfMonth() . '/' . $actime->Month() . '/' . $actime->Year() . ': ' . $actime->AcademicWeek() . ',' . $actime->AcademicTermName() . ',' . $actime->AcademicYearName() . '<br/>'; //*/ // data from inside DaysBetweenTimestamps function // probably no longer required now its fixed echo ' Day of year of first: ' . (int) date('z', $prev_date->Timestamp()) . '<br/>'; echo ' Day of year of second: ' . (int) date('z', $actime->Timestamp()) . '<br/>'; $difference = (int) date('z', $actime->Timestamp()) - (int) date('z', $prev_date->Timestamp()); if ($difference < 0) { echo ' Days of year of first: ' . (365 + (int) date('L', $prev_date->Timestamp())) . '<br/>'; } // New line to seperate error dates echo '<br/>'; } $prev_date = $actime; ++$term_day; } $dow_counter = 1; } } } return $errors; }