Пример #1
0
 public function index(Request $request)
 {
     if ($request->isMethod('post')) {
         $rules = array('name' => 'required', 'email' => 'required|email', 'message' => 'required');
         $postData = $request->all();
         $validator = Validator::make($postData, $rules);
         if ($validator->fails()) {
             return Redirect::to('/contactupdate')->withInput()->withErrors($validator);
         }
         Session::set('userinfo.message', $postData['message']);
         echo "Contact updated successfully";
         //$contact1= UserContact::where('email','=',$postData['email'])->get();
         $contact1 = UserContact::where('email', '=', $postData['email'])->first();
         $contact1->message = $request->message;
         $contact1->save();
         //echo "email= $request->message<br>";
     }
     $contact1 = UserContact::all();
     $view_data = ['data' => $contact1];
     //return view('contactupdate',$view_data);
     foreach ($view_data as $d) {
         echo "<pre>";
         print_r($d);
         echo "--";
     }
 }
Пример #2
0
 public function index(Request $request)
 {
     if ($request->isMethod('post')) {
         $rules = array('name' => 'required', 'email' => 'required|email', 'message' => 'required');
         $postData = $request->all();
         $validator = Validator::make($postData, $rules);
         if ($validator->fails()) {
             return Redirect::to('/contactvalid')->withInput()->withErrors($validator);
         }
         echo "Contact Details:";
         //$contact1 = UserContact::all();
     }
     $contact1 = UserContact::all();
     $view_data = ['data' => $contact1];
     return view('contactvalid', $view_data);
 }
Пример #3
0
 /**
  * Finds the UserContact model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserContact the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id, $user_id = null)
 {
     if (($model = UserContact::findOne($id)) !== null) {
         return $model;
     } else {
         if ($user_id && ($model = UserContact::find()->where(['user_id' => $user_id])->one()) !== null) {
             return $model;
         } else {
             if (($model = User::findOne($user_id)) !== null) {
                 $new_user_contact = new UserContact();
                 $new_user_contact->user_id = $user_id;
                 return $new_user_contact;
             } else {
                 throw new NotFoundHttpException('The requested page does not exist.');
             }
         }
     }
 }
Пример #4
0
 public function contacts()
 {
     $contacts = UserContact::select("user_contacts.*", "contact_type.name as contact_type_name", "value_type.type as value_type_name")->join("contact_type", "user_contacts.contact_type_id", "=", "contact_type.id")->join("value_type", "user_contacts.value_type_id", "=", "value_type.id")->where("user_id", $this->id)->get();
     return $contacts;
 }
Пример #5
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $contactModel = UserContact::findOne(['user_id' => $model->id]);
     /** @var UserContact $contactModel */
     if ($model->load(Yii::$app->request->post()) && $contactModel->load(Yii::$app->request->post())) {
         if ($contactModel->save() && $model->save()) {
             UserTag::updateAll(['status' => 'inactive'], ['user_id' => $model->id]);
             $tags = Yii::$app->request->post('User')['tags'];
             array_walk($tags, function (&$arr) use($model) {
                 $userTagModel = new UserTag();
                 $userTagModel->created_by = Yii::$app->user->id;
                 $userTagModel->tag_id = $arr;
                 $userTagModel->user_id = $model->id;
                 if (!$userTagModel->save()) {
                     throw new Exception("Cannot save user tag!");
                 }
             });
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'contactModel' => $contactModel]);
     }
 }
Пример #6
0
 /**
  * @return country details
  */
 public function getUserContact()
 {
     return $this->hasOne(UserContact::className(), ['user_id' => 'id']);
 }