public function actionDetail($id) { $profiler = $this->findProfiler($id); LastActiveDate::getModel(LastActiveDate::TYPE_PROFILER)->setData((int) $id)->setUserId(\Yii::$app->user->id)->save(); $project = Project::findOne($profiler->project_id); if (!$project) { throw new NotFoundHttpException('Проект профайлера не найден'); } \Yii::$app->getView()->params['leftMenu']['active'] = "profiler_{$profiler->id}"; $data = new ActiveDataProvider(['query' => DurationGraph::getQuery($id), 'pagination' => ['pageSize' => self::PAGE_SIZE], 'sort' => false]); return $this->render('detail.tpl', ['model' => $project, 'profiler' => $profiler, 'data' => $data, 'totalMessage' => Profiler::find()->where(['message_id' => $id])->count(), 'total' => ListProfiler::find()->where(['project_id' => $project->id])->count()]); }
/** * @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; }
/** * @return array */ public function actionCount() { $result = ['profiler' => ['total' => false, 'item' => []]]; // Берем список проектов пользователя if (\Yii::$app->cache->exists('project:user:'******'project:user:'******'staff_id' => \Yii::$app->user->id])->all(); \Yii::$app->cache->set('project:user:'******'id'); // Получение списка профайлеров по проектам $command = new ListProfiler\command\GetProfilerList(); $command->setClassModel('app\\models\\amop\\models\\ListProfiler'); $profiler = $command->setData($idProject)->execute(); $idProfiler = ArrayHelper::getColumn($profiler, 'id'); // Получаем список новых элементов для профайлеров $countProfiler = CountData::getModel(CountData::TYPE_PROFILER)->setData(function () use($idProfiler) { return LastActiveDate::getModel(LastActiveDate::TYPE_PROFILER)->setData($idProfiler)->setUserId(\Yii::$app->user->id)->get(); })->getCount(); $result['profiler']['item'] = $countProfiler; $countProfiler ? $result['profiler']['total'] = 'new' : ($result['profiler']['total'] = false); return ['status' => 200, 'result' => $result]; }
/** * “естирование проверки об¤зательных параметров */ public function testDeleteException() { $this->setExpectedException('InvalidArgumentException'); $command = LastActiveDate::getModel(LastActiveDate::TYPE_PROFILER)->setUserId(1)->setData("ffff")->delete(); }