/** * Получение меню * @return array */ public function getData($active) { if ($active != null) { self::$data['menu']['active'] = $active; } // Берем список проектов пользователя 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(); // Формирование списка профайлеров для меню foreach ($profiler as $valueProfiler) { $profilerMenu = ['label' => $valueProfiler['message'], 'name' => "profiler_" . $valueProfiler['id'], 'class' => "profiler_" . $valueProfiler['id'], 'icon_class' => 'fa fa-cube', 'badges' => ['class' => "label pull-right bg-red"], 'url' => '/profiler/detail/' . $valueProfiler['id']]; self::$data['menu']['item'][1]['item'][] = $profilerMenu; } // Формирование списка проектов для меню foreach ($project as $value) { self::$data['menu']['item'][0]['item'][] = ['label' => $value->title, 'name' => "project_" . $value->id, 'icon_class' => 'fa fa-cube', 'url' => '/project/detail/' . $value->id]; } self::$data['user']['data']['avatar'] = \Yii::$app->user->getIdentity()->avatar; self::$data['user']['data']['name'] = \Yii::$app->user->getIdentity()->name; self::$data['user']['data']['surname'] = \Yii::$app->user->getIdentity()->surname; return self::$data; }
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()]); }
/** * todo Сделать ограничение на частоту добавления с одного проекта * @return array * @throws HttpException */ public function actionAdd() { $json = file_get_contents('php://input'); $data = json_decode($json); if ($this->generateSecretKey($data->projectId . '-' . $data->projectKey) != $data->secretKey) { throw new HttpException(400, 'Secret_key is incorrect'); } $project = Project::find()->where(['id' => $data->projectId, 'secret_key' => $data->projectKey])->one(); if (!$project) { throw new HttpException(400, 'Project not found or project_key is incorrect'); } foreach ($data->data as $object) { $message = $object; $message->date_create = $data->dateCreate; $message->project_id = $data->projectId; $result = \Yii::$app->gearman->getDispatcher()->background('AddProfiler', new JobWorkload(['params' => ['data' => $message]])); } return ['status' => 200, 'message' => 'Success']; }
/** * @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]; }
/** * @return \yii\db\ActiveQuery */ public function getProject() { return $this->hasOne(Project::className(), ['id' => 'project_id']); }
/** * Получение модели проекта * @param $id * @return null|static * @throws NotFoundHttpException */ protected function findModel($id) { if (($model = Project::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Проект не найден'); } }