/** * 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->aInstitucion !== null) { if ($this->aInstitucion->isModified() || $this->aInstitucion->getCulture() && $this->aInstitucion->getCurrentInstitucionI18n()->isModified() || $this->aInstitucion->isNew()) { $affectedRows += $this->aInstitucion->save($con); } $this->setInstitucion($this->aInstitucion); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = InstitucionI18nPeer::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->setNew(false); } else { $affectedRows += InstitucionI18nPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { date_default_timezone_set('America/Argentina/Buenos_Aires'); $model = new Institucion(); $send = new SendEmailService(); $ficha_institucion = new FichaInstitucion(); $localidad = new Localidad(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($model, $ficha_institucion)); if (isset($_POST['Institucion'], $_POST['FichaInstitucion'], $_POST['Localidad'])) { $model->attributes = $_POST['Institucion']; $ficha_institucion->attributes = $_POST['FichaInstitucion']; $localidad->attributes = $_POST['Localidad']; $model->fhcreacion = new CDbExpression('NOW()'); $model->fhultmod = new CDbExpression('NOW()'); $model->cusuario = "sysadmin"; $passencr = md5($model->password); // encripto la password en MD5 $localidad->fhcreacion = new CDbExpression('NOW()'); $localidad->fhultmod = new CDbExpression('NOW()'); $localidad->cusuario = $model->email; $ficha_institucion->fhcreacion = new CDbExpression('NOW()'); $ficha_institucion->fhultmod = new CDbExpression('NOW()'); $ficha_institucion->cusuario = $model->email; $ficha_institucion->id_localidad = $_POST['Localidad']['id_localidad']; $mail = $model->email; if ($model->validate() && $ficha_institucion->validate()) { if ($model->save()) { Institucion::model()->updateAll(array('password' => $passencr), 'email="' . $mail . '"'); $institucion = Institucion::model()->findByAttributes(array('email' => $mail)); $ficha_institucion->id_institucion = $institucion->id_institucion; if ($ficha_institucion->save()) { $send->Send($model->email); $this->redirect(array('view', 'id' => $model->id_institucion)); } } } } $this->render('create', array('model' => $model, 'ficha_institucion' => $ficha_institucion, 'localidad' => $localidad)); }