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 editarDatos() { if (Request::ajax()) { $new_profesor = Profesor::find(Auth::user()->id); $new_profesor->email = Input::get("email"); $new_datos_profesor = DatosProfesor::where('profesor_id', '=', Auth::user()->id)->first(); $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->celular = Input::get("celular"); if ($new_datos_profesor->validate(array('nombre' => 'required', 'apellido_paterno' => 'required', 'apellido_materno' => 'required', 'celular' => 'required|digits:10'))) { if ($new_profesor->updateUniques()) { $new_datos_profesor->forceSave(); return Response::json(array('success' => true)); } else { return Response::json(array('success' => false, 'errores' => $new_profesor->errors()->toArray())); } } else { return Response::json(array('success' => false, 'errores' => $new_datos_profesor->errors()->toArray())); } } }
@stop @section('body') <div id="cargandoDocumento" class="text-center"><img class="cargandoDocumento" src="{{ asset('images/cargando-documento.gif') }}" /><br/><h1>Generando Documento</h1></div> <div id="divFormAgregarDocumento" class="center-block fullWidth"> <h1 class="text-center">Añadir una nueva Planeacion Didáctica</h1> <div class="col-xs-11 center-block"> {{ Form::open(array('id'=>'formAgregarDocumento', 'role'=>'form', 'route'=>'jdd-doc-plan-didac')) }} <span class="mensajeError alert-danger"></span> <div class="form-group row"> {{ Form::label('fecha_creacion', 'Fecha de creación del documento', array('class' => 'col-xs-12 col-sm-6'))}} {{ Form::text('fecha_creacion', date("Y-m-d"), array('class' => 'col-xs-12 col-sm-6', 'readonly')) }} </div> <div class="form-group row"> <?php $nombre = DatosProfesor::whereProfesorID(Auth::user()->id)->select(DB::raw('CONCAT(nombre, " ", apellido_materno, " ", apellido_paterno) as nombre'))->pluck('nombre'); ?> {{ Form::label('profesor', 'Nombre del profesor', array('class' => 'col-xs-12 col-sm-6'))}} {{ Form::text('profesor', $nombre, array('class' => 'col-xs-12 col-sm-6', 'readonly')) }} </div> <div class="form-group row"> {{ Form::label('asignatura_id', 'Asignatura', array('class' => 'col-xs-12 col-sm-6'))}} <?php $collection = DB::table('datos_profesor')->join('profesores', 'profesores.id', '=', 'datos_profesor.profesor_id')->join('asignaturas_grupos_profesores', 'asignaturas_grupos_profesores.profesores_id', '=', 'profesores.id')->where('asignaturas_grupos_profesores.profesores_id', '=', Auth::user()->id)->join('asignaturas_grupos', 'asignaturas_grupos.id', '=', 'asignaturas_grupos_profesores.asignaturas_grupos_id')->join('asignaturas', 'asignaturas.id', '=', 'asignaturas_grupos.asignatura_id')->select('asignaturas.id', 'asignaturas.nombre')->get(); $collection = array_values(array_sort($collection, function ($value) { return $value->nombre; })); $arreglo = array(); $arreglo[0] = ""; foreach ($collection as $clave => $valor) { $arreglo[$valor->id] = $valor->nombre;
public function run() { $faker = Faker\Factory::create(); $primerNumValido = 11110; for ($i = 0; $i < 150; $i++) { ProfesorValido::create(['num_empleado' => $primerNumValido + $i]); } for ($i = 1; $i <= 100; $i++) { Profesor::create(['num_empleado' => $primerNumValido + $i, 'password' => '' . ($primerNumValido + $i), 'email' => $faker->unique()->email, 'status' => 1, 'rol' => $i == 1 ? "subdirector" : ($i == 2 ? "JDD" : ($i == 3 || $i == 5 ? "PDA" : ($i == 4 || $i == 6 ? "JDA" : "profesor")))]); } // Añadir más de cada uno y asignarlos a academias y deptos // for ($i = 1; $i <= 100; $i++) { $sexo = rand(0, 1) ? 'H' : 'M'; $nombre = $sexo == 'H' ? $faker->firstName('male') : $faker->firstName('female'); $aux = DatosProfesor::create(['nombre' => $nombre, 'apellido_paterno' => $faker->lastName, 'apellido_materno' => $faker->lastName, 'sexo' => $sexo, 'celular' => $faker->numberBetween($min = 1111111111, $max = 9999999999), 'ruta' => $nombre . '_' . $faker->word . '_CV.pdf', 'profesor_id' => $i]); $aux->forceSave(); // NI IDEA DE PORQUE TUVE QUE HACER ESTO, NO JALABA DE OTRA FORMA } Departamento::create(['nombre' => 'Departamento X', 'profesores_id' => 2]); Departamento::create(['nombre' => 'Departamento Y', 'profesores_id' => null]); Academia::create(['nombre' => 'Academia A', 'profesores_id' => 3, 'departamentos_id' => 1]); Academia::create(['nombre' => 'Academia B', 'profesores_id' => 5, 'departamentos_id' => 1]); Academia::create(['nombre' => 'Academia C', 'profesores_id' => null, 'departamentos_id' => 1]); Academia::create(['nombre' => 'Academia D', 'profesores_id' => null, 'departamentos_id' => 2]); Academia::create(['nombre' => 'Academia E', 'profesores_id' => null, 'departamentos_id' => 2]); for ($i = 0; $i < 10; $i++) { $nombre = $faker->sentence(3); Asignatura::create(['nombre' => 'Materia ' . substr($nombre, 0, strlen($nombre) - 1), 'academia_id' => 1, 'profesores_id' => $i == 0 ? 4 : null]); } for ($i = 0; $i < 10; $i++) { $nombre = $faker->sentence(3); Asignatura::create(['nombre' => 'Materia ' . substr($nombre, 0, strlen($nombre) - 1), 'academia_id' => 2, 'profesores_id' => $i == 0 ? 6 : null]); } for ($i = 0; $i < 10; $i++) { $nombre = $faker->sentence(3); Asignatura::create(['nombre' => 'Materia ' . substr($nombre, 0, strlen($nombre) - 1), 'academia_id' => 3, 'profesores_id' => null]); } for ($i = 0; $i < 10; $i++) { $nombre = $faker->sentence(3); Asignatura::create(['nombre' => 'Materia ' . substr($nombre, 0, strlen($nombre) - 1), 'academia_id' => 4, 'profesores_id' => null]); } for ($i = 0; $i < 10; $i++) { $nombre = $faker->sentence(3); Asignatura::create(['nombre' => 'Materia ' . substr($nombre, 0, strlen($nombre) - 1), 'academia_id' => 5, 'profesores_id' => null]); } for ($i = 1; $i <= 8; $i++) { for ($j = 1; $j <= 12; $j++) { Grupo::create(['nombre' => $i . 'CM' . $j]); } } $arrayAsignaturasGrupos = array(); $arrayAsignaturasGruposProfesores = array(); $arrayAcademiasProfesores = array(); for ($i = 1; $i <= 96; $i++) { //Hay 96 grupos $materiasUsadas = array(); $academiasUsadas = array(); for ($j = 1; $j <= 5; $j++) { // Asignar 5 materias por grupo y al profesor a academia $profesor = $faker->numberBetween(1, 100); do { $materia = $faker->numberBetween(1, 50); } while (in_array($materia, $materiasUsadas)); $materiasUsadas[] = $materia; $arrayAsignaturasGrupos[] = array('asignatura_id' => $materia, 'grupo_id' => $i); $idAGP = count($arrayAsignaturasGrupos); $arrayAsignaturasGruposProfesores[] = array('asignaturas_grupos_id' => $idAGP, 'profesores_id' => $profesor); if ($materia <= 10) { $academia = 1; } else { if ($materia <= 20) { $academia = 2; } else { if ($materia <= 30) { $academia = 3; } else { if ($materia <= 40) { $academia = 4; } else { $academia = 5; } } } } if (!in_array($academia, $academiasUsadas)) { $arrayAcademiasProfesores[] = array('academias_id' => $academia, 'profesores_id' => $profesor); } } unset($materiasUsadas); unset($academiasUsadas); } $arrayAcademiasProfesores = array_unique($arrayAcademiasProfesores, SORT_REGULAR); TipoDocumento::create(['nombre' => "Convocatoria y Orden del dia", 'rol' => 'PDAJDA']); TipoDocumento::create(['nombre' => "Informe Semestral de Academia", 'rol' => 'PDA']); TipoDocumento::create(['nombre' => "Informe Semestral de Asignatura", 'rol' => 'JDA']); TipoDocumento::create(['nombre' => "Lista de Asistencia", 'rol' => 'PDAJDA']); TipoDocumento::create(['nombre' => "Memorandum", 'rol' => 'PDAJDA']); TipoDocumento::create(['nombre' => "Minuta", 'rol' => 'PDAJDA']); TipoDocumento::create(['nombre' => "Planeación Didáctica", 'rol' => 'profesor']); TipoDocumento::create(['nombre' => "Seguimiento Programático", 'rol' => 'profesor']); $arrayDocumentos = array(); $arrayDocumentos[] = array('ruta' => 'ruta/que/no/existe.pdf', 'fecha_agregacion' => '2015-01-18', 'ciclo' => '2014-2015/1', 'periodo' => '19/1', 'tipos_documento_id' => '1', 'profesor_id' => '3', 'academia_id' => '1', 'asignatura_id' => '1'); $arrayDocumentos[] = array('ruta' => 'otra/ruta/que/no/existe.pdf', 'fecha_agregacion' => '2015-01-30', 'ciclo' => '2014-2015/1', 'periodo' => '19/1', 'tipos_documento_id' => '2', 'profesor_id' => '4', 'academia_id' => '1', 'asignatura_id' => '3'); $arrayDocumentos[] = array('ruta' => 'ruta/no/existe.pdf', 'fecha_agregacion' => '2015-02-10', 'ciclo' => '2014-2015/1', 'periodo' => '19/1', 'tipos_documento_id' => '3', 'profesor_id' => '5', 'academia_id' => '1', 'asignatura_id' => '2'); DB::table('asignaturas_grupos')->insert($arrayAsignaturasGrupos); DB::table('asignaturas_grupos_profesores')->insert($arrayAsignaturasGruposProfesores); DB::table('academias_profesores')->insert($arrayAcademiasProfesores); DB::table('documentos')->insert($arrayDocumentos); }