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())); } }
public function getDate() { $unix_time = strtotime($this->status->created_at); $date = new SwatDate(); $date->setTimestamp($unix_time); $date->toUTC(); return $date; }
public function getDate() { $unix_time = strtotime($this->campaign['send_time']); $date = new SwatDate(); $date->setTimestamp($unix_time); $date->toUTC(); return $date; }
/** * Saves this object to the database * * Only modified properties are updated. */ protected function saveInternal() { if ($this->id === null) { $this->shortname = $this->generateShortname($this->title); $this->createdate = new SwatDate(); $this->createdate->toUTC(); } parent::saveInternal(); }
public function getDate() { $date_string = $this->xpath->evaluate("string(pubDate)", $this->element); $unix_time = strtotime($date_string); $date = new SwatDate(); $date->setTimestamp($unix_time); $date->toUTC(); return $date; }
public function isSent() { $sent = false; if ($this->send_date instanceof SwatDate) { $send_date = clone $this->send_date; $send_date->toUTC(); $now = new SwatDate(); $now->toUTC(); $sent = $now->after($this->send_date); } return $sent; }
protected function saveDBData() { $values = $this->ui->getValues(array('title', 'shortname')); $this->tag->title = $values['title']; -($this->tag->shortname = $values['shortname']); if ($this->id === null) { $now = new SwatDate(); $now->toUTC(); $this->tag->createdate = $now; $this->tag->instance = $this->app->getInstanceId(); } if ($this->tag->isModified()) { $this->tag->save(); if (isset($this->app->memcache)) { $this->app->memcache->flushNs('tags'); // only clear the posts when editing an existing tag if ($this->id !== null) { $this->app->memcache->flushNs('posts'); } } $message = new SwatMessage(sprintf(Blorg::_('“%s” has been saved.'), $this->tag->title)); $this->app->messages->add($message); } }
protected function updatePost() { $values = $this->ui->getValues(array('title', 'shortname', 'author', 'comment_status')); $values['bodytext'] = $this->bodytext_control->value; $values['extended_bodytext'] = $this->extended_bodytext_control->value; $this->post->author = $values['author']; $this->post->title = $values['title']; $this->post->shortname = $values['shortname']; $this->post->comment_status = $values['comment_status']; $this->post->bodytext = $values['bodytext']; $this->post->extended_bodytext = $values['extended_bodytext']; $this->post->bodytext_filter = $this->app->config->blorg->visual_editor ? 'visual' : 'raw'; // save default author for the current admin user $instance_id = $this->app->getInstanceId(); if ($this->id === null && $instance_id !== null) { $sql = sprintf('update AdminUserInstanceBinding set default_author = %s where usernum = %s and instance = %s', $this->app->db->quote($values['author'], 'integer'), $this->app->db->quote($this->app->session->user->id, 'integer'), $this->app->db->quote($instance_id, 'integer')); SwatDB::exec($this->app->db, $sql); } // set published date $publish = $this->ui->getWidget('publish'); $this->post->publish_date = $publish->getPublishDate(); if ($this->post->publish_date === null) { $this->post->publish_date = new SwatDate(); $this->post->publish_date->toUTC(); } else { $this->post->publish_date->setTZ($this->app->default_time_zone); $this->post->publish_date->toUTC(); } // set enabled (hidden) $this->post->enabled = $publish->value !== BlorgPublishRadioTable::HIDDEN; // set create/modified date $now = new SwatDate(); $now->toUTC(); if ($this->id === null) { $this->post->createdate = $now; $this->post->instance = $this->app->getInstanceId(); } else { if ($this->post->isModified()) { $this->post->modified_date = $now; } } }
protected function createBlorgFile(SwatFileEntry $file, $path) { $now = new SwatDate(); $now->toUTC(); $class_name = SwatDBClassMap::get('BlorgFile'); $blorg_file = new $class_name(); $blorg_file->setDatabase($this->app->db); $blorg_file->setFileBase($path); $blorg_file->createFileBase($path); $blorg_file->visible = false; $blorg_file->filename = $file->getUniqueFileName($path); $blorg_file->mime_type = $file->getMimeType(); $blorg_file->filesize = $file->getSize(); $blorg_file->createdate = $now; $blorg_file->instance = $this->app->getInstanceId(); $blorg_file->save(); $file->saveFile($path, $blorg_file->filename); return $blorg_file->id; }
protected function saveEarnedCredits(CMEAccount $account, CMEFrontMatter $front_matter) { $wrapper = SwatDBClassMap::get('CMEAccountEarnedCMECreditWrapper'); $class_name = SwatDBClassMap::get('CMEAccountEarnedCMECredit'); $earned_credits = new $wrapper(); $earned_date = new SwatDate(); $earned_date->toUTC(); foreach ($front_matter->credits as $credit) { if ($credit->isEarned($account)) { // check for existing earned credit before saving $sql = sprintf('select count(1) from AccountEarnedCMECredit where credit = %s and account = %s', $this->app->db->quote($credit->id, 'integer'), $this->app->db->quote($account->id, 'integer')); if (SwatDB::queryOne($this->app->db, $sql) == 0) { $earned_credit = new $class_name(); $earned_credit->account = $account->id; $earned_credit->credit = $credit->id; $earned_credit->earned_date = $now; $earned_credits->add($earned_credit); } } } $earned_credits->setDatabase($this->app->db); $earned_credits->save(); }
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 getPhotos() { // load the photos uploaded in the last day $date = new SwatDate(); $date->subtractDays(1); $date->toUTC(); $instance_id = $this->app->getInstance() === null ? null : $this->app->getInstanceId(); $sql = sprintf('select PinholePhoto.* from PinholePhoto inner join ImageSet on PinholePhoto.image_set = ImageSet.id where ImageSet.instance %s %s and PinholePhoto.dav_upload = %s and PinholePhoto.upload_date > %s order by original_filename asc', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean'), $this->app->db->quote($date->getDate(), 'date')); $photos = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('PinholeSimplePhotoWrapper')); return $photos; }
/** * 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 setPhotoValues() { $values = $this->getUIValues(); // turns the date back into UTC $photo_date = new SwatDate($values['photo_date']); $photo_date->setTZById($this->photo->photo_time_zone); $photo_date->toUTC(); $this->photo->title = $values['title']; $this->photo->description = $values['description']; $this->photo->photo_date = $photo_date; $this->photo->private = $values['private']; $this->photo->for_sale = $values['for_sale']; $this->photo->photo_time_zone = $values['photo_time_zone']; $this->photo->setStatus($values['status']); if ($this->ui->getWidget('comment_status_field')->visible) { $this->photo->comment_status = $values['comment_status']; } if ($this->photo->photo_time_zone === null) { $this->photo->photo_time_zone = $this->app->default_time_zone->getName(); } }
protected function resetQuiz(SwatForm $form) { // response can be null when refreshing the quiz page immediately after // resetting a quiz, or resetting it in another window, and attempting // to reset a second time. if (!$this->front_matter->resettable || !$this->response instanceof InquisitionResponse) { return; } $now = new SwatDate(); $now->toUTC(); $sql = sprintf('update InquisitionResponse set reset_date = %s where id = %s', $this->app->db->quote($now->getDate(), 'date'), $this->app->db->quote($this->response->id, 'integer')); SwatDB::exec($this->app->db, $sql); }