public static function saveStatistic($model, $event) { $model_events = config('quickcms.model_events'); foreach ($model_events as $model_event) { if ($model->getTable() == $model_event['table'] && $model_event['event'] == $event && (array_key_exists('where', $model_event) ? $model->{$model_event}['where']['column'] == $model_event['where']['value'] : true)) { $statistic = Statistic::select('id', 'statistic_value')->where('statistic_key', $model_event['statistic_key'])->whereRaw("statistic_time=date_format(now(),'%Y-%m-%d')")->first(); $statistic_value = $model_event['statistic_value'] == 1 ? 1 : $model->{$model_event}['statistic_value']; if (!isset($statistic)) { $statistic = new Statistic(); $statistic->statistic_value += $statistic_value; $statistic->sort = $model_event['sort']; $statistic->statistic_time = date('Y-m-d', time()); $statistic->statistic_key = $model_event['statistic_key']; $statistic->save(); } else { $statistic->statistic_value += $statistic_value; $statistic->save(); } } } }
public function statistic() { $qq = count(User::where('qq_id', '!=', 'null')->get()); $weixin = count(User::where('unionid', '!=', 'null')->get()); $s = Statistic::find(1); if (isset($s)) { $s->qq = $qq; $s->weixin = $weixin; $s->save(); } else { $s = new Statistic(); $s->qq = $qq; $s->weixin = $weixin; $s->save(); } return true; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new FileForm(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['FileForm'])) { $file = new File(); $file->name = $_POST['FileForm']['name']; $slug = $file->generateRandomString(); while (true) { $invalidSlug = File::model()->findByAttributes(array('slug' => $slug)); if (!$invalidSlug) { break; } } $file->slug = $slug; if ($file->save()) { $fileFormTypeArray = $file->fileType(); foreach ($fileFormTypeArray as $fileType) { if (trim($_POST['FileForm'][$fileType]) != "") { $url = new Url(); $url->type = $fileType; $url->file_id = $file->id; $url->day_update = date('d'); $url->month_update = date('m'); $url->url = $_POST['FileForm'][$fileType]; $url->save(); } } $statistic = new Statistic(); $statistic->file_id = $file->id; $statistic->date = date('dmY'); $statistic->save(); } $this->redirect(array('admin')); } $this->render('create', array('model' => $model)); }
/** * Если пользователь зарегистрировался и сохранился то возвращаем //тру * * @return boolean */ public function checkAndLoginNewplayer() { if ($this->validate()) { // Если пароли не совпадают выдадим ошибку if ($this->password != $this->password_repeat) { $this->addError('password', 'Вы указали разные значения в поле пароль'); return false; } else { $this->password = md5($this->password); $this->date_regist = time(); if ($this->save()) { // Отправить письмо с подтверждением email $this->sendAndCheckEmail(); // Проверка и создание реферала $session = new CHttpSession(); $session->open(); if (isset($session['ref_id'])) { $player = Player::model()->findByAttributes(array('id' => (int) $session['ref_id'])); if ($player != null) { $referal = new Referals(); $referal->id_player = $player->id; $referal->id_referal = $this->id; $referal->is_active = Referals::$NOT_ACTIVE; $referal->save(); } } $statistic = new Statistic(); $statistic->id_player = $this->id; $statistic->invest_summ = 0; $statistic->out_sum = 0; $statistic->questions_summ_complette = 0; $statistic->referals = 0; $statistic->save(); $identity = new UserIdentity($this->email, $this->password); $identity->authenticate(); Yii::app()->user->login($identity, 0); return true; } else { return false; } } } else { return false; } }
public function actionPostStatistics() { $id = Yii::app()->request->getParam('id'); $data = Yii::app()->request->getRawBody(); if ($id === null || !is_int(intval($id))) { http_response_code(400); echo sprintf("Incorrect id. Id: %s", $id); exit; } if ($data === null || !is_string(strval($data))) { http_response_code(400); echo sprintf("Incorrect statistic data. Data: %s", $data); exit; } $pointId = intval($id); $decodedData = json_decode(strval($data), true); if ($decodedData === null) { try { $CM = Yii::app()->contentManager; $pointDir = "spool/points/" . $pointId . "/" . data('Y-m-d'); $pointDir = $CM->PrepareSpoolPath($pointDir); $handle = fopen($pointDir . "/statistic.txt", "w"); fwrite($handle, $data); fclose($handle); } catch (Exception $e) { http_response_code(500); echo sprintf("Saving data error. Exc: %s", json_encode($e)); exit; } http_response_code(400); echo sprintf("Incorrect statistic data format. JSON decoding error. Data: %s", $data); exit; } foreach ($decodedData as $value) { if (!$value['meta']) { http_response_code(400); echo sprintf("Incorrect statistic data format. Empty meta in row %s. Data: %s", json_encode($value), $data); exit; } $explodedMeta = explode(';', $value['meta']); if (count($explodedMeta) !== 4) { http_response_code(400); echo sprintf("Incorrect statistic data format. Broken meta in row %s. Data: %s", json_encode($value), $data); exit; } $duration = explode(':', $explodedMeta[0]); if (!isset($duration[0]) || !isset($duration[1]) || !is_float(floatval($duration[1])) || $duration[0] !== 'duration') { http_response_code(400); echo sprintf("Incorrect statistic data format. Broken meta in row %s. No duration set. Data: %s", json_encode($value), $data); exit; } $duration = floatval($duration[1]); $idFile = explode(':', $explodedMeta[1]); if (!isset($idFile[0]) || !isset($idFile[1]) || !is_int(intval($idFile[1])) || $idFile[0] !== 'file') { http_response_code(400); echo sprintf("Incorrect statistic data format. Broken meta in row %s. No file id. Data: %s", json_encode($value), $data); exit; } $idFile = intval($idFile[1]); $idPlaylist = explode(':', $explodedMeta[2]); if (!isset($idPlaylist[0]) || !isset($idPlaylist[1]) || !is_int(intval($idPlaylist[1])) || $idPlaylist[0] !== 'pl') { http_response_code(400); echo sprintf("Incorrect statistic data format. Broken meta in row %s. No playlist id. Data: %s", json_encode($value), $data); exit; } $idPlaylist = intval($idPlaylist[1]); $idAuthor = explode(':', $explodedMeta[3]); if (!isset($idAuthor[0]) || !isset($idAuthor[1]) || !is_int(intval($idAuthor[1])) || $idAuthor[0] !== 'author') { http_response_code(400); echo sprintf("Incorrect statistic data format. Broken meta in row %s. No author id. Data: %s", json_encode($value), $data); exit; } $idAuthor = intval($idAuthor[1]); if (!$value['channel'] || !$value['file'] || !$value['date'] || !$value['time'] || !is_int(intval($value['channel'])) || !is_string(strval($value['file'])) || !is_string(strval($value['date'])) || !is_string(strval($value['time']))) { http_response_code(400); echo sprintf("Incorrect statistic data format. Broken row structure %s. Data: %s", json_encode($value), $data); exit; } $channel = intval($value['channel']); $fileName = strval($value['file']); $date = strval($value['date']); $time = strval($value['time']); $year = substr((string) $date, 0, 4); $month = substr((string) $date, 4, 2); $day = substr((string) $date, 6, 2); $hours = substr((string) $time, 0, 2); $minutes = substr((string) $time, 3, 2); $seconds = substr((string) $time, 6, 2); $statistic = new Statistic(); $statistic->dt_playback = $year . '-' . $month . '-' . $day . ' ' . $hours . ':' . $minutes . ':' . $seconds; $statistic->duration = $duration; $statistic->file_name = substr($fileName, 0, 255); $statistic->channel = $channel; $statistic->id_point = $pointId; $statistic->id_file = $idFile; $statistic->id_playlist = $idPlaylist; $statistic->id_author = $idAuthor; $statistic->save(); } echo 'ok'; }
public function resetClick() { $url = Url::model()->findBySql("SELECT * FROM " . $this->tableName() . " ORDER BY id DESC"); if ($url->day_update != date('d')) { Url::model()->updateAll(array('day_update' => date('d'), 'day_click' => 0, 'total' => 0)); if ($url->month_update != date('m')) { Url::model()->updateAll(array('month_update' => date('m'), 'month_click' => 0)); } $files = File::model()->findAll(array('order' => 'id')); foreach ($files as $file) { $statistic = new Statistic(); $statistic->file_id = $file->id; $statistic->date = date('dmY'); $statistic->save(); } } }