Exemplo n.º 1
0
 public function executeUpdateProfile()
 {
     $profile = $this->getUser()->getProfile();
     //$profile->setCampusId($this->getRequestParameter('campus'));
     //$profile->setDepartmentId($this->getRequestParameter('department'));
     //$profile->setSubdepartmentId($this->getRequestParameter('subdepartment'));
     //$profile->setFirstName($this->getRequestParameter('first_name'));
     //$profile->setLastName($this->getRequestParameter('last_name'));
     //$profile->setTitle($this->getRequestParameter('title'));
     //$profile->setPicture($this->getRequestParameter('picture'));
     //$privacy = $this->getRequestParameter('privacy');
     /*
     $tab = $this->getRequestParameter('tab');
     
     if ($tab == "personal")
     {
       $this->logMessage('tab: ['.$tab.']');
       
       if (is_array($privacy))
       {
         $privacy = $privacy[0];
       }
       
       if (is_numeric($privacy))
       {
         $profile->setPrivacyLevel($privacy);
       }
       $department = DepartmentPeer::retrieveByUuid($this->getRequestParameter('department'));
       $subdepartment = SubdepartmentPeer::retrieveByUuid($this->getRequestParameter('subdepartment'));
       
       $this->forward404Unless($department != null && $subdepartment != null, 'department or subdepartment not found');
       
       $profile->setDepartmentId($department->getId());
       $profile->setSubdepartmentId($subdepartment->getId());
     
       $this->departments = DepartmentPeer::doSelect(new Criteria());
       $this->subdepartments = SubdepartmentPeer::doSelect(new Criteria());
     
       $this->getUser()->setCulture($this->getRequestParameter('language', 'en_US');
     
     
     }
     
     if ($tab == "photo")
     {
       $this->logMessage('Checking to see if we need to remove the photo');
       $currentFile = sfConfig::get('sf_upload_dir')."/photos/".$profile->getPicture();
       $photo_remove = $this->getRequestParameter('photo_remove', null);
       if (!$this->getRequest()->hasErrors() && !is_null($photo_remove))
       {
         $this->logMessage('We need to remove it!');
         $profile->setNoPicture();
         if (is_file($currentFile))
         {
           unlink($currentFile);
         }
       }
     
       $this->logMessage('Attempting to set photo');
       if (!$this->getRequest()->hasErrors() && $this->getRequest()->getFileSize('photo'))
       {
         $fileName = md5($this->getRequest()->getFileName('photo').time().rand(0, 99999));
         $ext = $this->getRequest()->getFileExtension('photo');
         if (is_file($currentFile))
         {
           unlink($currentFile);
         }
         $this->getRequest()->moveFile('photo', sfConfig::get('sf_upload_dir')."/photos/".$fileName.$ext);
         $profile->setPicture($fileName.$ext);
         $this->logMessage('Photo set to ['.$fileName.'.'.$ext.']');
       }
       
       $this->logMessage('Was the photo set?');
     }
     */
     $department = DepartmentPeer::retrieveByUuid($this->getRequestParameter('departments'));
     $this->forward404Unless($department, 'Dept not found, unable to set.');
     $subdepartment = SubdepartmentPeer::retrieveByName(trim($this->getRequestParameter('subdepartment')));
     if ($subdepartment == null) {
         $subdept = new Subdepartment();
         $subdept->setDepartmentId($department->getId());
         $subdept->setName($this->getRequestParameter('subdepartment'));
         $subdept->setAbbreviation($this->getRequestParameter('subdepartment'));
         $subdept->save();
         $subdepartment = $subdept;
     }
     $profile->setDepartmentId($department->getId());
     $profile->setSubdepartmentId($subdepartment->getId());
     if ($this->getRequestParameter('about') != null) {
         $profile->setAbout($this->getRequestParameter('about'));
     }
     if ($this->getRequestParameter('gender') == sfConfig::get('app_profile_gender_male') || $this->getRequestParameter('gender') == sfConfig::get('app_profile_gender_female')) {
         $profile->setGender($this->getRequestParameter('gender'));
     }
     if ($this->getRequestParameter('language') != null) {
         $this->getUser()->setCulture($this->getRequestParameter('language'));
     }
     $this->logMessage("User culture set to {$this->getUser}()->getCulture()");
     $profile->save();
     $contactInfo = $this->getUser()->getProfile()->getPrimaryContactInfo();
     $contactInfo->setPhone($this->getRequestParameter('phone'));
     $contactInfo->setEmail($this->getRequestParameter('email'));
     $contactInfo->save();
     if ($this->getRequestParameter('profile_password') != null && $this->getRequestParameter('profile_password') == $this->getRequestParameter('profile_password_confirm')) {
         $user = $profile->getsfGuardUser();
         $user->setPassword($this->getRequestParameter('profile_password'));
         $user->save();
     }
     //$this->campuses = CampusPeer::doSelect(new Criteria());
     $this->profile = $profile;
     return $this->redirect('@edit_user_profile');
 }