/**
  * Creates a new Optionalwork model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Optionalwork();
     if ($model->load(Yii::$app->request->post())) {
         $selectSchool = ArrayHelper::map(Scholar::find()->where(['scholar_id' => $model->scholar_scholar_id])->all(), 'school_school_id', 'school_school_id');
         $schoolID = array_values($selectSchool)[0];
         $model->scholar_school_school_id = $schoolID;
         $model->save();
         return $this->redirect(['view', 'id' => $model->optionalwork_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Optionalwork model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $username = Yii::$app->user->identity->username;
     $users = User::find()->all();
     $scholars = Scholar::find()->all();
     $model = new Optionalwork();
     foreach ($users as $user) {
         foreach ($scholars as $scholar) {
             if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
                 $model->scholar_scholar_id = $scholar->scholar_id;
                 $model->scholar_school_school_id = $scholar->school_school_id;
                 if ($model->load(Yii::$app->request->post()) && $model->save()) {
                     return $this->redirect(['index', 'id' => $model->optionalwork_id]);
                 } else {
                     return $this->render('create', ['model' => $model]);
                 }
             }
         }
     }
 }