Пример #1
0
    public static function matricularUno($alumno_id, $grupo_id)
    {
        $year = Year::where('actual', '=', true)->first();
        $consulta = 'SELECT m.id, m.alumno_id, m.grupo_id, m.matriculado, g.year_id 
			FROM matriculas m 
			inner join grupos g 
				on m.alumno_id = :alumno_id and g.year_id = :year_id and m.grupo_id=g.id';
        $matriculas = DB::select(DB::raw($consulta), array('alumno_id' => $alumno_id, 'year_id' => $year->id));
        $matricula = false;
        for ($i = 0; $i < count($matriculas); $i++) {
            $matri = Matricula::onlyTrashed()->where('id', $matriculas[$i]->id)->first();
            /*
            $queries = DB::getQueryLog();
            $last_query = end($queries);
            return $last_query;
            */
            if ($matri) {
                if ($matri->grupo_id == $grupo_id) {
                    if ($matricula) {
                        // Si ya he encontrado en un elemento anterior una matrícula identica, es por que ya la he activado, no debo activar más. Por el contrario, debo borrarlas
                        ${$matri}->delete();
                    } else {
                        $matri->matriculado = true;
                        $matri->fecha_retiro = null;
                        $matri->save();
                        $matri->restore();
                        $matricula = $matri;
                    }
                } else {
                    $matri->delete();
                }
            }
        }
        try {
            if (!$matricula) {
                $matricula = new Matricula();
                $matricula->alumno_id = $alumno_id;
                $matricula->grupo_id = $grupo_id;
                $matricula->matriculado = true;
                $matricula->save();
            }
        } catch (Exception $e) {
            // se supone que esto nunca va a ocurrir, ya que eliminé todas las matrículas
            // excepto la que concordara con el grupo, poniéndola en matriculado=true
            $matricula = Matricula::where('alumno_id', '=', $alumno_id)->where('grupo_id', '=', $grupo_id)->first();
            $matricula->matriculado = true;
            $matricula->save();
        }
        return $matricula;
    }
Пример #2
0
 public function deleteDestroy($id)
 {
     $img = ImageModel::findOrFail($id);
     $filename = 'images/perfil/' . $img->nombre;
     // Debería crear un código que impida borrar si la imagen es usada.
     if (File::exists($filename)) {
         File::delete($filename);
         $img->delete();
     } else {
         return 'No se encuentra la imagen a eliminar. ' . $img->nombre;
     }
     // Elimino cualquier referencia que otros tengan a esa imagen borrada.
     $alumnos = Alumno::where('foto_id', $id)->get();
     foreach ($alumnos as $alum) {
         $alum->foto_id = null;
         $alum->save();
     }
     $profesores = Profesor::where('foto_id', $id)->get();
     foreach ($profesores as $prof) {
         $prof->foto_id = null;
         $prof->save();
     }
     $acudientes = Acudiente::where('foto_id', $id)->get();
     foreach ($acudientes as $acud) {
         $acud->foto_id = null;
         $acud->save();
     }
     $users = User::where('imagen_id', $id)->get();
     foreach ($users as $user) {
         $user->imagen_id = null;
         $user->save();
     }
     $years = Year::where('logo_id', $id)->get();
     foreach ($years as $year) {
         $year->logo_id = null;
         $year->save();
     }
     $asks = ChangeAsked::where('oficial_image_id', $id)->destroy();
     return $img;
 }
Пример #3
0
 public static function actual()
 {
     $year = Year::where('actual', true)->first();
     return $year;
 }
Пример #4
0
    public function getTrashed()
    {
        $user = User::fromToken();
        $previous_year = $user->year - 1;
        $id_previous_year = 0;
        $previous_year = Year::where('year', '=', $previous_year)->first();
        $consulta = 'SELECT m2.matricula_id, a.id as alumno_id, a.no_matricula, a.nombres, a.apellidos, a.sexo, a.user_id, 
				a.fecha_nac, a.ciudad_nac, a.celular, a.direccion, a.religion,
				m2.year_id, m2.grupo_id, m2.nombregrupo, m2.abrevgrupo, IFNULL(m2.actual, -1) as currentyear,
				u.username, u.is_superuser, u.is_active
			FROM alumnos a left join 
				(select m.id as matricula_id, g.year_id, m.grupo_id, m.alumno_id, g.nombre as nombregrupo, g.abrev as abrevgrupo, 0 as actual
				from matriculas m INNER JOIN grupos g ON m.grupo_id=g.id and g.year_id=:id_previous_year
				and m.alumno_id NOT IN 
					(select m.alumno_id
					from matriculas m INNER JOIN grupos g ON m.grupo_id=g.id and g.year_id=:year_id)
					union
					select m.id as matricula_id, g.year_id, m.grupo_id, m.alumno_id, g.nombre as nombregrupo, g.abrev as abrevgrupo, 1 AS actual
					from matriculas m INNER JOIN grupos g ON m.grupo_id=g.id and g.year_id=:year2_id
				)m2 on a.id=m2.alumno_id
			left join users u on u.id=a.user_id where a.deleted_at is not null';
        return DB::select(DB::raw($consulta), array(':id_previous_year' => $id_previous_year, ':year_id' => $user->year_id, ':year2_id' => $user->year_id));
    }
Пример #5
0
 public function postStore()
 {
     $user = User::fromToken();
     $year = new Year();
     $year->year = Request::input('year');
     $year->nombre_colegio = Request::input('nombre_colegio');
     $year->abrev_colegio = Request::input('abrev_colegio');
     $year->nota_minima_aceptada = Request::input('nota_minima_aceptada');
     $year->resolucion = Request::input('resolucion');
     $year->codigo_dane = Request::input('codigo_dane');
     //$year->encabezado_certificado	=	Request::input('encabezado_certificado');
     //$year->frase_final_certificado	=	Request::input('frase_final_certificado');
     $year->actual = Request::input('actual');
     $year->telefono = Request::input('telefono');
     $year->celular = Request::input('celular');
     $year->unidad_displayname = Request::input('unidad_displayname');
     $year->unidades_displayname = Request::input('unidades_displayname');
     $year->genero_unidad = Request::input('genero_unidad');
     $year->subunidad_displayname = Request::input('subunidad_displayname');
     $year->subunidades_displayname = Request::input('subunidades_displayname');
     $year->genero_subunidad = Request::input('genero_subunidad');
     $year->website = Request::input('website');
     $year->website_myvc = Request::input('website_myvc');
     $year->alumnos_can_see_notas = Request::input('alumnos_can_see_notas');
     $year->save();
     if ($year->actual) {
         Year::where('actual', true)->update(['actual' => false]);
     }
     // NECESITARÉ MUCHO EL AÑO ANTERIOR
     $year_ante = $year->year - 1;
     $pasado = Year::where('year', $year_ante)->first();
     if ($pasado) {
         $year->ciudad_id = $pasado->ciudad_id;
         $year->logo_id = $pasado->logo_id;
         $year->rector_id = $pasado->rector_id;
         $year->secretario_id = $pasado->secretario_id;
         $year->tesorero_id = $pasado->tesorero_id;
         $year->coordinador_academico_id = $pasado->coordinador_academico_id;
         $year->coordinador_disciplinario_id = $pasado->coordinador_disciplinario_id;
         $year->capellan_id = $pasado->capellan_id;
         $year->psicorientador_id = $pasado->psicorientador_id;
         $year->save();
         /// COPIAREMOS LAS ESCALAS DE VALORACIÓN
         $escalas_ant = EscalaDeValoracion::where('year_id', $pasado->id)->get();
         foreach ($escalas_ant as $key => $escalas) {
             $newEsc = new EscalaDeValoracion();
             $newEsc->desempenio = $escalas->desempenio;
             $newEsc->valoracion = $escalas->valoracion;
             $newEsc->porc_inicial = $escalas->porc_inicial;
             $newEsc->porc_final = $escalas->porc_final;
             $newEsc->descripcion = $escalas->descripcion;
             $newEsc->orden = $escalas->orden;
             $newEsc->perdido = $escalas->perdido;
             $newEsc->year_id = $year->id;
             $newEsc->icono_infantil = $escalas->icono_infantil;
             $newEsc->icono_adolescente = $escalas->icono_adolescente;
             $newEsc->save();
         }
         /// COPIAREMOS LAS FRASES
         $frases_ant = Frase::where('year_id', $pasado->id)->get();
         foreach ($frases_ant as $key => $frases) {
             $newFra = new Frase();
             $newFra->frase = $frases->frase;
             $newFra->tipo_frase = $frases->tipo_frase;
             $newFra->year_id = $year->id;
             $newFra->save();
         }
         /// AHORA COPIAMOS LOS GRUPOS Y ASIGNATURAS DEL AÑO PASADO AL NUEVO AÑO.
         $grupos_ant = Grupo::where('year_id', $pasado->id)->get();
         foreach ($grupos_ant as $key => $grupo) {
             $newGr = new Grupo();
             $newGr->nombre = $grupo->nombre;
             $newGr->abrev = $grupo->abrev;
             $newGr->year_id = $year->id;
             $newGr->grado_id = $grupo->grado_id;
             $newGr->valormatricula = $grupo->valormatricula;
             $newGr->valorpension = $grupo->valorpension;
             $newGr->orden = $grupo->orden;
             $newGr->caritas = $grupo->caritas;
             $newGr->save();
             $asigs_ant = Asignatura::where('grupo_id', $grupo->id)->get();
             foreach ($asigs_ant as $key => $asig) {
                 $newAsig = new Asignatura();
                 $newAsig->materia_id = $asig->materia_id;
                 $newAsig->grupo_id = $asig->grupo_id;
                 $newAsig->creditos = $asig->creditos;
                 $newAsig->orden = $asig->orden;
                 $newAsig->save();
             }
             $grupo->asigs_ant = $asigs_ant;
         }
         $year->grupos_ant = $grupos_ant;
     }
     return $year;
 }