/**
  * Creates a new Applicant model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model1 = new Applicant();
     $model2 = new Personal();
     $model3 = new Academic();
     if ($model1->load(Yii::$app->request->post()) && $model2->load(Yii::$app->request->post()) && $model3->load(Yii::$app->request->post()) && $model1->save() && $model2->save() && $model3->save()) {
         return $this->redirect(['view', 'id' => $model1->id]);
     } else {
         return $this->render('create', ['model1' => $model1, 'model2' => $model2, 'model3' => $model3]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Personal::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'telno' => $this->telno, 'celno' => $this->celno, 'birthdate' => $this->birthdate, 'age' => $this->age, 'height' => $this->height, 'weight' => $this->weight]);
     $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'middlename', $this->middlename])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'house_num1', $this->house_num1])->andFilterWhere(['like', 'st_add1', $this->st_add1])->andFilterWhere(['like', 'brgy_add1', $this->brgy_add1])->andFilterWhere(['like', 'city_add1', $this->city_add1])->andFilterWhere(['like', 'house_num2', $this->house_num2])->andFilterWhere(['like', 'st_add2', $this->st_add2])->andFilterWhere(['like', 'brgy_add2', $this->brgy_add2])->andFilterWhere(['like', 'city_add2', $this->city_add2])->andFilterWhere(['like', 'email_add', $this->email_add])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'sex', $this->sex])->andFilterWhere(['like', 'birthplace', $this->birthplace])->andFilterWhere(['like', 'nationality', $this->nationality])->andFilterWhere(['like', 'religion', $this->religion]);
     return $dataProvider;
 }
Example #3
0
 /**
  * (string) actionDetail : 右侧区域信息
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionDetail()
 {
     //$this->layout = 'bank';
     $id = Yii::$app->request->post('id', '%');
     if ($id == '0' || $id == '@') {
         $id = '%';
     }
     $name = Yii::$app->request->post('name', '计生管理系统');
     $unit = new Unit();
     $p_num = Personal::find()->where(['unit' => $id])->count(1);
     if ($unit->isParent($id) && $p_num <= 0) {
         return $this->renderAjax('_detail', ['parent' => $id, 'parentName' => $name, 'unitcode' => Unit::getMaxunitcode($id), 'isParent' => intval($this->findModel($id)->corpflag) < 5 ? "yes" : "no"]);
     } else {
         $preferences = [];
         $preferences['sex'] = Preferences::getByClassmark('psex');
         $preferences['marry'] = Preferences::getByClassmark('pmarry');
         $preferences['flag'] = Preferences::getByClassmark('pflag');
         $preferences['work1'] = Preferences::getByClassmark('pwork1');
         return $this->renderAjax('/personal/_list', ['parent' => $id, 'parentName' => $name, 'code1' => Personal::getMaxCode(), 'preferences' => Json::encode($preferences)]);
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPersonal0()
 {
     return $this->hasOne(Personal::className(), ['id' => 'personal']);
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPersonals()
 {
     return $this->hasMany(Personal::className(), ['unit' => 'unitcode']);
 }
Example #6
0
 /**
  * Finds the Personal model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Personal the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Personal::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #7
0
 /**
  * (string) actionDataTables :
  * @param string $type
  * @param $pid
  * @return string
  * @throws Exception
  * @throws \Exception
  * @throws \yii\db\Exception
  */
 public function actionDataTables($type = 'fetch', $pid)
 {
     $returnData = [];
     switch ($type) {
         case "fetch":
             $returnData = Personal::getPersonalByPid($pid)->marries;
             return Json::encode($returnData);
         case "crud":
             $requestAction = Yii::$app->request->post('action');
             switch ($requestAction) {
                 case "create":
                     $requestID = key(Yii::$app->request->post('data'));
                     $requestData = Yii::$app->request->post('data')[$requestID];
                     $model = new Marry();
                     //块赋值
                     $model->attributes = $requestData;
                     //返回错误信息给datatable
                     if (!$model->validate()) {
                         $fieldErrors = [];
                         foreach ($model->errors as $name => $status) {
                             $fieldErrors[] = ['name' => $name, 'status' => Json::encode($status)];
                         }
                         return Json::encode(['fieldErrors' => $fieldErrors, 'data' => []]);
                     }
                     if ($model->save()) {
                         $requestData['mid'] = $model->mid;
                         $data = [];
                         $data[] = $requestData;
                         return Json::encode(['data' => $data]);
                     } else {
                         var_dump($model->errors);
                         $error = '恢复操作发生意外!';
                         throw new Exception($error);
                     }
                 case "edit":
                     $editID = array_keys(Yii::$app->request->post('data'));
                     //执行事务,保存必须都成功了才行
                     $transaction = Marry::getDb()->beginTransaction();
                     //返回值
                     $data = [];
                     try {
                         foreach ($editID as $requestID) {
                             $requestData = Yii::$app->request->post('data')[$requestID];
                             $model = Marry::findOne($requestID);
                             //块赋值
                             $model->attributes = $requestData;
                             //返回错误信息给datatable
                             if (!$model->validate()) {
                                 $fieldErrors = [];
                                 foreach ($model->errors as $name => $status) {
                                     $fieldErrors[] = ['name' => $name, 'status' => Json::encode($status)];
                                 }
                                 return Json::encode(['fieldErrors' => $fieldErrors, 'data' => []]);
                             }
                             $model->save();
                             //单个字段更新的时候
                             if (count($requestData) == 1 || !is_array($requestData)) {
                                 $requestData = Marry::find()->select(['*'])->where(['mid' => $requestID])->one();
                             } else {
                                 $requestData['mid'] = $requestID;
                             }
                             $data[] = $requestData;
                         }
                         //提交事务
                         $transaction->commit();
                         return Json::encode(['data' => $data]);
                     } catch (\Exception $e) {
                         $transaction->rollBack();
                         throw $e;
                     }
                 case "remove":
                     //多选则删除全部 用deleteAll()不会触发 event: EVENT_BEFORE_DELETE 和 EVENT_AFTER_DELETE
                     foreach (Yii::$app->request->post('data') as $removeID => $removeData) {
                         Marry::findOne($removeID)->delete();
                     }
                     return Json::encode($returnData);
                 default:
                     return Json::encode($returnData);
             }
         default:
             throw new \Exception('参数错误!');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getApplicantName()
 {
     return $this->hasOne(Personal::className(), ['id' => 'applicant_name']);
 }