/** * 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->aMesa !== null) { if ($this->aMesa->isModified() || $this->aMesa->isNew()) { $affectedRows += $this->aMesa->save($con); } $this->setMesa($this->aMesa); } if ($this->aJugador !== null) { if ($this->aJugador->isModified() || $this->aJugador->isNew()) { $affectedRows += $this->aJugador->save($con); } $this->setJugador($this->aJugador); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->turnosScheduledForDeletion !== null) { if (!$this->turnosScheduledForDeletion->isEmpty()) { foreach ($this->turnosScheduledForDeletion as $turno) { // need to save related object because we set the relation to null $turno->save($con); } $this->turnosScheduledForDeletion = null; } } if ($this->collTurnos !== null) { foreach ($this->collTurnos as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $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() { $model = new Jugador(); $user = Yii::app()->user; $selectEstados = Estado::model()->selectEstados(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Jugador'])) { $model->attributes = $_POST['Jugador']; if ($model->save()) { $user->setFlash('success', "Datos han sido guardados <strong>satisfactoriamente</strong>."); $this->redirect(array('create')); } } $this->render('create', array('model' => $model, 'selectEstados' => $selectEstados)); }
public function insertar_post() { $coddocente = substr(Input::get('Nombre'), 0, 6); if ($docente = Docente::where('codDocente', '=', $coddocente)->first()) { $haydocenteenequipo = Jugador::where('codDocente', '=', $coddocente)->where('codEquipo', '=', Session::get('user_codequipo'))->first(); if ($haydocenteenequipo == '') { if (Input::hasFile('foto')) { $equipo = Equipo::where('codEquipo', '=', Session::get('user_codequipo'))->first(); $codcampeonato = $equipo->codCampeonato; $jugadorenequipo = DB::table('tjugador')->join('tequipo', 'tequipo.codEquipo', '=', 'tjugador.codEquipo')->where('tequipo.codCampeonato', '=', $codcampeonato)->where('tjugador.codDocente', '=', $coddocente)->First(); if ($jugadorenequipo == '') { $fullnamedocente = $docente->apellidopaterno . ' ' . $docente->apellidomaterno . ' ' . $docente->nombre; $file = Input::file('foto'); $extension = $file->getClientOriginalExtension(); $namefotocomplete = $fullnamedocente . '.' . $extension; $file->move('storage/jugador', $namefotocomplete); $newjugador = new Jugador(); $newjugador->dni = Input::get('DNI'); $newjugador->direccion = Input::get('direccion'); $newjugador->telefono = Input::get('telefono'); $newjugador->edad = Input::get('edad'); $newjugador->foto = $namefotocomplete; $newjugador->estado = 'habilitado'; //el jugador se crea por defecto en habilitado $newjugador->codEquipo = Session::get('user_codequipo'); $newjugador->codDocente = $coddocente; $newjugador->save(); Session::flash('message', 'Jugador agregado correctamente'); return Redirect::to('jugador/listar.html'); } else { $error = ['wilson' => 'Este jugador ya es de otro equipo por favor ingrese otro jugador']; return Redirect::back()->withInput()->withErrors($error); } } else { $error = ['wilson' => 'No ha ingresado ninguna foto']; return Redirect::back()->withInput()->withErrors($error); } } else { $error = ['wilson' => 'Este jugador ya existe']; return Redirect::back()->withInput()->withErrors($error); } } else { $error = ['wilson' => 'Este docente no existe']; return Redirect::back()->withInput()->withErrors($error); } }