public function __construct(SiteApplication $app, CMEProvider $provider, $year, $quarter) { $this->app = $app; $this->provider = $provider; $start_month = (intval($quarter) - 1) * 3 + 1; $this->start_date = new SwatDate(); $this->start_date->setTime(0, 0, 0); $this->start_date->setDate($year, $start_month, 1); $this->start_date->setTZ($this->app->default_time_zone); $this->end_date = clone $this->start_date; $this->end_date->addMonths(3); }
protected function initPost($year, $month_name, $shortname) { if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) { throw new SiteNotFoundException('Post not found.'); } // Date parsed from URL is in locale time. $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, BlorgPageFactory::$months_by_name[$month_name], 1); $date->setTime(0, 0, 0); $memcache = isset($this->app->memcache) ? $this->app->memcache : null; $loader = new BlorgPostLoader($this->app->db, $this->app->getInstance(), $memcache); $loader->addSelectField('title'); $loader->addSelectField('bodytext'); $loader->addSelectField('extended_bodytext'); $loader->addSelectField('shortname'); $loader->addSelectField('publish_date'); $loader->addSelectField('author'); $loader->addSelectField('comment_status'); $loader->addSelectField('visible_comment_count'); $loader->setLoadFiles(true); $loader->setLoadTags(true); $loader->setWhereClause(sprintf('enabled = %s', $this->app->db->quote(true, 'boolean'))); $this->post = $loader->getPostByDateAndShortname($date, $shortname); if ($this->post === null) { throw new SiteNotFoundException('Post not found.'); } }
protected function initReport() { $quarter = SiteApplication::initVar('quarter', null, SiteApplication::VAR_GET); if ($quarter === null || preg_match('/^2[0-9]{3}-0[1-4]$/', $quarter) === 0) { throw new AdminNotFoundException('Invalid quarter.'); } list($year, $quarter) = explode('-', $quarter, 2); $start_month = (intval($quarter) - 1) * 3 + 1; $quarter = new SwatDate(); $quarter->setTime(0, 0, 0); $quarter->setDate($year, $start_month, 1); $quarter->setTZ($this->app->default_time_zone); $quarter->toUTC(); $type = SiteApplication::initVar('type', null, SiteApplication::VAR_GET); $provider = new CMEProvider(); $provider->setDatabase($this->app->db); if (!$provider->loadByShortname($type)) { throw new AdminNotFoundException('Invalid CME provider.'); } $sql = sprintf('select * from QuizReport where quarter = %s and provider = %s', $this->app->db->quote($quarter->getDate(), 'date'), $this->app->db->quote($provider->id, 'integer')); $this->report = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEQuizReportWrapper'))->getFirst(); if (!$this->report instanceof CMEQuizReport) { throw new AdminNotFoundException(sprintf('Report not found for quarter %s.', $quarter->getDate())); } $this->report->setFileBase('../../system/quiz-report-updater'); if (!file_exists($this->report->getFilePath())) { throw new AdminNotFoundException(sprintf('Report file ‘%s’ not found', $this->report->getFilePath())); } }
/** * Returns an XHTML calendar with photo counts * * @param integer $year The year to display * @param integer $month The month to display * * @return string an XHTML calendar. */ public function getCalendar($year, $month) { $date = new SwatDate(); $date->setDate($year, $month, 1); $date->setTime(0, 0, 0); ob_start(); PinholeCalendarGadget::displayCalendarMonth($this->app, $date); $response['calendar_month'] = ob_get_clean(); ob_start(); PinholeCalendarGadget::displayCalendarBody($this->app, $date); $response['calendar_body'] = ob_get_clean(); return $response; }
public static function displayCalendarBody(SiteWebApplication $app, SwatDate $date) { if (isset($app->memcache)) { $cache_key = sprintf('PinholeCalendarGadget.%s.%s.%s', 'displayCalendarBody', $date->getISO8601(), $app->session->isLoggedIn() ? 'private' : 'public'); $body = $app->memcache->getNs('photos', $cache_key); if ($body !== false) { echo $body; return; } } ob_start(); $day_count = self::getPhotoCountPerDay($app, $date); echo '<table>'; $wd = new SwatDate(); $wd->setDate(1995, 1, 1); echo '<tr class="days-of-week">'; for ($i = 1; $i <= 7; $i++) { echo '<td>' . $wd->formatLikeIntl('EEE') . '</td>'; $wd->setDay($i + 1); } echo '</tr>'; $locale = SwatI18NLocale::get(); $start = -1 * $date->getDayOfWeek() + 1; $current_date = clone $date; for ($i = 0; $i <= 41; $i++) { $day = $i + $start; if ($i == 0) { echo '<tr>'; } elseif ($i % 7 == 0) { echo '</tr><tr>'; } if ($day > 0 && $day <= $date->getDaysInMonth()) { $current_date->setDay($day); if (array_key_exists($day, $day_count)) { printf('<td class="has-photos">' . '<a href="%stag?date.date=%s" ' . 'title="%s %s">%s</a></td>', $app->config->pinhole->path, $current_date->formatLikeIntl('yyyy-MM-dd'), $locale->formatNumber($day_count[$day]), Pinhole::ngettext('Photo', 'Photos', $day_count[$day]), $day); } else { echo '<td>' . $day . '</td>'; } } else { echo '<td> </td>'; } } echo '</tr></table>'; $body = ob_get_clean(); if (isset($app->memcache)) { $app->memcache->setNs('photos', $cache_key, $body); } echo $body; }
protected function initComments($year, $month_name, $shortname, $page) { if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) { throw new SiteNotFoundException(Blorg::_('Page not found.')); } // Date parsed from URL is in locale time. $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, BlorgPageFactory::$months_by_name[$month_name], 1); $date->setTime(0, 0, 0); $memcache = isset($this->app->memcache) ? $this->app->memcache : null; $loader = new BlorgPostLoader($this->app->db, $this->app->getInstance(), $memcache); $loader->addSelectField('title'); $loader->addSelectField('bodytext'); $loader->addSelectField('shortname'); $loader->addSelectField('publish_date'); $loader->addSelectField('author'); $loader->addSelectField('visible_comment_count'); $loader->setWhereClause(sprintf('enabled = %s', $this->app->db->quote(true, 'boolean'))); $this->post = $loader->getPostByDateAndShortname($date, $shortname); if ($this->post === null) { throw new SiteNotFoundException('Post not found.'); } $this->total_count = $this->post->getVisibleCommentCount(); $this->comments = false; if (isset($this->app->memcache)) { $key = $this->getCommentsCacheKey(); $this->comments = $this->app->memcache->getNs('posts', $key); } if ($this->comments === false) { $offset = ($page - 1) * $this->getPageSize(); $this->comments = $this->post->getVisibleComments($this->getPageSize(), $offset); if (isset($this->app->memcache)) { $this->app->memcache->setNs('posts', $key, $this->comments); } } else { $this->comments->setDatabase($this->app->db); } if ($page > 1 && count($this->comments) === 0) { throw new SiteNotFoundException(Blorg::_('Page not found.')); } }
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; }
protected function displayMonths() { $path = $this->app->config->blorg->path . 'archive'; $view = SiteViewFactory::get($this->app, 'post'); $view->setPartMode('title', SiteView::MODE_SUMMARY); $view->setPartMode('bodytext', SiteView::MODE_NONE); $view->setPartMode('extended_bodytext', SiteView::MODE_NONE); $view->setPartMode('tags', SiteView::MODE_NONE); $view->setPartMode('files', SiteView::MODE_NONE); $ul_tag = new SwatHtmlTag('ul'); $ul_tag->class = 'blorg-archive-months'; $ul_tag->open(); foreach ($this->months as $month => $posts) { $li_tag = new SwatHtmlTag('li'); $li_tag->open(); $heading_tag = new SwatHtmlTag('h4'); $heading_tag->class = 'blorg-archive-month-title'; $heading_tag->open(); $date = new SwatDate(); $date->setDate(2010, $month, 1); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = sprintf('%s/%s/%s', $path, $this->year, BlorgPageFactory::$month_names[$month]); $anchor_tag->setContent($date->getMonthName()); $anchor_tag->display(); $heading_tag->close(); $post_ul_tag = new SwatHtmlTag('ul'); $post_ul_tag->class = 'entries'; $post_ul_tag->open(); foreach ($posts as $post) { $post_li_tag = new SwatHtmlTag('li'); $post_li_tag->open(); $view->display($post); $post_li_tag->close(); } $post_ul_tag->close(); $li_tag->close(); } $ul_tag->close(); }
protected function getQuarterEarnedCredits(CMEProvider $provider, $year, $quarter) { $start_month = ($quarter - 1) * 3 + 1; $start_date = new SwatDate(); $start_date->setTime(0, 0, 0); $start_date->setDate($year, $start_month, 1); $start_date->setTZ($this->default_time_zone); $end_date = clone $start_date; $end_date->addMonths(3); $sql = sprintf('select count(1) from AccountCMEProgressCreditBinding inner join AccountCMEProgress on AccountCMEProgressCreditBinding.progress = AccountCMEProgress.id inner join AccountEarnedCMECredit on AccountEarnedCMECredit.account = AccountCMEProgress.account and AccountCMEProgressCreditBinding.credit = AccountEarnedCMECredit.credit inner join CMECredit on CMECredit.id = AccountEarnedCMECredit.credit inner join Account on AccountCMEProgress.account = Account.id where CMECredit.front_matter in ( select CMEFrontMatterProviderBinding.front_matter from CMEFrontMatterProviderBinding where CMEFrontMatterProviderBinding.provider = %s ) and convertTZ(earned_date, %s) >= %s and convertTZ(earned_date, %s) < %s and Account.delete_date is null', $this->db->quote($provider->id, 'integer'), $this->db->quote($this->config->date->time_zone, 'text'), $this->db->quote($start_date->getDate(), 'date'), $this->db->quote($this->config->date->time_zone, 'text'), $this->db->quote($end_date->getDate(), 'date')); return SwatDB::queryOne($this->db, $sql); }
protected function buildNavBar() { $path = $this->app->config->blorg->path . 'archive'; $this->layout->navbar->createEntry(Blorg::_('Archive'), $path); $path .= '/' . $this->year; $this->layout->navbar->createEntry($this->year, $path); $date = new SwatDate(); $date->setDate(2010, $this->month, 1); $month_title = $date->getMonthName(); $month_name = BlorgPageFactory::$month_names[$this->month]; $path .= '/' . $month_name; $this->layout->navbar->createEntry($month_title, $path); }
private function parseMetaDataDate($date_string) { list($year, $month, $day, $hour, $minute, $second) = sscanf($date_string, "%d:%d:%d %d:%d:%d"); $date = new SwatDate(); $error = $date->setDate($year, $month, $day); if (PEAR::isError($error)) { return null; } $error = $date->setTime($hour, $minute, $second); if (PEAR::isError($error)) { return null; } $date->toUTC(); return $date; }
protected function displayArchive() { $path = $this->app->config->blorg->path . 'archive'; $locale = SwatI18NLocale::get(); $year_ul_tag = new SwatHtmLTag('ul'); $year_ul_tag->class = 'blorg-archive-years'; $year_ul_tag->open(); foreach ($this->years as $year => $values) { $year_li_tag = new SwatHtmlTag('li'); $year_li_tag->open(); $year_anchor_tag = new SwatHtmlTag('a'); $year_anchor_tag->href = sprintf('%s/%s', $path, $year); $year_anchor_tag->setContent($year); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $values['post_count']), $locale->formatNumber($values['post_count']))); $year_heading_tag = new SwatHtmlTag('h4'); $year_heading_tag->class = 'blorg-archive-year-title'; $year_heading_tag->open(); $year_anchor_tag->display(); $post_count_span->display(); $year_heading_tag->close(); $month_ul_tag = new SwatHtmlTag('ul'); $month_ul_tag->open(); foreach ($values['months'] as $month => $post_count) { $date = new SwatDate(); // Set year and day so we're sure it's a valid date, otherwise // the month may not be set. $date->setDate(2010, $month, 1); $month_li_tag = new SwatHtmlTag('li'); $month_li_tag->open(); $month_anchor_tag = new SwatHtmlTag('a'); $month_anchor_tag->href = sprintf('%s/%s/%s', $path, $year, BlorgPageFactory::$month_names[$month]); $month_anchor_tag->setContent($date->getMonthName()); $month_anchor_tag->display(); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $post_count), $locale->formatNumber($post_count))); $post_count_span->display(); $month_li_tag->close(); } $month_ul_tag->close(); $year_li_tag->close(); } $year_ul_tag->close(); }
/** * Gets the SQL where clause for this date tag * * @return string the SQL where clause for this date tag. */ public function getWhereClause() { switch ($this->name) { case 'date': $date = new SwatDate(); list($year, $month, $day) = sscanf($this->value, "%d-%d-%d"); $date->setDate($year, $month, $day); // only matching the date, time and time zone of reference // date are irrelevant $date->setTime(0, 0, 0); // don't compare times $where = sprintf('date_trunc(\'day\', convertTZ(PinholePhoto.photo_date, PinholePhoto.photo_time_zone)) = date_trunc(\'day\', timestamp %s)', $this->db->quote($date, 'date')); break; case 'week': if (ctype_digit($this->value)) { // get date by week number $days = ($this->value - 1) * 7; $start_date = new SwatDate(); $start_date->setMonth(1); $start_date->setDay(1); $start_date->addDays($days); // beginning of next week $end_date = clone $start_date; $end_date->addDays(7 - $end_date->getDayOfWeek()); } else { // beginning of current week $start_date = new SwatDate($this->value); $start_date->subtractDays($start_date->getDayOfWeek()); // beginning of next week $end_date = new SwatDate($this->value); $end_date->addDays(7 - $end_date->getDayOfWeek()); } // database content is always UTC $start_date->setTime(0, 0, 0); $end_date->setTime(0, 0, 0); $start_date->toUTC(); $end_date->toUTC(); $where = sprintf('PinholePhoto.photo_date >= %s and PinholePhoto.photo_date < %s', $this->db->quote($start_date, 'date'), $this->db->quote($end_date, 'date')); break; case 'year': case 'month': case 'day': $where = sprintf('date_part(%s, convertTZ(PinholePhoto.photo_date, PinholePhoto.photo_time_zone)) = %s', $this->db->quote($this->name, 'text'), $this->db->quote($this->value, 'float')); break; default: $where = ''; break; } return $where; }
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; }