/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { // echo Yii::$app->getBasePath();die; //var_dump($id); /* if (!$resutl = $this->_validUserRequest($id)) { $this->redirect(array('user/view', 'id' => $id)); }*/ $model = $this->loadModelByUserId($id); //echo"<pre>";print_r($_POST);die; $categoryModel = new Category(); $categorys = Category::model()->getAllCategoryList(); $category = CHtml::listData($categorys, 'id', 'category_name'); $skills = CHtml::listData(Yii::app()->db->createCommand()->select('id, name')->from('skill')->queryAll(), 'id', 'name'); //echo"<pre>";print_r($skills);die; $skills = CHtml::listData(Yii::app()->db->createCommand()->select('id, name')->from('skill')->queryAll(), 'id', 'name'); $talentLevel = array('beginner' => 'Beginner', 'professional' => 'Professional'); $profileWatch = array('anyone' => 'Anyone', 'friends_of_friends' => 'Friends of friends', 'friends' => 'Friends'); $genderOptions = array('M' => 'Male', 'F' => 'Female', 'others' => 'Others'); if ($model == NULL) { $model = new Userinfo(); $model->setIsNewRecord(TRUE); } /* if(Yii::app()->request->getIsAjaxRequest()){ // echo "<pre>";print_r($_POST);die; if($model->validate()){ }else{ $model->addErrors('error'); } }*/ $this->performAjaxValidation($model); //if($model->validate()){ //echo"<pre>";print_r($model);die; if (isset($_POST['Userinfo']) && !empty($_POST['Userinfo'])) { if ($_POST['Userinfo']['form_type'] == "profession") { //echo"<pre>";print_r($_POST);die; $post = new Userinfo(); $post->category_id = $_POST['Userinfo']['category_id']; $post->skill_levell = $_POST['Userinfo']['skill_levell']; $post->skill_id = $_POST['Userinfo']['skill_id']; $post->secondary_talent = $_POST['Userinfo']['secondary_talent']; $post->secondary_talent_1 = $_POST['Userinfo']['secondary_talent_1']; $post->save(); $this->render('stepform', array('model' => $model, 'genderOptions' => $genderOptions, 'talentLevel' => $talentLevel, 'skills' => $skills, 'categoryModel' => $categoryModel, 'category' => $category, 'profileWatch' => $profileWatch)); } elseif ($_POST['Userinfo']['form_type'] == "basic") { //echo"<pre>";print_r($_POST);die; $post = new Userinfo(); //$post->name=$_POST['Userinfo']['name']; //$post->email=$_POST['Userinfo']['email']; $post->dob = $_POST['Userinfo']['phone']; $post->gender = $_POST['Userinfo']['gender']; $post->nationality = $_POST['Userinfo']['nationality']; $post->education = $_POST['Userinfo']['education']; $post->school_name = $_POST['Userinfo']['school_name']; $post->date = $_POST['Userinfo']['date']; $post->field_of_study = $_POST['Userinfo']['field_of_study']; $post->description = $_POST['Userinfo']['description']; $post->save(); //$userPost= new User(); $userPost = User::model()->findByPk($id); if (!empty($_POST['Userinfo']['name'])) { $userPost->first_name = $_POST['Userinfo']['name']; } if (!empty($_POST['Userinfo']['email'])) { $userPost->first_name = $_POST['Userinfo']['email']; } $userPost->save(); } elseif ($_POST['Userinfo']['form_type'] == "experience") { //echo"<pre>";print_r($_POST);die; $post = new Userinfo(); //$post->name=$_POST['Userinfo']['name']; //$post->email=$_POST['Userinfo']['email']; $post->company_name = $_POST['Userinfo']['company_name']; $post->position = $_POST['Userinfo']['position']; $post->experience = $_POST['Userinfo']['experience']; $post->exp_description = $_POST['Userinfo']['exp_description']; $post->save(); } elseif ($_POST['Userinfo']['form_type'] == "awards") { //echo"<pre>";print_r($_POST);die; $post = new Userinfo(); //$post->name=$_POST['Userinfo']['name']; //$post->email=$_POST['Userinfo']['email']; $post->award_title = $_POST['Userinfo']['award_title']; $post->award = $_POST['Userinfo']['award']; $post->year = $_POST['Userinfo']['year']; $post->award_description = $_POST['Userinfo']['award_description']; $post->save(); } elseif ($_POST['Userinfo']['form_type'] == "interests") { //echo"<pre>";print_r($_POST);die; $post = new Userinfo(); $post->interests = $_POST['Userinfo']['interests']; $post->save(); } elseif ($_POST['Userinfo']['form_type'] == "privacy") { // echo"<pre>";print_r($_POST);die; $post = new Userinfo(); $post->message = $_POST['Userinfo']['message']; $post->connect = $_POST['Userinfo']['connect']; $post->see_phone = $_POST['Userinfo']['see_phone']; $post->see_dob = $_POST['Userinfo']['see_dob']; $post->save(); $this->redirect(array('user/view', 'id' => $id)); } } //} // throw new CHttpException(404,'The specified url cannot be found.'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); /* if (isset($_POST['Userinfo'])) { $userId = Yii::app()->user->getId(); $_POST['Userinfo']['user_id'] = $userId; $model->attributes = $_POST['Userinfo']; try { $profilePicture = CUploadedFile::getInstance($model, 'profile_photo_name'); $coverPicture = CUploadedFile::getInstance($model, 'cover_photo_name'); if (!empty($profilePicture)) $model->profile_photo_name = "{$userId}_{$profilePicture}"; if (!empty($coverPicture)) $model->cover_photo_name = "{$userId}_{$coverPicture}"; if (!file_exists(Yii::app()->basePath . '/../images')) { mkdir(Yii::app()->basePath . '/../images'); } if ($model->save()) { //$profilePicture = str_replace('','',$model->profile_photo_name); //$coverPicture = str_replace('','',$model->cover_photo_name); if (!empty($profilePicture)) $profilePicture->saveAs(Yii::app()->basePath . '/../images/user/profile/' . $model->profile_photo_name); if (!empty($coverPicture)) $coverPicture->saveAs(Yii::app()->basePath . '/../images/user/cover/' . $model->cover_photo_name); //$this->redirect(array('user/view', 'id' => $model->user_id)); } } catch (Exception $e) { throw new CHttpException(404, $e->getMessages()); } }*/ $this->render('stepform', array('model' => $model, 'genderOptions' => $genderOptions, 'talentLevel' => $talentLevel, 'skills' => $skills, 'categoryModel' => $categoryModel, 'category' => $category, 'profileWatch' => $profileWatch)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { //var_dump($id); if (!($resutl = $this->_validUserRequest($id))) { $this->redirect(array('user/view', 'id' => $id)); } $model = $this->loadModelByUserId($id); // var_dump($model); if ($model == NULL) { $model = new Userinfo(); $model->setIsNewRecord(TRUE); } // throw new CHttpException(404,'The specified url cannot be found.'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Userinfo'])) { $userId = Yii::app()->user->getId(); $_POST['Userinfo']['user_id'] = $userId; $model->attributes = $_POST['Userinfo']; try { $profilePicture = CUploadedFile::getInstance($model, 'profile_photo_name'); $coverPicture = CUploadedFile::getInstance($model, 'cover_photo_name'); if (!empty($profilePicture)) { $model->profile_photo_name = "{$userId}_{$profilePicture}"; } if (!empty($coverPicture)) { $model->cover_photo_name = "{$userId}_{$coverPicture}"; } if (!file_exists(Yii::app()->basePath . '/../images')) { mkdir(Yii::app()->basePath . '/../images'); } if ($model->save()) { //$profilePicture = str_replace('','',$model->profile_photo_name); //$coverPicture = str_replace('','',$model->cover_photo_name); if (!empty($profilePicture)) { $profilePicture->saveAs(Yii::app()->basePath . '/../images/user/profile/' . $model->profile_photo_name); } if (!empty($coverPicture)) { $coverPicture->saveAs(Yii::app()->basePath . '/../images/user/cover/' . $model->cover_photo_name); } $this->redirect(array('user/view', 'id' => $model->user_id)); } } catch (Exception $e) { throw new CHttpException(404, $e->getMessages()); } } $this->render('update', array('model' => $model)); }