Beispiel #1
0
 public function actionView_Profile()
 {
     $model = new EditProfileForm();
     $model->user_id = Yii::app()->user->id;
     $user = $this->loadUser(Yii::app()->user->id);
     $model->first_name = $user->first_name;
     $model->last_name = $user->last_name;
     $model->email = $user->email;
     $model->affiliation = $user->affiliation;
     $model->newsletter = $user->newsletter;
     $model->preferred_link = $user->preferred_link;
     $current = $user->newsletter;
     if (isset($_POST['EditProfileForm'])) {
         $model->attributes = $_POST['EditProfileForm'];
         if ($model->validate()) {
             if ($model->updateInfo()) {
                 $new = $model->newsletter;
                 if ($new && !$current) {
                     Yii::log('add new mailing', 'debug');
                     $success = Utils::addToMailing($model->email, array('FNAME' => $model->first_name, 'LNAME' => $model->last_name));
                 }
                 if (!$new && $current) {
                     Yii::log('remove mailing', 'debug');
                     $success = Utils::removeFromMailing($model->email);
                 }
                 $this->redirect('/user/view_profile');
             }
         } else {
             Yii::log(print_r($model->getErrors(), true), 'debug');
         }
     }
     $searchRecord = SearchRecord::model()->findAllByAttributes(array('user_id' => Yii::app()->user->id));
     //Yii::log(print_r($searchRecord, true), 'debug');
     $uploadedDatasets = Dataset::model()->findAllByAttributes(array('submitter_id' => Yii::app()->user->id), array('order' => 'upload_status'));
     $this->render('view_profile', array('model' => $model, 'searchRecord' => $searchRecord, 'uploadedDatasets' => $uploadedDatasets));
 }