Esempio n. 1
0
 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 getContainer()
 {
     $date = new SwatDate();
     if (isset($this->app->memcache)) {
         $cache_key = sprintf('PinholeDateBrowserGadget.getContent.%s.%s', $date->formatLikeIntl('MM/yyyy'), $this->app->session->isLoggedIn() ? 'private' : 'public');
         $container = $this->app->memcache->getNs('photos', $cache_key);
         if ($container !== false) {
             return $container;
         }
     }
     $container = new SwatContainer();
     $months = $this->getMonths();
     if (count($months) == 0) {
         $content = new SwatContentBlock();
         $content->content = Pinhole::_('No photos have been uploaded yet.');
         $container->add($content);
         return $container;
     }
     $months_array = array();
     foreach ($months as $month) {
         $date = new SwatDate($month->photo_date);
         $key = $date->getYear() . '/' . $date->getMonth();
         $months_array[$key] = $month;
     }
     $locale = SwatI18NLocale::get();
     $start_date = new SwatDate($months->getFirst()->photo_date);
     $start_year = $start_date->getYear();
     $index = count($months) - 1;
     $end_date = new SwatDate($months->getByIndex($index)->photo_date);
     $end_year = $end_date->getYear();
     $date = new SwatDate();
     $date->clearTime();
     for ($year = $start_year; $year >= $end_year; $year--) {
         $year_count = 0;
         $disclosure = new SwatDisclosure();
         $disclosure->title = $year;
         $disclosure->open = false;
         ob_start();
         echo '<ul>';
         for ($i = 1; $i <= 12; $i++) {
             echo '<li class="clearfix"><div>';
             $date->setDate($year, $i, 1);
             if (isset($months_array[$year . '/' . $i])) {
                 $a_tag = new SwatHtmlTag('a');
                 $a_tag->setContent($date->getMonthName());
                 $a_tag->href = $this->app->config->pinhole->path . 'tag?date.year=' . $year . '/date.month=' . $i;
                 $a_tag->display();
                 $photo_count = $months_array[$year . '/' . $i]->photo_count;
                 echo '<span>' . $locale->formatNumber($photo_count) . '</span>';
                 $year_count += $photo_count;
             } else {
                 $div_tag = new SwatHtmlTag('div');
                 $div_tag->setContent($date->getMonthName());
                 $div_tag->display();
             }
             echo '</div></li>';
             if ($i == 12 && $year_count > 0) {
                 echo '<li class="clearfix"><div>';
                 $a_tag = new SwatHtmlTag('a');
                 $a_tag->setContent(sprintf(Pinhole::_('View all photos from %s'), $year));
                 $a_tag->href = $this->app->config->pinhole->path . 'tag?date.year=' . $year;
                 $a_tag->display();
                 echo '<span>' . $locale->formatNumber($year_count) . '</span>';
                 echo '</div></li>';
             }
         }
         echo '</ul>';
         $content = new SwatContentBlock();
         $content->content_type = 'text/xml';
         $content->content = ob_get_clean();
         $disclosure->add($content);
         $container->add($disclosure);
     }
     if (isset($this->app->memcache)) {
         $this->app->memcache->setNs('photos', $cache_key, $container);
     }
     return $container;
 }
Esempio n. 3
0
    protected function getInfo()
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select count(1) as post_count,
			sum(visible_comment_count) as comment_count,
			min(publish_date) as start_date from BlorgPost
				left outer join BlorgPostVisibleCommentCountView as v on
					BlorgPost.id = v.post and BlorgPost.instance = v.instance
			where BlorgPost.instance %s %s and BlorgPost.enabled = %s and
				BlorgPost.publish_date is not null', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean'));
        $post_info = SwatDB::queryRow($this->app->db, $sql, array('integer', 'integer', 'date'));
        $sql = sprintf('select sum(post_count) as tag_count from
			BlorgTagVisiblePostCountView as v
				inner join BlorgTag on BlorgTag.id = v.tag
			where instance %s %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $tag_info = SwatDB::queryRow($this->app->db, $sql, array('integer'));
        $start_date = new SwatDate($post_info->start_date);
        $now = new SwatDate();
        $start_month = $start_date->getMonth();
        $end_month = $now->getMonth();
        $start_year = $start_date->getYear();
        $end_year = $now->getYear();
        if ($start_month > $end_month) {
            $end_month += 12;
            $end_year--;
        }
        $months = $end_month - $start_month + ($end_year - $start_year) * 12;
        $days = $now->diff($start_date)->days;
        $posts_per_month = $months == 0 ? 0 : $post_info->post_count / $months;
        $comments_per_day = $days == 0 ? 0 : $post_info->comment_count / $days;
        return array('post_count' => $post_info->post_count, 'posts_per_month' => $posts_per_month, 'comment_count' => $post_info->comment_count, 'comments_per_day' => $comments_per_day, 'tag_count' => $tag_info->tag_count);
    }
 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);
     }
 }
Esempio n. 5
0
 protected function saveReport(SwatDate $quarter, CMEProvider $provider, $filepath)
 {
     $year = $quarter->getYear();
     $quarter = intval($quarter->formatLikeIntl('qq'));
     $report = $this->getReportGenerator($provider, $year, $quarter);
     $report->saveFile($filepath);
 }
Esempio n. 6
0
 /**
  * Whether or not a name-value pair is valid for this date tag
  *
  * @param string $name the name.
  * @param string $value the value.
  *
  * @return boolean true if the name-value pair is valid for this date tag
  *                  and false if the name-value pair is not valid for this
  *                  date tag.
  */
 private function isValid($name, $value)
 {
     $iso_date_expression = '/^(\\d{4})-?(\\d{1,2})-?(\\d{1,2})$/';
     switch ($name) {
         case 'date':
             $matches = array();
             if (preg_match($iso_date_expression, $value, $matches) == 1) {
                 $valid = checkdate($matches[2], $matches[3], $matches[1]);
             } else {
                 $valid = false;
             }
             break;
         case 'week':
             if (ctype_digit($value)) {
                 $week = intval($value);
                 $valid = $week >= 1 && $week <= 52;
             } else {
                 $matches = array();
                 if (preg_match($iso_date_expression, $value, $matches) == 1) {
                     $valid = checkdate($matches[2], $matches[3], $matches[1]);
                 } else {
                     $valid = false;
                 }
             }
             break;
         case 'year':
             $date = new SwatDate();
             $valid = ctype_digit($value) && $value > 0 && $value <= $date->getYear();
             break;
         case 'month':
             $valid = ctype_digit($value) && $value >= 1 && $value <= 12;
             break;
         case 'day':
             $valid = ctype_digit($value) && $value >= 1 && $value <= 31;
             break;
         default:
             $valid = false;
             break;
     }
     return $valid;
 }
 /**
  * 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();
 }
 protected function getInlineJavaScript(SwatDate $date)
 {
     $javascript = sprintf("var %s = new PinholeCalendarGadget('%s', %d, %d);", $this->calendar_id, $this->calendar_id, $date->getYear(), $date->getMonth());
     return $javascript;
 }