protected function doSave($con) { $affectedRows = 0; if (!$this->alreadyInSave) { $this->alreadyInSave = true; if ($this->asfGuardUser !== null) { if ($this->asfGuardUser->isModified()) { $affectedRows += $this->asfGuardUser->save($con); } $this->setsfGuardUser($this->asfGuardUser); } if ($this->aCampus !== null) { if ($this->aCampus->isModified()) { $affectedRows += $this->aCampus->save($con); } $this->setCampus($this->aCampus); } if ($this->aDepartment !== null) { if ($this->aDepartment->isModified()) { $affectedRows += $this->aDepartment->save($con); } $this->setDepartment($this->aDepartment); } if ($this->aSubdepartment !== null) { if ($this->aSubdepartment->isModified()) { $affectedRows += $this->aSubdepartment->save($con); } $this->setSubdepartment($this->aSubdepartment); } if ($this->isModified()) { if ($this->isNew()) { $pk = sfGuardUserProfilePeer::doInsert($this, $con); $affectedRows += 1; $this->setId($pk); $this->setNew(false); } else { $affectedRows += sfGuardUserProfilePeer::doUpdate($this, $con); } $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUserType !== null) { if ($this->aUserType->isModified() || $this->aUserType->isNew()) { $affectedRows += $this->aUserType->save($con); } $this->setUserType($this->aUserType); } if ($this->asfGuardUser !== null) { if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) { $affectedRows += $this->asfGuardUser->save($con); } $this->setsfGuardUser($this->asfGuardUser); } if ($this->isNew()) { $this->modifiedColumns[] = sfGuardUserProfilePeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = sfGuardUserProfilePeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += sfGuardUserProfilePeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collJobNotess !== null) { foreach ($this->collJobNotess as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collJobAttachments !== null) { foreach ($this->collJobAttachments as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collPhotographers !== null) { foreach ($this->collPhotographers as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collClients !== null) { foreach ($this->collClients as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collLogs !== null) { foreach ($this->collLogs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function executeSignin($request) { $this->op = $request->getParameter('op'); //echo $this->op; //die; $dialog = $request->getParameter('dialog', false); /* IF FB CONNECT */ if ($this->op == 'fbc' && ($facebook_uid = VoFacebook::getUid())) { //echo "FBC";die; $c = new Criteria(); $c->addJoin(SfGuardUserProfilePeer::USER_ID, SfGuardUserPeer::ID); $c->add(SfGuardUserProfilePeer::FACEBOOK_UID, $facebook_uid); $sfGuardUser = SfGuardUserPeer::doSelectOne($c); if (!$sfGuardUser instanceof sfGuardUser) { // Comprobación de que no existe ya el usuario con ese username (bug #734) $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, 'Facebook_' . $facebook_uid); $existingUser = sfGuardUserPeer::doSelectOne($c); if ($existingUser) { $existingUser->setUsername('Facebook_' . $facebook_uid . '-' . time()); $existingUser->save(); } $sfGuardUser = new sfGuardUser(); $sfGuardUser->setUsername('Facebook_' . $facebook_uid); $sfGuardUser->save(); $voProfile = $sfGuardUser->getProfile(); $vanityUrl = SfVoUtil::encodeVanity('Facebook_' . $facebook_uid); $voProfile->setFacebookUid($facebook_uid); if (!$voProfile->getNombre()) { $data = VoFacebook::getData($voProfile->getFacebookUid()); $voProfile->setNombre($data->first_name); $voProfile->setApellidos($data->last_name); } $c2 = new Criteria(); $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE); $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2); $counter = 0; foreach ($usuariosLikeMe as $usuarioLikeMe) { if (preg_match("/^Facebook_{$facebook_uid}-([0-9]*)/i", $usuarioLikeMe->getVanity(), $matches)) { $curIdx = $matches[1]; if ($curIdx > $counter) { $counter = $curIdx + 1; } } else { $counter++; } } $voProfile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}")); $voProfile->setMailsComentarios(0); $voProfile->setMailsNoticias(0); $voProfile->setMailsContacto(0); $voProfile->setMailsSeguidor(0); $voProfile->save(); } $this->getUser()->signin($sfGuardUser, false); $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $this->getUser()->getReferer('@homepage')); $this->redirect($signinUrl); } /* FI FB CONNECT */ $this->registrationform = new RegistrationForm(); $this->signinform = new SigninForm(); if ($request->isMethod('post') && !$dialog) { // Register if ($this->op == 'r') { $this->registrationform = new RegistrationForm(); $this->registrationform->bind($request->getParameter('registration')); if ($this->registrationform->isValid()) { $user = new sfGuardUser(); $user->setUsername($this->registrationform->getValue('username')); $user->setPassword($this->registrationform->getValue('password')); $user->setIsActive(0); $user->setCreatedAt(time()); $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, $user->getUsername()); sfGuardUserPeer::doInsert($user); $user = sfGuardUserPeer::doSelect($c); if (count($user) == 1) { $profile = $user[0]->getProfile(); $profile->setNombre($this->registrationform->getValue('nombre')); $profile->setApellidos($this->registrationform->getValue('apellidos')); $profile->setPresentacion($this->registrationform->getValue('presentacion')); $profile->setAnonymous($this->registrationform->getValue('anonymous')); $profile->setCodigo(util::generateUID()); /* Generar vanity */ if ($profile->getVanity() == '') { $vanityUrl = SfVoUtil::encodeVanity($profile->getNombre() . "-" . $profile->getApellidos()); $c2 = new Criteria(); $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE); $c2->add(SfGuardUserProfilePeer::ID, $user[0]->getId(), Criteria::NOT_EQUAL); $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2); $counter = 0; foreach ($usuariosLikeMe as $usuarioLikeMe) { $counter++; } $profile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}")); } /* Fin Generar vanity */ sfGuardUserProfilePeer::doInsert($profile); $this->sendWelcome($user[0]); $this->user = $user[0]; return "Registered"; } } /* else { $this->getUser()->setFlash('notice_type', 'error', false); $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false); } */ } else { $r = new SigninForm(); $r->bind($request->getParameter('signin')); if ($r->isValid()) { $r->addPostValidation(); $r->bind($request->getParameter('signin')); if ($r->isValid()) { $this->doSignin($request, $this->op); } } /* else { $this->getUser()->setFlash('notice_type', 'error', false); $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false); } */ $this->signinform = $r; } } $this->title = sfContext::getInstance()->getI18N()->__('Acceso usuarios', array()); $this->title .= ' - Voota'; $this->response->setTitle($this->title); if ($this->op == 'fb') { return 'FB'; } }