public function edit($id)
 {
     $cursos = Curso::findOrFail($id);
     $asignaturas = Asignatura::lists('nombre', 'id');
     $docentes = Docente::lists('nombres', 'id');
     return view('Administrador.CursoCrud.editarCurso', compact('cursos', 'asignaturas', 'docentes'));
 }
 public function edit($id)
 {
     $cursos = Curso::findOrFail($id);
     $asignaturas = Asignatura::lists('nombre', 'id');
     $docentes = Docente::lists('nombres', 'id');
     return view('Encargado.Curso.editarCursoE', compact('cursos', 'asignaturas', 'docentes'));
 }
 public function destroy($id)
 {
     $docentes = Docente::find($id);
     $docentes->delete();
     Session::flash('message', 'El docente ' . $docentes->nombres . ' de rut ' . $docentes->rut . ' fue eliminado');
     return redirect()->route('Encargado.docentes.index');
 }
 public function store(Request $request)
 {
     //dd('jajaja');
     $file = $request->file('file');
     if (is_null($request->file('file'))) {
         Session::flash('message', 'Seleccion el archivo');
         return redirect()->back();
     }
     //obtenemos el campo file obtenido por el formulario
     $nombre = $file->getClientOriginalName();
     //indicamos que queremos guardar un nuevo archivo en el disco local
     \Storage::disk('local')->put($nombre, \File::get($file));
     $falla = false;
     $departamentos = $request->get('departamentos');
     //  dd($departamentos);
     \Excel::load('/storage/public/files/' . $nombre, function ($archivo) use(&$falla) {
         $result = $archivo->get();
         //leer todas las filas del archivo
         foreach ($result as $key => $value) {
             $departamentos = Departamento::whereNombre($value->departamento_id)->pluck('id');
             if (is_null($departamentos)) {
                 // El campus no existe, deberia hacer algo para mitigar esto, o retornarlo al usuario ...
             }
             $var = new Docente();
             $datos = ['rut' => $value->rut, 'nombres' => $value->nombres, 'apellidos' => $value->apellidos, 'email' => $value->email, 'departamento_id' => $departamentos];
             $validator = Validator::make($datos, Docente::storeRules());
             if ($validator->fails()) {
                 Session::flash('message', 'Los Docentes ya existen o el archivo ingresado no es valido');
                 $falla = true;
             } else {
                 $var->fill($datos);
                 $var->save();
             }
         }
     })->get();
     if ($falla) {
         // Fallo la validacion de algun campus, retornar al index con mensaje
         return redirect()->route('Encargado.docentes.index');
     }
     \Storage::delete($nombre);
     Session::flash('message', 'Los Docentes fueron agregados exitosamente!');
     return redirect()->route('Encargado.docentes.index');
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Docente::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['idDocente' => $this->idDocente]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'apellidos', $this->apellidos])->andFilterWhere(['like', 'correo', $this->correo]);
     return $dataProvider;
 }
 public function store(Request $request)
 {
     //dd('jajaja');
     $file = $request->file('file');
     //obtenemos el campo file obtenido por el formulario
     if (is_null($request->file('file'))) {
         Session::flash('message', 'Seleccion el archivo');
         return redirect()->back();
     }
     $nombre = $file->getClientOriginalName();
     //indicamos que queremos guardar un nuevo archivo en el disco local
     \Storage::disk('local')->put($nombre, \File::get($file));
     $asignaturas = $request->get('asignaturas');
     $docentes = $request->get('docentes');
     $falla = false;
     \Excel::load('/storage/public/files/' . $nombre, function ($archivo) use(&$falla) {
         $result = $archivo->get();
         //leer todas las filas del archivo
         foreach ($result as $key => $value) {
             $asignaturas = Asignatura::whereNombre($value->asignatura_id)->pluck('id');
             $docentes = Docente::whereNombres($value->docente_id)->pluck('id');
             //echo $facultades."<br>";
             if (is_null($asignaturas)) {
                 // El campus no existe, deberia hacer algo para mitigar esto, o retornarlo al usuario ...
             }
             if (is_null($docentes)) {
                 // El campus no existe, deberia hacer algo para mitigar esto, o retornarlo al usuario ...
             }
             //if(!Curso::whereNombre('asignatura_id',$asignaturas)->whereNombres('docente_id',$docentes)->first()){
             $var = new Curso();
             $datos = ['asignatura_id' => $asignaturas, 'docente_id' => $docentes, 'semestre' => $value->semestre, 'anio' => $value->anio, 'seccion' => $value->seccion];
             $validator = Validator::make($datos, Curso::storeRules());
             if ($validator->fails()) {
                 Session::flash('message', 'Los Cursos ya existen o el archivo ingresado no es valido');
                 $falla = true;
             } else {
                 $var->fill($datos);
                 $var->save();
             }
         }
     })->get();
     if ($falla) {
         // Fallo la validacion de algun campus, retornar al index con mensaje
         return redirect()->route('Encargado.cursos.index');
     }
     \Storage::delete($nombre);
     Session::flash('message', 'Los Cursos fueron agregados exitosamente!');
     return redirect()->route('Encargado.cursos.index');
 }
 public function show($id)
 {
     $docentes = Docente::find($id);
     //dd($Campus);
     if ($docentes) {
         $data = array(array('rut', 'nombres', 'apellidos', 'email', 'departamento_id'), array($docentes->rut, $docentes->nombres, $docentes->apellidos, $docentes->email, $docentes->departamentos->nombre));
         Excel::create('Docentes' . $docentes->nombres, function ($excel) use($data) {
             $excel->sheet('Sheetname', function ($sheet) use($data) {
                 $sheet->fromArray($data);
             });
         })->download('csv');
     } else {
         abort('404');
     }
 }
Beispiel #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdDocente0()
 {
     return $this->hasOne(Docente::className(), ['idDocente' => 'idDocente']);
 }
 /**
  * Finds the Docente model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Docente the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Docente::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDocente()
 {
     return $this->hasOne(Docente::className(), ['id' => 'docente_id']);
 }