public function saveTema($mensaje, $foro_id) { $tema = new Tema(); $tema->titulo = \Input::get('titulo'); $tema->slug = \Str::slug(\Input::get('titulo')); $tema->cuerpo = $mensaje; $tema->autor = \Input::get('nombre'); $tema->foro_id = $foro_id; $tema->save(); }
function form_agregar() { $this->form_validation->set_rules('nombre', 'Nombre', 'trim|required|callback_validaNombre'); $respuesta = new stdClass(); if ($this->form_validation->run() == TRUE) { $tema = new Tema(); $tema->nombre = $this->input->post('nombre'); $tema->destacado = $this->input->post('destacado') ? 1 : 0; $tema->save(); $this->session->set_flashdata('message', 'Tema agregado exitosamente! :)'); $respuesta->validacion = TRUE; $respuesta->redirect = site_url('backend/temas/'); } else { $respuesta->validacion = FALSE; $respuesta->errores = validation_errors('<p class="error">', '</p>'); } echo json_encode($respuesta); }
/** * admin_add method * * @return void */ public function admin_add() { if ($this->request->is('post')) { if (!in_array($this->request->data['Libro']['isbn'], array('0', '', ' '))) { // convierto isbn a ean13 $isbn = $this->Libro->ean13($this->request->data['Libro']['isbn']); $id_temp = $this->Libro->find('first', array('fields' => array('id'), 'conditions' => array('isbn' => $isbn))); // si el isbn existe fuera if (isset($id_temp[$this->alias]['id'])) { $this->Session->setFlash(__('Este libro ya existe.')); $this->redirect('/inicio/mensaje'); } // llamo a _buscarLibro con el isbn para que devuelva un array con los // datos del libro $error = 0; $datos = $this->_buscarLibro($isbn); switch ($datos['Error']) { case 'Sin datos': $this->Session->setFlash(__('No se encontró el libro.<br />Lo siento, debes hacerlo a mano.'), 'default', array('class' => 'error-message'), 'encontrado'); $this->redirect('/admin/libros/new'); break; case 'Faltan datos': $error = 1; // break; // break; default: //se encontró el libro y se guarda $ides = array(); // para guardar todas las ides de los registros // guadar la editorial if (isset($datos['Publicación:'])) { $edito = new Editoriale(); if (isset($datos['Provincia:'])) { $edito->set(array('ciudad' => $datos['Provincia:'])); } $edito->set(array('nombre' => $datos['Publicación:'])); if (!$edito->checkExist()) { $edito->save(null, false); } $ides['Editorial'] = $edito->getID(); } else { $error = 1; // break; } // guardar los autores $ides['Autores'] = array(); if (isset($datos['Autor/es:'])) { foreach ($datos['Autor/es:'] as $autor) { $aut = new Autore(); $aut->set(array('nombre' => $autor)); if (!$aut->checkExist()) { $aut->save(null, false); } $ides['Autores'][] = $aut->getID(); } } else { $error = 1; // break; } // guardar los temas $ides['Temas'] = array(); if (isset($datos['Materia/s:'])) { foreach ($datos['Materia/s:'] as $tema) { $tem = new Tema(); $tem->set(array('nombre' => $tema)); if (!$tem->checkExist()) { $tem->save(null, false); } $ides['Temas'][] = $tem->getID(); } } else { $error = 1; // break; } // guardar el Libro $this->Libro->create(); if (isset($datos['Título:'])) { $this->Libro->set(array('titulo' => $datos['Título:'])); } if (isset($datos['Edición:'])) { $this->Libro->set(array('edicion' => $datos['Edición:'])); } if (isset($datos['Fecha Edición:'])) { $this->Libro->set(array('anio' => $datos['Fecha Edición:'])); } if (isset($datos['Encuadernación:'])) { $this->Libro->set(array('encuadernacion' => $datos['Encuadernación:'])); } if (isset($ides['Editorial'])) { $this->Libro->set(array('editoriale_id' => $ides['Editorial'])); } if (isset($ides['Autores'])) { $this->Libro->set(array('Autore' => $ides['Autores'])); } if (isset($ides['Temas'])) { $this->Libro->set(array('Tema' => $ides['Temas'])); } if (isset($isbn)) { $this->Libro->set(array('isbn' => $isbn)); } if ($error === 1) { $this->Session->setFlash(__('Datos incompletos debes hacerlo a mano.'), 'default', array('class' => 'error-message'), 'encontrado'); $this->Session->write('Datos', $datos); $this->Session->write('Isbn', $isbn); $this->Session->write('Ides', $ides); $this->redirect('/admin/libros/new'); } else { if (!$this->Libro->checkExist()) { if ($this->Libro->save(null, false)) { $this->Session->setFlash(__('Se guardó con éxito.')); $this->redirect('/admin/libros/view/' . $this->Libro->id); } } else { $this->Session->setFlash(__('Este libro ya existe.')); $this->redirect(array('controller' => 'inicio', 'action' => 'mensaje')); } } } } else { // si está vacío el campo isbn $this->redirect('/admin/libros/new'); } } }