/** * 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 corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aExpediente !== null) { if ($this->aExpediente->isModified() || $this->aExpediente->isNew()) { $affectedRows += $this->aExpediente->save($con); } $this->setExpediente($this->aExpediente); } if ($this->aServicio !== null) { if ($this->aServicio->isModified() || $this->aServicio->isNew()) { $affectedRows += $this->aServicio->save($con); } $this->setServicio($this->aServicio); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->expedientehistorialsScheduledForDeletion !== null) { if (!$this->expedientehistorialsScheduledForDeletion->isEmpty()) { ExpedientehistorialQuery::create()->filterByPrimaryKeys($this->expedientehistorialsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->expedientehistorialsScheduledForDeletion = null; } } if ($this->collExpedientehistorials !== null) { foreach ($this->collExpedientehistorials as $referrerFK) { if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function registrarServicio($descripcion, $metodo, $tiempo_entrega, $cantM_x_ensayo, $tarifa, $tarifa_Acred, $detalle) { $resultado = array('valor' => 1, 'message' => 'Servicio Registrado correctamente.'); $servicio = new Servicio(); $servicio->descripcion = $descripcion; $servicio->metodo = $metodo; $servicio->tiempo_entrega = $tiempo_entrega; $servicio->cantM_x_ensayo = $cantM_x_ensayo; $servicio->tarifa = $tarifa; $servicio->tarifa_Acred = $tarifa_Acred; $servicio->detalle = $detalle; if (!$servicio->save()) { $resultado = array('valor' => 0, 'message' => 'No hemos podido Registrar el servicio, intentelo nuevamente'); } return $resultado; }
public function store() { //RECUPERAR LOS DATOS DE CREATE Y GUARDAR LOS DATOS EN LA BASE DE DATOS $nombre = Input::get('nombre'); $a = '[{"nombre":"' . $nombre . '"}]'; $b = Servicio::select('nombre')->where('nombre', $nombre)->get(); if ($a == $b) { Session::flash('message', "El Servicio ({$nombre}) ya existe en la base de datos!"); Session::flash('class', 'danger'); } else { $servicio = new Servicio(); $servicio->nombre = Input::get('nombre'); $servicio->save(); Session::flash('message', 'Guardado correctamente!'); Session::flash('class', 'success'); } return Redirect::to('servicio/create'); }
/** * 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 corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aAdmision !== null) { if ($this->aAdmision->isModified() || $this->aAdmision->isNew()) { $affectedRows += $this->aAdmision->save($con); } $this->setAdmision($this->aAdmision); } if ($this->aLugarinventario !== null) { if ($this->aLugarinventario->isModified() || $this->aLugarinventario->isNew()) { $affectedRows += $this->aLugarinventario->save($con); } $this->setLugarinventario($this->aLugarinventario); } if ($this->aServicio !== null) { if ($this->aServicio->isModified() || $this->aServicio->isNew()) { $affectedRows += $this->aServicio->save($con); } $this->setServicio($this->aServicio); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
function postServicios(Request $request, Response $response) { $response = $response->withHeader('Content-type', 'application/json'); $data = json_decode($request->getBody(), true); try { $servicio = new Servicio(); $servicio->nombre = $data['nombre']; $servicio->descripcion = $data['descripcion']; $servicio->estado = $data['estado']; $servicio->save(); //$val = $servicio->id; $servisector = new ServiciosSector(); $servisector->idSector = $data['idSector']; $servisector->idServicio = $servicio->id; $servisector->save(); $respuesta = json_encode(array('msg' => "Guardado correctamente", "std" => 1)); $response = $response->withStatus(200); } catch (Exception $err) { $respuesta = json_encode(array('msg' => "error", "std" => 0, "err" => $err->getMessage())); $response = $response->withStatus(404); } $response->getBody()->write($respuesta); return $response; }
function form_agregar() { $respuesta = new stdClass(); $this->form_validation->set_rules('codigo', 'Código', 'trim|required|min_length[5]|max_length[8]|callback_valida_codigo'); $this->form_validation->set_rules('nombre', 'Nombre', 'trim|required'); $this->form_validation->set_rules('mision', 'Misión', 'trim|required'); $this->form_validation->set_rules('entidad_codigo', 'Entidad', 'trim|required'); if ($this->form_validation->run() == TRUE) { $servicio = new Servicio(); $servicio->codigo = $this->input->post('codigo'); $servicio->nombre = $this->input->post('nombre'); $servicio->sigla = $this->input->post('sigla'); $servicio->url = $this->input->post('url'); $servicio->responsable = $this->input->post('responsable'); $servicio->entidad_codigo = $this->input->post('entidad_codigo'); $servicio->mision = $this->input->post('mision'); $servicio->sector_codigo = $this->input->post('sector_codigo') ? $this->input->post('sector_codigo') : '00'; $servicio->setTagsFromArray($this->input->post('tags')); $servicio->save(); $this->session->set_flashdata('message', 'Servicio agregado exitosamente! :)'); $respuesta->validacion = TRUE; $respuesta->redirect = site_url('backend/servicios/'); } else { $respuesta->validacion = FALSE; $respuesta->errores = validation_errors('<p class="error">', '</p>'); } echo json_encode($respuesta); }
public function submit_create_servicio() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); // Verifico si el usuario es un Webmaster if ($data["user"]->idrol == 1) { // Validate the info, create rules for the inputs $attributes = array('nombre' => 'Nombre del Servicio', 'descripcion' => 'Descripcion', 'tipo_servicio' => 'Tipo de Servicio', 'area' => 'Area', 'personal' => 'Personal'); $rules = array('nombre' => 'required|max:100|unique:servicios,nombre|alpha_spaces', 'descripcion' => 'max:200|alpha_spaces', 'tipo_servicio' => 'required|min:1', 'area' => 'required|min:1', 'personal' => 'required|min:1'); $messages = array('tipo_servicio' => 'Seleccionar un tipo de servicio.', 'area.min' => 'Seleccionar un area.', 'personal.min' => 'Seleccionar un usuario.'); // Run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules, $messages, $attributes); // If the validator fails, redirect back to the form if ($validator->fails()) { return Redirect::to('servicios/create_servicio')->withErrors($validator)->withInput(Input::all()); } else { $servicio = new Servicio(); $servicio->nombre = Input::get('nombre'); $servicio->descripcion = Input::get('descripcion'); $servicio->idtipo_servicios = Input::get('tipo_servicio'); $servicio->idarea = Input::get('area'); $servicio->id_usuario_responsable = Input::get('personal'); $servicio->idestado = 1; $servicio->save(); Session::flash('message', 'Se registró correctamente el servicio.'); return Redirect::to('servicios/list_servicios'); } } else { return View::make('error/error', $data); } } else { return View::make('error/error', $data); } }