protected function getTableModel(SwatView $view) { $now = new SwatDate(); $now->setTimezone($this->app->default_time_zone); $year = $this->start_date->getYear(); $start_date = new SwatDate(); $start_date->setTime(0, 0, 0); $start_date->setDate($year, 1, 1); $start_date->setTZ($this->app->default_time_zone); $end_date = clone $start_date; $end_date->addMonths(3); $display_end_date = clone $end_date; $display_end_date->subtractMonths(1); $store = new SwatTableStore(); while ($end_date->before($now)) { for ($i = 1; $i <= 4; $i++) { // Only add the quarter to the table model if the start date // is within or prior to that quarter. if ($this->start_date->before($end_date)) { $ds = new SwatDetailsStore(); $quarter = $start_date->formatLikeIntl('yyyy-qq'); $ds->date = clone $start_date; $ds->year = $year; $ds->quarter = $quarter; $ds->quarter_title = sprintf(CME::_('Q%s - %s to %s'), $i, $start_date->formatLikeIntl('MMMM yyyy'), $display_end_date->formatLikeIntl('MMMM yyyy')); foreach ($this->providers as $provider) { $shortname = $provider->shortname; $sensitive = isset($this->reports_by_quarter[$quarter][$shortname]); $ds->{'is_' . $shortname . '_sensitive'} = $sensitive; } $store->add($ds); } $start_date->addMonths(3); $end_date->addMonths(3); $display_end_date->addMonths(3); } $year++; } return $store; }
protected function selectSwatDateEntry($id, SwatDate $date) { static $month_map = array('January' => '01', 'February' => '02', 'March' => '03', 'April' => '04', 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08', 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'); $year = $date->getYear(); $month = $date->getMonth(); $day = $date->getDay(); $year_select = 'xpath=//select[@id=\'' . $id . '_year\']'; $month_select = 'xpath=//select[@id=\'' . $id . '_month\']'; $day_select = 'xpath=//select[@id=\'' . $id . '_day\']'; // get year info $year_options = $this->getSelectOptions($year_select); $start_year = $year_options[1]; $end_year = end($year_options); // get month info if ($this->isElementPresent($month_select)) { $month_options = $this->getSelectOptions($month_select); $start_month = preg_replace('/[^A-Za-z]/', '', $month_options[1]); $start_month = $month_map[$start_month]; $end_month = preg_replace('/[^A-Za-z]/', '', end($month_options)); $end_month = $month_map[$end_month]; } else { $start_month = '01'; $end_month = '01'; } // get day info if ($this->isElementPresent($day_select)) { $day_options = $this->getSelectOptions($day_select); $start_day = sprintf('%02d', $day_options[1]); $end_day = sprintf('%02d', end($day_options)); } else { $start_day = '01'; $end_day = '01'; } // validate ranges $start_date = new SwatDate($start_year . $start_month . $start_day); $end_date = new SwatDate($end_year . $end_month . $end_day); $this->assertFalse($date->before($start_date), 'Date specified in test (' . $date . ') is before the minimum ' . 'selectable date (' . $start_date . ').'); $this->assertFalse($date->after($end_date), 'Date specified in test (' . $date . ') is after the maximum ' . 'selectable date (' . $end_date . ').'); // select year $year_index = $year - intval($start_year) + 1; $this->select($year_select, 'index=' . $year_index); // select month if ($this->isElementPresent($month_select)) { $month_index = $month - intval($start_month) + 1; $this->select($month_select, 'index=' . $month_index); } // select day if ($this->isElementPresent($day_select)) { $day_index = $day - intval($start_day) + 1; $this->select($day_select, 'index=' . $day_index); } }