/** * Creates a new Scout model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Scout(); if ($model->load(Yii::$app->request->post())) { if (!Yii::$app->user->isGuest && !Yii::$app->user->identity->getIsScout() && !Yii::$app->user->identity->getIsParent()) { $auth = Yii::$app->authManager; $authorRole = $auth->getRole('scout'); $auth->assign($authorRole, Yii::$app->user->getId()); } $model->setAttribute('userid', Yii::$app->user->getId()); if ($model->save()) { if (Yii::$app->user->identity->getIsParent()) { $scoutrelation = new Scoutrelation(); $scoutrelation->scoutid = $model->id; $thisuser = Yii::$app->user->getId(); $parent = Scoutparent::findOne(['userid' => $thisuser]); $scoutrelation->parentid = $parent->id; $scoutrelation->save(); } $post = Yii::$app->request->post(); if ($post['where'] == 'fromparent') { return $this->redirect(['/scoutrelation/create']); } else { return $this->redirect(['/site/index']); } } else { return $this->render('create', ['model' => $model]); } } else { $context = Yii::$app->request->get(); if (in_array('where', $context) && $context['where'] == 'fromparent') { return $this->render('create', ['model' => $model, 'where' => 'fromparent']); } else { return $this->render('create', ['model' => $model, 'where' => '']); } } }