public function actionProfesores() { if ($_SESSION['perfil'] == 1) { $params['active'] = 2; $params['vista'] = '_profesores'; $params['modelProfesor'] = new Profesor(); if (isset($_POST['Profesor'])) { try { $usuario = new Usuario(); $usuario->perfil = 2; $usuario->nombreUsuario = $_POST['Profesor']['identificacion']; $usuario->password = md5($_POST['Profesor']['identificacion']); if ($usuario->save()) { $profesor = new Profesor(); $profesor->attributes = $_POST['Profesor']; $profesor->idUsuario = $usuario->idUsuario; if (!$profesor->save()) { Yii::app()->user->setFlash('alert alert-danger', "Profesor no fue creado"); } else { Yii::app()->user->setFlash('alert alert-success', "Profesor fue creado con éxito"); } } else { Yii::app()->user->setFlash('alert alert-danger', "Usuario no fue creado"); } } catch (Exception $e) { Yii::app()->user->setFlash('alert alert-danger', "Usuario no fue creado"); } } $params['profesores'] = Profesor::model()->findAll(); } else { $params['active'] = 0; $params['vista'] = "_sinPermisos"; } $this->render('panel', array('params' => $params)); }
public function registrarProfesor() { $new_profesor = new Profesor(); $new_profesor->num_empleado = Input::get("num_empleado"); $new_profesor->password = Input::get("password"); $new_profesor->email = Input::get("email"); $new_datos_profesor = new DatosProfesor(); $new_datos_profesor->nombre = Input::get("nombre"); $new_datos_profesor->apellido_paterno = Input::get("apellido_paterno"); $new_datos_profesor->apellido_materno = Input::get("apellido_materno"); $new_datos_profesor->sexo = Input::get("sexo"); $new_datos_profesor->celular = Input::get("celular"); // Pequeño hack. Primero lo ponemos como archivo para validarlo, después le asignamos la ruta real para guardarlo $new_datos_profesor->ruta = Input::file('cv'); if ($new_profesor->validate()) { if ($new_datos_profesor->validate()) { $nombreCV = Input::get("nombre") . "_" . Input::get("apellido_paterno") . "_" . Input::get("apellido_materno") . "_CV.pdf"; //CHECAR PORQUE NO SE CREA EL PUTO CV!!! Input::file('cv')->move("CVs", $nombreCV); $new_datos_profesor->ruta = "/CVs/" . $nombreCV; //Ahora si, guardamos todo después de haberlo validado $new_profesor->save(); $new_datos_profesor->profesor()->associate($new_profesor); // Forzamos Save porque sabemos que no validará ruta como un string, sino como un file $new_datos_profesor->forceSave(); return Redirect::to('/'); } else { return Redirect::route('registro')->withErrors($new_datos_profesor->errors())->withInput(); } } else { $new_datos_profesor->validate(); $erroresValidaciones = array_merge_recursive($new_profesor->errors()->toArray(), $new_datos_profesor->errors()->toArray()); return Redirect::route('registro')->withErrors($erroresValidaciones)->withInput(); } }
public function nuevo() { if (Input::haspost("profesor")) { $profesor = new Profesor(Input::post("profesor")); $profesor->asignarPassword(); $profesor->asignarIp(); if ($profesor->save()) { Flash::valid("Nuevo profesor guardado con éxito!"); } else { Flash::error("No se guardó el nuevo profesor!"); } } Router::redirect("profesor/"); }