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);
 }
示例#2
0
 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.');
     }
 }
示例#3
0
    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()));
        }
    }
示例#4
0
 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.'));
     }
 }
示例#5
0
    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');
        }
    }
示例#6
0
    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);
    }
 public function build()
 {
     if (isset($this->layout->navbar)) {
         $this->buildNavBar();
     }
     $this->layout->startCapture('content');
     Blorg::displayAd($this->app, 'top');
     $this->displayPosts();
     Blorg::displayAd($this->app, 'bottom');
     $this->layout->endCapture();
     $date = new SwatDate();
     $date->setDate($this->year, $this->month, 1);
     $date->setTZ($this->app->default_time_zone);
     $this->layout->data->title = $date->formatLikeIntl(SwatDate::DF_MY);
 }
示例#8
0
 protected function buildInternal()
 {
     parent::buildInternal();
     $message = $this->ui->getWidget('confirmation_message');
     $message->content = $this->getConfirmationMessage();
     $message->content_type = 'text/xml';
     $date = new SwatDate();
     $date->setTZ($this->app->default_time_zone);
     $note = sprintf(Deliverance::_('Scheduled times in ' . '<strong>%s</strong>. Leave date and time blank to send ' . 'immediately.'), $date->formatTZ(SwatDate::TZ_COMBINED));
     $this->ui->getWidget('send_date_field')->note = $note;
     $this->ui->getWidget('send_date_field')->note_content_type = 'txt/xml';
 }
示例#9
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;
 }