Esempio n. 1
0
 public function getColegio()
 {
     $user = User::fromToken();
     $years = Year::all();
     foreach ($years as $year) {
         $year->periodos = Periodo::where('year_id', $year->id)->get();
     }
     $certif = ConfigCertificado::all();
     $imagenes = ImageModel::where('user_id', $user->user_id)->where('publica', true)->get();
     $result = ['years' => $years, 'certificados' => $certif, 'imagenes' => $imagenes];
     return $result;
 }
Esempio n. 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;
 }
Esempio n. 3
0
 public function getShow($id)
 {
     $alumno = Alumno::findOrFail($id);
     if (!is_null($alumno->user_id)) {
         $alumno->user = User::findOrFail($alumno->user_id);
     }
     $imagen = ImageModel::find($alumno->foto_id);
     if ($imagen) {
         $alumno->foto_nombre = $imagen->nombre;
     } else {
         if ($alumno->sexo == 'F') {
             $alumno->foto_nombre = 'default_female.jpg';
         } else {
             $alumno->foto_nombre = 'default_male.jpg';
         }
     }
     return $alumno;
 }