/** * @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))); }