/** * Change the way the album constrains dates. * @param string $style Can be one of {@link Album_is_single_day}, {@link Album_is_span}, {@link Album_is_journal} or {@link Album_is_adjusted}. * @param DATE_TIME $first_day * @param DATE_TIME $last_day */ public function set_date_style($style, $first_day, $last_day) { $this->first_day = $first_day; $this->last_day = $last_day; switch ($style) { case Album_is_single_day: $this->first_day_mode = Day_mode_fixed; $this->last_day_mode = Day_mode_fixed; $this->first_day->set_time_from_iso('00:00:00'); $this->last_day->set_time_from_iso('23:59:59'); break; case Album_is_span: $this->first_day_mode = Day_mode_fixed; $this->last_day_mode = Day_mode_fixed; $this->first_day->set_time_from_iso('00:00:00'); $this->last_day->set_time_from_iso('23:59:59'); break; case Album_is_journal: $this->first_day_mode = Day_mode_fixed; $this->last_day_mode = Day_mode_today; $this->first_day->set_time_from_iso('00:00:00'); $this->last_day->set_now(); break; case Album_is_adjusted: $this->first_day_mode = Day_mode_adjust; $this->last_day_mode = Day_mode_adjust; $this->refresh_dates(); break; } }
/** * Set the first and last days to render. * Must be called before calling {@link display()}. * @param DATE_TIME $first_day * @param DATE_TIME $last_day */ public function set_ranges($first_day, $last_day) { $first_day->set_time_from_iso('00:00:00'); $last_day->set_time_from_iso('23:59:59'); $this->first_day = $first_day; $this->last_day = $last_day; $php_first_day = $first_day->as_php(); $php_last_day = $last_day->as_php(); $first_month = date("n", $php_first_day); $first_year = date("Y", $php_first_day); $last_month = date("n", $php_last_day); $last_year = date("Y", $php_last_day); $diff_months = $last_year * Months_in_year + $last_month - ($first_year * Months_in_year + $first_month); if ($diff_months > Months_in_year) { $this->num_years = $last_year - $first_year + 1; } else { $this->num_years = 1; } $this->pager->set_ranges($this->num_years, 1); $this->pager->page_offset = date("Y", $php_first_day) - 1; $curr_month = $first_month; $curr_year = $first_year; $diff_months = $last_year * 12 + $last_month - ($curr_year * 12 + $curr_month); if ($diff_months > 12) { // the span is more than 12 months, so split into pages if ($this->pager->page_number == 1) { $last_month = 12; $last_year = $curr_year; } else { $curr_month = 1; $curr_year = $curr_year + $this->pager->page_number - 1; if ($curr_year != $last_year) { $last_month = 12; $last_year = $curr_year; } } } $this->_curr_month = $curr_month; $this->_curr_year = $curr_year; $this->_last_month = $last_month; $this->_last_year = $last_year; $this->_page_changed(); }