Ejemplo n.º 1
0
 public function getCertifationdetails()
 {
     return $this->hasMany(Certification::className(), ['user_id' => 'id']);
 }
Ejemplo n.º 2
0
 public function actionCertification()
 {
     $userdetails = \Yii::$app->user->identity;
     $model = Certification::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($model)) {
         $model = new Certification();
     }
     $userprofile = UserProfile::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($userprofile)) {
         $userprofile = new UserProfile();
     }
     $user = Userform::find()->where(['id' => $userdetails->id])->one();
     if (empty($user)) {
         $user = new Userform();
     }
     if (isset($_POST['Certification'])) {
         $model->attributes = $_POST['Certification'];
         $model->user_id = $userdetails->id;
         $model->name = $_POST['Certification']['name'];
         $model->certification_authority = $_POST['Certification']['certification_authority'];
         $model->licence_no = $_POST['Certification']['licence_no'];
         $attended_date = explode('/', $_POST['Certification']['attended_date']);
         $model->attended_date = $attended_date[2] . '-' . $attended_date[1] . '-' . $attended_date[0];
         $completion_date = explode('/', $_POST['Certification']['completion_date']);
         $model->completion_date = $completion_date[2] . '-' . $completion_date[1] . '-' . $completion_date[0];
         $valid_upto = explode('/', $_POST['Certification']['valid_upto']);
         $model->valid_upto = $valid_upto[2] . '-' . $valid_upto[1] . '-' . $valid_upto[0];
         $model->created = new \yii\db\Expression('NOW()');
         if ($model->validate()) {
             if (isset($_POST['isnew'])) {
                 \Yii::$app->db->createCommand()->insert('tlb_certification', ['name' => $model->name, 'certification_authority' => $model->certification_authority, 'licence_no' => $model->licence_no, 'attended_date' => $model->attended_date, 'completion_date' => $model->completion_date, 'valid_upto' => $model->valid_upto, 'created' => new \yii\db\Expression('NOW()'), 'user_id' => $userdetails->id])->execute();
             } else {
                 $model->save();
             }
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ['data' => $model];
         }
     }
 }