本文整理汇总了PHP中DateUtil::init方法的典型用法代码示例。如果您正苦于以下问题:PHP DateUtil::init方法的具体用法?PHP DateUtil::init怎么用?PHP DateUtil::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateUtil
的用法示例。
在下文中一共展示了DateUtil::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* @see Form::save()
*/
public function save()
{
parent::save();
// build timestamps
$untilDate = intval(gmmktime(24, 0, 0, $this->untilMonth, $this->untilDay, intval($this->untilYear)));
$fromDate = intval(gmmktime(0, 0, 0, $this->fromMonth, $this->fromDay, intval($this->fromYear)));
// build sql date format
switch ($this->groupBy) {
case 'day':
$sqlDateFormat = '%Y%m%d';
break;
case 'week':
$sqlDateFormat = '%Y%u';
break;
default:
$sqlDateFormat = '%Y%m';
}
// get selected timezone
DateUtil::init();
$timezoneStr = str_replace('.', ':', sprintf("%+06.2f", DateUtil::$timezone));
// build sql
$results = array();
$max = 0;
$sql = "SELECT\t\tCOUNT(*) AS count, \n\t\t\t\t\tDATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(" . $this->types[$this->type]->dateFieldName . "),@@session.time_zone,'" . escapeString($timezoneStr) . "'),'" . $sqlDateFormat . "') AS groupBy,\n\t\t\t\t\tAVG(" . $this->types[$this->type]->dateFieldName . ") AS date\n\t\t\tFROM\t\t" . $this->types[$this->type]->tableName . "\n\t\t\tWHERE\t\t" . ($this->userObj !== null && $this->types[$this->type]->userFieldName ? $this->types[$this->type]->userFieldName . " = " . $this->userObj->userID . " AND" : '') . "\n\t\t\t\t\t" . $this->types[$this->type]->dateFieldName . " > " . $fromDate . "\n\t\t\t\t\tAND " . $this->types[$this->type]->dateFieldName . " < " . $untilDate . "\n\t\t\tGROUP BY \tgroupBy\n\t\t\tORDER BY\t" . $this->sortField . " " . $this->sortOrder;
$result = WCF::getDB()->sendQuery($sql);
while ($row = WCF::getDB()->fetchArray($result)) {
$results[] = $row;
if ($row['count'] > $max) {
$max = $row['count'];
}
}
WCF::getTPL()->assign(array('results' => $results, 'max' => $max, 'dateFormat' => WCF::getLanguage()->get($this->groupBy == 'day' ? 'wcf.global.dateFormatLocalized' : 'wcf.acp.stats.dateFormat.' . $this->groupBy)));
}