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())); } }
protected function initPosts($year, $month_name) { if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) { throw new SiteNotFoundException('Page not found.'); } // Date parsed from URL is in locale time. $month = BlorgPageFactory::$months_by_name[$month_name]; $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, $month, 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('comment_status'); $loader->addSelectField('visible_comment_count'); $loader->setLoadFiles(true); $loader->setLoadTags(true); $loader->setWhereClause(sprintf('enabled = %s and date_trunc(\'month\', convertTZ(publish_date, %s)) = date_trunc(\'month\', timestamp %s)', $this->app->db->quote(true, 'boolean'), $this->app->db->quote($this->app->default_time_zone->getName(), 'text'), $this->app->db->quote($date->getDate(), 'date'))); $loader->setOrderByClause('publish_date desc'); $this->posts = $loader->getPosts(); if (count($this->posts) == 0) { throw new SiteNotFoundException('Page not found.'); } }
/** * 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; }
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 displayContent() { echo '<div id="' . $this->calendar_id . '" ' . 'class="pinhole-calendar-gadget-container">'; $date = new SwatDate(); $date->convertTZById($this->app->config->date->time_zone); $date->setDay(1); $date->setTime(0, 0, 0); echo '<div class="pinhole-calendar-gadget-head">'; echo '<a class="pinhole-calendar-gadget-prev" ' . 'title="' . Pinhole::_('Previous Month') . '" ' . 'id="' . $this->calendar_id . '_prev" href="#">«</a>'; echo '<div id="' . $this->calendar_id . '_month" class="pinhole-calendar-month">'; echo self::displayCalendarMonth($this->app, $date); echo '</div>'; echo '<a class="pinhole-calendar-gadget-next" ' . 'title="' . Pinhole::_('Next Month') . '" ' . 'id="' . $this->calendar_id . '_next" href="#">»</a>'; echo '</div>'; echo '<div id="' . $this->calendar_id . '_body" class="pinhole-calendar-body">'; echo self::displayCalendarBody($this->app, $date); echo '</div>'; echo '</div>'; Swat::displayInlineJavaScript($this->getInlineJavaScript($date)); }
protected function initMonths($year, $page) { // Date parsed from URL is in locale time. $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, 1, 1); $date->setTime(0, 0, 0); $memcache = isset($this->app->memcache) ? $this->app->memcache : null; $this->loader = new BlorgPostLoader($this->app->db, $this->app->getInstance(), $memcache); $this->loader->addSelectField('title'); $this->loader->addSelectField('bodytext'); $this->loader->addSelectField('shortname'); $this->loader->addSelectField('publish_date'); $this->loader->addSelectField('author'); $this->loader->addSelectField('comment_status'); $this->loader->addSelectField('visible_comment_count'); $this->loader->setWhereClause(sprintf('enabled = %s and date_trunc(\'year\', convertTZ(publish_date, %s)) = date_trunc(\'year\', timestamp %s)', $this->app->db->quote(true, 'boolean'), $this->app->db->quote($this->app->default_time_zone->getName(), 'text'), $this->app->db->quote($date->getDate(), 'date'))); $this->loader->setOrderByClause('publish_date desc'); $offset = ($page - 1) * self::MAX_POSTS; $this->loader->setRange(self::MAX_POSTS, $offset); $posts = $this->loader->getPosts(); foreach ($posts as $post) { $publish_date = clone $post->publish_date; $publish_date->convertTZ($this->app->default_time_zone); $month = $publish_date->getMonth(); if (!array_key_exists($month, $this->months)) { $this->months[$month] = array(); } $this->months[$month][] = $post; } if (count($this->months) == 0) { throw new SiteNotFoundException('Page not found'); } }
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); }
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; }
/** * Checks whether or not this date tag applies to a given photo * * @param PinholePhoto the photo to check. * * @return boolean true if this tag applies to the given photo and false if * this tag does not apply to the given photo. */ public function appliesToPhoto(PinholePhoto $photo) { switch ($this->name) { case 'date': $date = new SwatDate($this->value); // database content is always UTC $date->setTime(0, 0, 0); $date->toUTC(); $applies = SwatDate::compare($photo->photo_date, $date) == 0; 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 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(); $applies = SwatDate::compare($photo->photo_date, $start_date) >= 0 && SwatDate::compare($photo->photo_date, $end_date) <= 0; break; case 'year': $local_photo_date = clone $photo->photo_date; $local_photo_date->convertTZById($photo->photo_time_zone); $applies = $local_photo_date->getYear() == $this->value; break; case 'month': $local_photo_date = clone $photo->photo_date; $local_photo_date->convertTZById($photo->photo_time_zone); $applies = $local_photo_date->getMonth() == $this->value; break; case 'day': $local_photo_date = clone $photo->photo_date; $local_photo_date->convertTZById($photo->photo_time_zone); $applies = $local_photo_date->getDay() == $this->value; break; default: $applies = false; break; } return $applies; }
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 getPhotoTableStore() { if (count($this->tag_list) == 0) { $tag_path = ''; } else { $tag_path = '?' . $this->tag_list->__toString(); } $photos = $this->tag_list->getPhotos('thumbnail'); // throw exception or else tags that have only private photos would be // exposed. if (count($this->tag_list->getByType('PinholeTag')) > 0 && count($photos) == 0) { throw new SiteNotFoundException(sprintf('There are no photos in the current tag intersection: %s.', (string) $this->tag_list)); } $store = new SwatTableStore(); foreach ($photos as $photo) { $ds = new SwatDetailsStore(); $ds->root_path = $this->app->config->pinhole->path; $ds->path = $photo->id . $tag_path; $ds->photo = $photo; $ds->display_title = $this->app->config->pinhole->browser_index_titles; $now = new SwatDate(); $now->convertTZById($this->app->config->date->time_zone); $now->setTime(0, 0, 0); if (count($this->tag_list) == 0) { $publish_date = $photo->publish_date; $publish_date->convertTZbyID($this->app->config->date->time_zone); $days_past = $now->diff($publish_date)->days; if ($days_past <= 1) { $period = Pinhole::_('Today'); } elseif ($days_past <= 2) { $period = Pinhole::_('Yesterday'); } elseif ($days_past <= 7) { $period = sprintf(Pinhole::_('%d Days Ago'), floor($days_past)); } else { $period = $publish_date->formatLikeIntl(SwatDate::DF_DATE_LONG); } $ds->publish_period = sprintf(Pinhole::_('Added %s'), $period); } else { $ds->publish_period = null; } $store->add($ds); } return $store; }