public function save($con = null)
 {
     if ($this->getObject()->isNew()) {
         $signup = true;
     } else {
         $signup = false;
     }
     $object = parent::save();
     // update profile
     $values = $this->getValues();
     $profile = $object->getProfile();
     // save and remove photo from values
     $photo = $values["profile"]["photo"];
     unset($values["profile"]["photo"]);
     // update profile object
     $profile->fromArray($values["profile"], BasePeer::TYPE_FIELDNAME);
     $profile->setUser($object);
     // new photo??
     if ($photo) {
         $fileName = $profile->getPhoto(false);
         if (!$fileName) {
             $fileName = $profile->generateAvatarName() . '.jpg';
         }
         $photo->save(sfConfig::get('sf_userimage_dir') . DIRECTORY_SEPARATOR . $fileName);
         $profile->setPhoto($fileName);
     }
     if ($values["profile"]["remove_photo"]) {
         $fileName = $profile->getPhoto(false);
         if ($fileName) {
             $profile->setPhoto(null);
             $profile->save();
             // remove from filesystem
             unlink(sfConfig::get('sf_userimage_dir') . DIRECTORY_SEPARATOR . $fileName);
         } else {
             $profile->save();
         }
     } else {
         $profile->save();
     }
     // if creating, setup email and permanent jotag
     if ($signup) {
         // setup email
         $email = new Email();
         $email->setEmail($this->getValue('email'));
         $email->setIsConfirmed(true);
         $email->setIsPrimary(true);
         $email->setType(ContactPeer::TP_PERSONAL);
         $email->setUser($object);
         $email->save();
         // generate JOTAG.
         $tag = new Tag();
         $tag->setJotag($object->generateRandomJOTAG());
         $tag->setIsPrimary(true);
         $tag->setStatus(TagPeer::ST_ACTIVE);
         $tag->setUser($object);
         // link primary email to tag
         $tm = new TagEmail();
         $tm->setEmail($email);
         $tag->addTagEmail($tm);
         // save new tag
         $tag->save();
     }
     return $object;
 }
Beispiel #2
0
 public function save($con = null)
 {
     $this->updatesfGuardUser();
     parent::save();
     return $this->object;
 }