当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTimeHelper::formatTimeForDb方法代码示例

本文整理汇总了PHP中DateTimeHelper::formatTimeForDb方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeHelper::formatTimeForDb方法的具体用法?PHP DateTimeHelper::formatTimeForDb怎么用?PHP DateTimeHelper::formatTimeForDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeHelper的用法示例。


在下文中一共展示了DateTimeHelper::formatTimeForDb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getNextAnnouncement

 /**
  * Returns the next active announcement.
  *
  * @param string $timeInAdvance
  *
  * @return AnnouncementModel
  */
 public function getNextAnnouncement($timeInAdvance = '0')
 {
     $time = DateTimeHelper::currentUTCDateTime();
     $time->modify('+' . $timeInAdvance);
     $announcementRecord = craft()->db->createCommand()->select('*')->from('maintenance_announcements')->where(array('and', array('or', 'blockSite = 1', 'blockCp = 1'), 'startDate <= :time', array('or', 'endDate >= :now', 'endDate IS NULL')), array(':now' => DateTimeHelper::formatTimeForDb(), ':time' => DateTimeHelper::formatTimeForDb($time)))->order('startDate desc')->queryRow();
     if ($announcementRecord) {
         return Maintenance_AnnouncementModel::populateModel($announcementRecord);
     }
 }
开发者ID:carlcs,项目名称:craft-maintenance,代码行数:16,代码来源:MaintenanceService.php

示例2: log

 /**
  * Logs a new deprecation error.
  *
  * @param string $key
  * @param string $message
  *
  * @return bool
  */
 public function log($key, $message)
 {
     $log = new DeprecationErrorModel();
     $log->key = $key;
     $log->message = $message;
     $log->lastOccurrence = DateTimeHelper::currentTimeForDb();
     $log->template = craft()->request->isSiteRequest() ? craft()->templates->getRenderingTemplate() : null;
     // Everything else requires the stack trace
     $this->_populateLogWithStackTraceData($log);
     // Don't log the same key/fingerprint twice in the same request
     if (!isset($this->_fingerprints[$log->key]) || !in_array($log->fingerprint, $this->_fingerprints[$log->key])) {
         craft()->db->createCommand()->insertOrUpdate(static::$_tableName, array('key' => $log->key, 'fingerprint' => $log->fingerprint), array('lastOccurrence' => DateTimeHelper::formatTimeForDb($log->lastOccurrence), 'file' => $log->file, 'line' => $log->line, 'class' => $log->class, 'method' => $log->method, 'template' => $log->template, 'templateLine' => $log->templateLine, 'message' => $log->message, 'traces' => JsonHelper::encode($log->traces)));
         $this->_fingerprints[$key][] = $log->fingerprint;
     }
     return true;
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:24,代码来源:DeprecatorService.php

示例3: purgeExpiredPendingUsers

 /**
  * Deletes any pending users that have shown zero sense of urgency and are just taking up space.
  *
  * This method will check the
  * [purgePendingUsersDuration](http://buildwithcraft.com/docs/config-settings#purgePendingUsersDuration) config
  * setting, and if it is set to a valid duration, it will delete any user accounts that were created that duration
  * ago, and have still not activated their account.
  *
  * @return null
  */
 public function purgeExpiredPendingUsers()
 {
     if (($duration = craft()->config->get('purgePendingUsersDuration')) !== false) {
         $interval = new DateInterval($duration);
         $expire = DateTimeHelper::currentUTCDateTime();
         $pastTimeStamp = $expire->sub($interval)->getTimestamp();
         $pastTime = DateTimeHelper::formatTimeForDb($pastTimeStamp);
         $ids = craft()->db->createCommand()->select('id')->from('users')->where('pending=1 AND verificationCodeIssuedDate < :pastTime', array(':pastTime' => $pastTime))->queryColumn();
         $affectedRows = craft()->db->createCommand()->delete('elements', array('in', 'id', $ids));
         if ($affectedRows > 0) {
             Craft::log('Just deleted ' . $affectedRows . ' pending users from the users table, because the were more than ' . $duration . ' old', LogLevel::Info, true);
         }
     }
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:24,代码来源:UsersService.php

示例4: packageAttributeValue

 /**
  * Takes an attribute's config and value and "normalizes" them either for saving to db or sending across a web
  * service.
  *
  * @param mixed $value
  * @param bool  $jsonEncodeArrays
  *
  * @return int|mixed|null|string
  */
 public static function packageAttributeValue($value, $jsonEncodeArrays = false)
 {
     if ($value instanceof \DateTime) {
         return DateTimeHelper::formatTimeForDb($value->getTimestamp());
     }
     if ($value instanceof BaseModel) {
         $attributes = $value->getAttributes(null, true);
         if ($value instanceof ElementCriteriaModel) {
             $attributes['__criteria__'] = $value->getElementType()->getClassHandle();
         } else {
             $attributes['__model__'] = get_class($value);
         }
         $value = $attributes;
     }
     if (is_array($value)) {
         // Flatten each of its keys
         foreach ($value as $key => $val) {
             $value[$key] = static::packageAttributeValue($val);
         }
         if ($jsonEncodeArrays) {
             return JsonHelper::encode($value);
         } else {
             return $value;
         }
     }
     if (is_bool($value)) {
         return $value ? 1 : 0;
     }
     return $value;
 }
开发者ID:webremote,项目名称:Craft-Release,代码行数:39,代码来源:ModelHelper.php

示例5: modifyElementsQuery

 /**
  * Modifies an element query targeting elements of this type.
  *
  * @param DbCommand $query
  * @param ElementCriteriaModel $criteria
  * @return mixed
  */
 public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
 {
     $query->addSelect('venti.startDate, venti.endDate, venti.allDay, venti.isrepeat, venti.eid, venti.eventid, venti.repeat, venti.rRule, venti.summary, venti.locale, entries.postDate, entries.expiryDate')->leftJoin('venti_events venti', 'venti.eventid = elements.id')->leftJoin('entries entries', 'entries.id = eventid')->group('venti.startDate');
     if ($criteria->locale) {
         $query->andWhere(DbHelper::parseParam('venti.locale', $criteria->locale, $query->params));
     }
     if ($criteria->startDate) {
         $query->andWhere(DbHelper::parseDateParam('venti.startDate', $criteria->startDate, $query->params));
     }
     if ($criteria->id) {
         $query->andWhere(DbHelper::parseParam('venti.eventid', $criteria->eventid, $query->params));
     }
     if ($criteria->eventid) {
         $query->andWhere(DbHelper::parseParam('venti.eventid', $criteria->eventid, $query->params));
     }
     if ($criteria->endDate) {
         $query->andWhere(DbHelper::parseDateParam('venti.endDate', $criteria->endDate, $query->params));
     }
     if ($criteria->summary) {
         $query->andWhere(DbHelper::parseParam('venti.summary', $criteria->summary, $query->params));
     }
     if ($criteria->isrepeat) {
         $query->andWhere(DbHelper::parseParam('venti.isrepeat', $criteria->isrepeat, $query->params));
     }
     if ($criteria->rRule) {
         $query->andWhere(DbHelper::parseParam('venti.rRule', $criteria->rRule, $query->params));
     }
     if ($criteria->eid) {
         $query->andWhere(DbHelper::parseParam('venti.eid', $criteria->eid, $query->params));
     }
     if ($criteria->repeat) {
         $query->andWhere(DbHelper::parseParam('venti.repeat', $criteria->repeat, $query->params));
     }
     if ($criteria->allDay) {
         $query->andWhere(DbHelper::parseDateParam('venti.allDay', $criteria->allDay, $query->params));
     }
     if ($criteria->between) {
         $dates = array();
         $interval = array();
         if (!is_array($criteria->between)) {
             $criteria->between = ArrayHelper::stringToArray($criteria->between);
         }
         if (count($criteria->between) == 2) {
             foreach ($criteria->between as $ref) {
                 if (!$ref instanceof \DateTime) {
                     $dates[] = DateTime::createFromString($ref, craft()->getTimeZone());
                 } else {
                     $dates[] = $ref;
                 }
             }
             if ($dates[0] > $dates[1]) {
                 $interval[0] = $dates[1];
                 $interval[1] = $dates[0];
             } else {
                 $interval = $dates;
             }
             $query->andWhere('(venti.startDate BETWEEN :betweenStartDate AND :betweenEndDate) OR (:betweenStartDate BETWEEN venti.startDate AND venti.endDate)', array(':betweenStartDate' => DateTimeHelper::formatTimeForDb($interval[0]->getTimestamp()), ':betweenEndDate' => DateTimeHelper::formatTimeForDb($interval[1]->getTimestamp())));
         }
     }
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:67,代码来源:Venti_EventElementType.php

示例6: prepDate

 public function prepDate($data, $field)
 {
     return DateTimeHelper::formatTimeForDb(DateTimeHelper::fromString($data, craft()->timezone));
 }
开发者ID:Tcheu,项目名称:FeedMe,代码行数:4,代码来源:FeedMe_FieldsService.php

示例7: parseDateParam

 /**
  * Parses a date param value to a DbCommand where condition.
  *
  * @param string $key
  * @param string $operator
  * @param string|array|DateTime $dates
  * @param array &$params
  * @return mixed
  */
 public static function parseDateParam($key, $operator, $dates, &$params)
 {
     $conditions = array();
     $dates = ArrayHelper::stringToArray($dates);
     foreach ($dates as $date) {
         if (!$date instanceof \DateTime) {
             $date = DateTime::createFromString($date, Craft::getTimezone());
         }
         $param = ':p' . StringHelper::randomString(9);
         $params[$param] = DateTimeHelper::formatTimeForDb($date->getTimestamp());
         $conditions[] = $key . $operator . $param;
     }
     if (count($conditions) == 1) {
         return $conditions[0];
     } else {
         array_unshift($conditions, 'or');
         return $conditions;
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:28,代码来源:DbHelper.php

示例8: formatStartDate

 /**
  * Convert date to MYSQL_DATETIME in UTC
  *
  * @return  Craft\DateTime
  */
 public function formatStartDate(\DateTime $date)
 {
     $temp = DateTimeHelper::formatTimeForDb($date->getTimestamp());
     return DateTime::createFromFormat(DateTime::MYSQL_DATETIME, $temp);
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:10,代码来源:Venti_EventManageService.php

示例9: prepForFieldType


//.........这里部分代码省略.........
                         }
                     }
                     // Find matching element in sources
                     $criteria = craft()->elements->getCriteria(ElementType::User);
                     $criteria->groupId = $groupIds;
                     $criteria->limit = $settings->limit;
                     // Get search strings
                     $search = ArrayHelper::stringToArray($data);
                     // Ability to import multiple Users at once
                     $data = array();
                     // Loop through keywords
                     foreach ($search as $query) {
                         // Search
                         $criteria->search = $query;
                         // Add to data
                         $data = array_merge($data, $criteria->ids());
                     }
                 } else {
                     // Return empty array
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeTags:
                 // Get field settings
                 $settings = $field->getFieldType()->getSettings();
                 // Get tag group id
                 $source = $settings->getAttribute('source');
                 list($type, $groupId) = explode(':', $source);
                 $tags = ArrayHelper::stringToArray($data);
                 $data = array();
                 foreach ($tags as $tag) {
                     // Find existing tag
                     $criteria = craft()->elements->getCriteria(ElementType::Tag);
                     $criteria->title = $tag;
                     $criteria->groupId = $groupId;
                     if (!$criteria->total()) {
                         // Create tag if one doesn't already exist
                         $newtag = new TagModel();
                         $newtag->getContent()->title = $tag;
                         $newtag->groupId = $groupId;
                         // Save tag
                         if (craft()->tags->saveTag($newtag)) {
                             $tagArray = array($newtag->id);
                         }
                     } else {
                         $tagArray = $criteria->ids();
                     }
                     // Add tags to data array
                     $data = array_merge($data, $tagArray);
                 }
                 break;
             case ImportModel::FieldTypeNumber:
                 // Parse as number
                 $data = LocalizationHelper::normalizeNumber($data);
                 // Parse as float
                 $data = floatval($data);
                 break;
             case ImportModel::FieldTypeDate:
                 // Parse date from string
                 $data = DateTimeHelper::formatTimeForDb(DateTimeHelper::fromString($data, craft()->timezone));
                 break;
             case ImportModel::FieldTypeRadioButtons:
             case ImportModel::FieldTypeDropdown:
                 //get field settings
                 $settings = $field->getFieldType()->getSettings();
                 //get field options
                 $options = $settings->getAttribute('options');
                 // find matching option label
                 $labelSelected = false;
                 foreach ($options as $option) {
                     if ($labelSelected) {
                         continue;
                     }
                     if ($data == $option['label']) {
                         $data = $option['value'];
                         //stop looking after first match
                         $labelSelected = true;
                     }
                 }
                 break;
             case ImportModel::FieldTypeCheckboxes:
             case ImportModel::FieldTypeMultiSelect:
                 // Convert to array
                 $data = ArrayHelper::stringToArray($data);
                 break;
             case ImportModel::FieldTypeLightSwitch:
                 // Convert yes/no values to boolean
                 switch ($data) {
                     case Craft::t('Yes'):
                         $data = true;
                         break;
                     case Craft::t('No'):
                         $data = false;
                         break;
                 }
                 break;
         }
     }
     return $data;
 }
开发者ID:ianshea,项目名称:import,代码行数:101,代码来源:ImportService.php

示例10: hasUserShunnedMessage

 /**
  * Returns whether a message is shunned for a user.
  *
  * @param int      $userId
  * @param string   $message
  * @return bool
  */
 public function hasUserShunnedMessage($userId, $message)
 {
     $row = craft()->db->createCommand()->select('id')->from('shunnedmessages')->where(array('and', 'userId = :userId', 'message = :message', array('or', 'expiryDate IS NULL', 'expiryDate > :now')), array(':userId' => $userId, ':message' => $message, ':now' => DateTimeHelper::formatTimeForDb()))->queryRow(false);
     return (bool) $row;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:12,代码来源:UsersService.php

示例11: applyDateCriteria

 /**
  * Apply date criteria.
  *
  * @param ElementCriteriaModel $criteria
  * @param DbCommand            $query
  */
 private function applyDateCriteria(ElementCriteriaModel $criteria, DbCommand $query)
 {
     // Check for date modified
     if (!empty($criteria->modified)) {
         $query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', $criteria->modified, $query->params));
     }
     // Check for date from
     if (!empty($criteria->from)) {
         $query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', '>= ' . DateTimeHelper::formatTimeForDb($criteria->from), $query->params));
     }
     // Check for date to
     if (!empty($criteria->to)) {
         $criteria->to->add(new DateInterval('PT23H59M59S'));
         $query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', '<= ' . DateTimeHelper::formatTimeForDb($criteria->to), $query->params));
     }
 }
开发者ID:boboldehampsink,项目名称:auditlog,代码行数:22,代码来源:AuditLogElementType.php

示例12: parseDateParam

 /**
  * Normalizes date params and then sends them off to parseParam().
  *
  * @param string                $column
  * @param string|array|DateTime $value
  * @param array                 &$params
  *
  * @return mixed
  */
 public static function parseDateParam($column, $value, &$params)
 {
     $normalizedValues = array();
     $value = ArrayHelper::stringToArray($value);
     if (!count($value)) {
         return '';
     }
     if ($value[0] == 'and' || $value[0] == 'or') {
         $normalizedValues[] = $value[0];
         array_shift($value);
     }
     foreach ($value as $val) {
         // Is this an empty value?
         static::_normalizeEmptyValue($val);
         if ($val == ':empty:' || $val == 'not :empty:') {
             $normalizedValues[] = $val;
             // Sneak out early
             continue;
         }
         if (is_string($val)) {
             $operator = static::_parseParamOperator($val);
         } else {
             $operator = '=';
         }
         if (!$val instanceof \DateTime) {
             $val = DateTime::createFromString($val, craft()->getTimeZone());
         }
         $normalizedValues[] = $operator . DateTimeHelper::formatTimeForDb($val->getTimestamp());
     }
     return static::parseParam($column, $normalizedValues, $params);
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:40,代码来源:DbHelper.php

示例13: prepForFieldType

 /**
  * Prepare fields for fieldtypes.
  *
  * @param string &$data
  * @param string $handle
  *
  * @return mixed
  */
 public function prepForFieldType(&$data, $handle)
 {
     // Fresh up $data
     $data = StringHelper::convertToUTF8($data);
     $data = trim($data);
     // Get field info
     $field = craft()->fields->getFieldByHandle($handle);
     // If it's a field ofcourse
     if (!is_null($field)) {
         // For some fieldtypes the're special rules
         switch ($field->type) {
             case ImportModel::FieldTypeEntries:
                 // No newlines allowed
                 $data = str_replace("\n", '', $data);
                 $data = str_replace("\r", '', $data);
                 // Don't connect empty fields
                 if (!empty($data)) {
                     $data = $this->prepEntriesFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeCategories:
                 if (!empty($data)) {
                     $data = $this->prepCategoriesFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeAssets:
                 if (!empty($data)) {
                     $data = $this->prepAssetsFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeUsers:
                 if (!empty($data)) {
                     $data = $this->prepUsersFieldType($data, $field);
                 } else {
                     $data = array();
                 }
                 break;
             case ImportModel::FieldTypeTags:
                 $data = $this->prepTagsFieldType($data, $field);
                 break;
             case ImportModel::FieldTypeNumber:
                 // Parse as numberx
                 $data = LocalizationHelper::normalizeNumber($data);
                 // Parse as float
                 $data = floatval($data);
                 break;
             case ImportModel::FieldTypeDate:
                 // Parse date from string
                 $data = DateTimeHelper::formatTimeForDb(DateTimeHelper::fromString($data, craft()->timezone));
                 break;
             case ImportModel::FieldTypeRadioButtons:
             case ImportModel::FieldTypeDropdown:
                 //get field settings
                 $data = $this->prepDropDownFieldType($data, $field);
                 break;
             case ImportModel::FieldTypeCheckboxes:
             case ImportModel::FieldTypeMultiSelect:
                 // Convert to array
                 $data = ArrayHelper::stringToArray($data);
                 break;
             case ImportModel::FieldTypeLightSwitch:
                 // Convert yes/no values to boolean
                 switch ($data) {
                     case Craft::t('Yes'):
                         $data = true;
                         break;
                     case Craft::t('No'):
                         $data = false;
                         break;
                 }
                 break;
         }
     }
     return $data;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:89,代码来源:ImportService.php

示例14: parseDateParam

 /**
  * Normalizes date params and then sends them off to parseParam().
  *
  * @param string                $key
  * @param string|array|DateTime $values
  * @param array                 &$params
  *
  * @return mixed
  */
 public static function parseDateParam($key, $values, &$params)
 {
     $normalizedValues = array();
     $values = ArrayHelper::stringToArray($values);
     if (!count($values)) {
         return '';
     }
     if ($values[0] == 'and' || $values[0] == 'or') {
         $normalizedValues[] = $values[0];
         array_shift($values);
     }
     foreach ($values as $value) {
         if (is_string($value)) {
             $operator = static::_parseParamOperator($value);
         } else {
             $operator = '=';
         }
         if (!$value instanceof \DateTime) {
             $value = DateTime::createFromString($value, craft()->getTimeZone());
         }
         $normalizedValues[] = $operator . DateTimeHelper::formatTimeForDb($value->getTimestamp());
     }
     return static::parseParam($key, $normalizedValues, $params);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:33,代码来源:DbHelper.php

示例15: packageAttributeValue

 /**
  * Takes an attribute's config and value and "normalizes" them either for saving to db or sending across a web service.
  *
  * @param      $value
  * @param bool $jsonEncodeArrays
  * @internal param $storedValue
  * @return int|mixed|null|string
  */
 public static function packageAttributeValue($value, $jsonEncodeArrays = false)
 {
     if ($value instanceof \DateTime) {
         return DateTimeHelper::formatTimeForDb($value->getTimestamp());
     }
     if ($value instanceof \CModel) {
         $value = $value->getAttributes();
     }
     if (is_array($value)) {
         // Flatten each of its keys
         foreach ($value as $key => $val) {
             $value[$key] = static::packageAttributeValue($val);
         }
         if ($jsonEncodeArrays) {
             return JsonHelper::encode($value);
         } else {
             return $value;
         }
     }
     if (is_bool($value)) {
         return $value ? 1 : 0;
     }
     return $value;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:32,代码来源:ModelHelper.php


注:本文中的DateTimeHelper::formatTimeForDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。