public static function getDb() { // return Yii::$app->db_common; $instance = Statuses::getInstance(); if ($instance === NULL) { throw new ErrorException('You should use this class through yii2-status module.'); } elseif (!$instance->db) { $db = 'db'; } else { $db = $instance->db; } return Yii::$app->get($db); }
/** * @return \yii\db\ActiveQuery */ public function getRight() { $class = \statuses\Statuses::getInstance()->accessRightsClass; return $this->hasOne($class::className(), ['id' => 'right_id']); }
/** * @inherit */ public function behaviors() { return ['access' => ['class' => \statuses\Statuses::getInstance()->accessClass]]; }
/** * Create links to other units of Statuses model * * @param integer $id * @return mixed */ public function actionLinkCreate($id) { $model = $this->findModel($id); if (!$model->isAllowed('statuses.statuses.link.create')) { throw new ForbiddenHttpException(Yii::t('statuses', 'Access restricted')); } $modelLink = new StatusesLinks(); $modelLink->status_from = $model->id; $post = Yii::$app->request->post(); if (!empty($post)) { if ($modelLink->load($post) && $modelLink->save()) { return $this->redirect(['view', 'id' => $model->id]); } } $searchModel = new StatusesSearch(); $dataProviderModel = $searchModel->searchUnlink($model, Yii::$app->request->queryParams); $rightsSearchClass = \statuses\Statuses::getInstance()->accessRightsSearchClass; $rightsSearchModel = new $rightsSearchClass(); $rightsDataProvider = $rightsSearchModel->search(Yii::$app->request->queryParams); return $this->render('link-create', ['model' => $model, 'modelLink' => $modelLink, 'searchModel' => $searchModel, 'dataProviderModel' => $dataProviderModel, 'rightsSearchModel' => $rightsSearchModel, 'rightsDataProvider' => $rightsDataProvider]); }