/** * @param GearmanJob|null $job * @return mixed */ public function execute(GearmanJob $job = null) { $data = $this->getWorkload($job)->getParams()['data']; // Создаем нужный элемент профилирования $listProfiler = ListProfiler::findOne(['message' => $data->message, 'project_id' => $data->project_id]); if (!$listProfiler) { $listProfiler = new ListProfiler(); $listProfiler->message = $data->message; $listProfiler->project_id = $data->project_id; } if (!$listProfiler->save()) { $job->sendStatus(400, 400); return false; } $model = new Profiler(); $model->date_create = \Yii::$app->formatter->asDate($data->date_create, 'yyyy-MM-dd H:m:s'); $model->project_id = $data->project_id; $model->type = $data->type; $model->message_id = $listProfiler->id; $model->duration = $data->duration; $model->time_start = $data->time_start; $model->time_end = $data->time_end; if (!$model->save()) { $job->sendStatus(400, 400); return false; } $job->sendStatus(200, 200); return true; }
/** * Тест методов валидации */ public function testValidate() { $model = new Profiler(); $this->specify('validate type', function () use($model) { $model->type = 1666; $model->validate(); $this->assertContains('Type message not found', $model->getErrors('type')); }); }
/** * @author Dianov German <*****@*****.**> * Find profiler by ID * @param $id profiler id */ protected function findModelListProfiler($id) { if (($model = Profiler::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Profiler not found'); } }
/** * Function get query filter * @param $messageid * @return ActiveQuery object */ public static function getQuery($messageId) { $filter = new Filter(); $filter->load(\Yii::$app->request->get()); $filter->validate(); $data = Profiler::find()->andWhere(['message_id' => $messageId])->andWhere(['>=', 'date_create', $filter->date_create_from])->andWhere(['<', 'date_create', $filter->date_create_to . ' 23:59']); return $data; }
/** * @return mixed */ public function getCount() { $table = \app\models\amop\models\Profiler::tableName(); if (is_array($this->_data)) { if (count($this->_data) <= 0) { return []; } $where = []; foreach ($this->_data as $key => $value) { $where[] = "([[message_id]] = {$key} AND [[date_create]] > '{$value}')"; } $where = implode(" OR ", $where); $data = \Yii::$app->db->createCommand("SELECT [[message_id]], count(*) as total FROM {{{$table}}} WHERE {$where} GROUP BY [[message_id]] ")->queryAll(); $result = ArrayHelper::map($data, 'message_id', 'total'); } else { throw new \InvalidArgumentException('Please set data as array'); } return $result; }
/** * @param GearmanJob|null $job * @return mixed */ public function execute(GearmanJob $job = null) { $data = $this->getWorkload($job)->getParams()['data']; if (!isset($data['id']) or !isset($data['project_id']) or !isset($data['staff_id']) or !is_int($data['staff_id']) or !is_int($data['id']) or !is_int($data['project_id'])) { $job->sendStatus(400, 400); return false; } $id = $data['id']; $project_id = $data['project_id']; $staff = $data['staff_id']; // ”даление из кеша даты последнего просмотра пользователем профайлера LastActiveDate::getModel(LastActiveDate::TYPE_PROFILER)->setData($id)->setUserId($staff)->delete(); // ”даление всех данных по профайлеру Profiler::deleteAll(['message_id' => $id]); // ”даление из кеша списка профайлеров по проекту $command = new DeleteProfilerList(); $command->setData($project_id)->execute(); $job->sendStatus(200, 200); return true; }
/** * @param GearmanJob|null $job * @return mixed */ public function execute(GearmanJob $job = null) { $data = $data = $this->getWorkload($job)->getParams()['data']; $id = $data['id']; $staff = $data['staff_id']; if (!is_int($id) or !is_int($staff)) { $job->sendStatus(400, 400); return false; } // Удаление из кеша даты последнего просмотра пользователем профайлеров проекта $profiler = ListProfiler::findAll(['project_id' => $id]); $profilerId = ArrayHelper::getColumn($profiler, 'id'); LastActiveDate::getModel(LastActiveDate::TYPE_PROFILER)->setData($profilerId)->setUserId($staff)->delete(); // Удаление списка профайлеров проекта ListProfiler::deleteAll(['project_id' => $id]); // Удаление данных проекта Profiler::deleteAll(['project_id' => $id]); // Удаление из кеша списка профайлеров проекта $command = new DeleteProfilerList(); $command->setData($id)->execute(); $job->sendStatus(200, 200); return true; }