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);
     }
 }
 protected function displayByDateAdded(PinholeTagList $tag_list)
 {
     $now = new SwatDate();
     $now->convertTZById($this->app->config->date->time_zone);
     $store = new SwatTableStore();
     foreach ($tag_list as $tag) {
         $ds = new SwatDetailsStore();
         $ds->tag = $tag;
         $tag_date = $tag->getDataObject()->first_modified;
         $tag_date->convertTZById($this->app->config->date->time_zone);
         $days_past = $now->diff($tag_date)->days;
         if ($days_past <= 1) {
             $ds->date_part = Pinhole::_('Today');
         } elseif ($days_past <= $now->getDayOfWeek() + 1) {
             $ds->date_part = Pinhole::_('This Week');
         } elseif ($days_past <= $now->getDay()) {
             $ds->date_part = Pinhole::_('This Month');
         } elseif ($days_past <= $now->getDayOfYear()) {
             $ds->date_part = Pinhole::_('This Year');
         } else {
             $ds->date_part = sprintf(Pinhole::_('%s'), $tag_date->getYear());
         }
         $store->add($ds);
     }
     $ul_tag = new SwatHtmlTag('ul');
     $li_tag = new SwatHtmlTag('li');
     $ul_tag->open();
     $part = null;
     foreach ($store as $ds) {
         if ($part !== $ds->date_part) {
             if ($part !== null) {
                 $li_tag->close();
             }
             $li_tag->open();
             $h2_tag = new SwatHtmlTag('h2');
             $h2_tag->class = 'pinhole-tag-entity';
             $h2_tag->setContent($ds->date_part);
             $h2_tag->display();
         } elseif ($part !== null) {
             echo ', ';
         }
         $this->displayTag($ds->tag);
         $part = $ds->date_part;
     }
     $li_tag->close();
     $ul_tag->close();
 }
 /**
  * Displays date.date tags for all the photos in the site instance of
  * this date tag browser's tag list
  *
  * The <i>$start_date</i> and <i>$end_date</i> are used to tell which
  * day, month and year are currently selected.
  *
  * @param SwatDate $start_date the start date of the photos in this date
  *                              tag browser's tag list.
  * @param SwatDate $end_date the end date of the photos in this date
  *                              tag browser's tag list.
  */
 protected function displayDays(SwatDate $start_date, SwatDate $end_date)
 {
     $date = new SwatDate();
     /*
      * Setting the month and year to the $start_date month and year makes
      * sense because the day list is only displayed if the start year and
      * month are the same as the end year and month.
      */
     $date->setMonth($start_date->getMonth());
     $date->setYear($start_date->getYear());
     // get selected day if it exists
     if ($start_date->getDay() == $end_date->getDay()) {
         $selected_day = $start_date->getDay();
     } else {
         $selected_day = null;
     }
     // create base tag list that new date.month tags will be added to
     $tag_list = $this->tag_list->filter(array('PinholeDateTag'));
     $tag_list->add(sprintf('date.year=%s', $date->formatLikeIntl('yyyy')));
     $tag_list->add(sprintf('date.month=%s', $date->formatLikeIntl('MM')));
     $photos = $tag_list->getPhotoCountByDate('day');
     // Filter again since the day list uses date.date tags instead of
     // combined date.year, date.month and date.day tags.
     $tag_list = $this->tag_list->filter(array('PinholeDateTag'));
     // display date.date tags for each day
     $div_tag = new SwatHtmlTag('div');
     $div_tag->class = 'days clearfix';
     $div_tag->open();
     $days_in_month = $date->getDaysInMonth();
     for ($i = 1; $i <= $days_in_month; $i++) {
         $date->setDay($i);
         $key = $date->formatLikeIntl('yyyy-MM-dd');
         $tag_string = sprintf('date.date=%s', $date->formatLikeIntl('yyyy-MM-dd'));
         $tag_list->add($tag_string);
         if ($selected_day === $i) {
             $span_tag = new SwatHtmlTag('span');
             $span_tag->setContent($date->formatLikeIntl('dd'));
             $span_tag->class = 'selected';
             $span_tag->display();
         } elseif (array_key_exists($key, $photos)) {
             $a_tag = new SwatHtmlTag('a');
             $a_tag->href = $this->base . '?' . $tag_list->__toString();
             $a_tag->title = sprintf(Pinhole::ngettext('1 photo', '%s photos', $photos[$key]), SwatString::numberFormat($photos[$key]));
             $a_tag->setContent($date->formatLikeIntl('dd'));
             $a_tag->display();
         } else {
             $span_tag = new SwatHtmlTag('span');
             $span_tag->setContent($date->formatLikeIntl('dd'));
             $span_tag->display();
         }
         $tag_list->remove($tag_string);
     }
     $div_tag->close();
 }