Exemple #1
0
    public static function isShortnameValid(SiteApplication $app, BlorgPost $post)
    {
        // get publish date in local time
        if ($post->publish_date === null) {
            $publish_date = new SwatDate();
            $publish_date->convertTZ($app->default_time_zone);
        } else {
            $publish_date = clone $post->publish_date;
            $publish_date->setTZ($app->default_time_zone);
        }
        $instance_id = $app->getInstanceId();
        $sql = 'select shortname from BlorgPost
			where shortname = %s and instance %s %s and id %s %s
			and date_trunc(\'month\', convertTZ(publish_date, %s)) =
				date_trunc(\'month\', timestamp %s)';
        $sql = sprintf($sql, $app->db->quote($post->shortname, 'text'), SwatDB::equalityOperator($instance_id), $app->db->quote($instance_id, 'integer'), SwatDB::equalityOperator($post->id, true), $app->db->quote($post->id, 'integer'), $app->db->quote($publish_date->getTimezone()->getName(), 'text'), $app->db->quote($publish_date->getDate(), 'date'));
        $query = SwatDB::query($app->db, $sql);
        return count($query) == 0;
    }
Exemple #2
0
 protected function loadDBData()
 {
     $this->ui->setValues(get_object_vars($this->post));
     $this->bodytext_control->value = $this->post->bodytext;
     $this->extended_bodytext_control->value = $this->post->extended_bodytext;
     if ($this->post->publish_date !== null) {
         $publish_date = new SwatDate($this->post->publish_date);
         $publish_date->convertTZ($this->app->default_time_zone);
         $this->ui->getWidget('publish')->setPublishDate($publish_date, $this->post->enabled === false);
     }
     $this->ui->getWidget('author')->value = $this->post->author->id;
     $tags = array();
     foreach ($this->post->tags as $tag) {
         $tags[$tag->shortname] = $tag->title;
     }
     $this->ui->getWidget('tags')->setSelectedTagArray($tags);
 }
 protected function getQuarters(CMEProvider $provider)
 {
     $quarters = array();
     $now = new SwatDate();
     $now->convertTZ($this->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->default_time_zone);
     $end_date = clone $start_date;
     $end_date->addMonths(3);
     $display_end_date = clone $end_date;
     $display_end_date->subtractMonths(1);
     while ($end_date->before($now)) {
         for ($quarter = 1; $quarter <= 4; $quarter++) {
             // Make sure the quarter has ended before generating the
             // report. Reports are cached and are not regenerated when new
             // data is available. If reports are generated for partial
             // quarters, the partial report is cached until the cache is
             // manually cleared.
             if ($end_date->after($now)) {
                 break;
             }
             $num_credits = $this->getQuarterEarnedCredits($provider, $year, $quarter);
             if ($num_credits > 0) {
                 $quarters[] = clone $start_date;
             }
             $start_date->addMonths(3);
             $end_date->addMonths(3);
             $display_end_date->addMonths(3);
         }
         $year++;
     }
     return $quarters;
 }