public function my_schedule() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_mi_horario', $data["actions"])) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return View::make('schedule/academic_year_error', $data); } $student = $data["user"]->student; $data["enrollment_info"] = $student->getCurrentEnrollment(); $data["level"] = $data["enrollment_info"]->level; $data["schedules_data"] = $data["level"]->schedules()->orderBy('initial_hour')->get(); return View::make('schedule/my_schedule', $data); } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ private function updateInfo() { if (!Yii::app()->user->isGuest) { $this->currentUser = User::model()->findByAttributes(array("email" => Yii::app()->user->name)); $userId = $this->currentUser->id; $this->academicYears = AcademicYear::model()->findAll(array("condition" => "student_id = {$userId}")); } }
public function getCurrentYearHomeworks() { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return null; } return $this->homeworks()->where('academic_year_id', '=', $current_ay->id)->orderBy('created_at', 'DESC'); }
public static function search($search_text, $search_state, $search_level) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return null; } if ($search_level) { return Enrollment::join('students', 'students.id', '=', 'enrollments.student_id')->where(function ($query) use($search_text) { $query->where('names', 'LIKE', "%{$search_text}%")->orWhere('lastname', 'LIKE', "%{$search_text}%"); })->where('enrollments.academic_year_id', '=', $current_ay->id)->where('enrollments.level_id', '=', $search_level)->where('enrollments.state', '=', $search_state)->orderBy('enrollments.date')->select('enrollments.*'); } else { return Enrollment::join('students', 'students.id', '=', 'enrollments.student_id')->where(function ($query) use($search_text) { $query->where('names', 'LIKE', "%{$search_text}%")->orWhere('lastname', 'LIKE', "%{$search_text}%"); })->where('enrollments.academic_year_id', '=', $current_ay->id)->where('enrollments.state', '=', $search_state)->orderBy('enrollments.date')->select('enrollments.*'); } }
public static function getStudentsEnrolledInLevel($level_id) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return null; } $enrolled_students = Student::whereHas('enrollments', function ($q) use($current_ay, $level_id) { $q->where('academic_year_id', '=', $current_ay->id)->where('state', '=', 'A')->where('level_id', '=', $level_id); }); return $enrolled_students->orderBy('lastname')->get(); }
public function answer_incident() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_mis_anotaciones', $data["actions"])) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return View::make('control_notebook_incidents/academic_year_error', $data); } $incident_id = Input::get('incident_id'); // Validate the info, create rules for the inputs $attributes = array('parent_comment' => 'Respuesta o comentario'); $messages = array(); $rules = array('parent_comment' => 'required|max:300'); // Run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules, $messages, $attributes); // If the validator fails, redirect back to the form if ($validator->fails()) { return Redirect::to('control_notebook_incidents/show_my_incident/' . $incident_id)->withErrors($validator)->withInput(Input::all()); } else { $incident = ControlNotebookIncident::find($incident_id); $incident->parent_comment = Input::get('parent_comment'); $incident->save(); Session::flash('message', 'Se registró correctamente la respuesta.'); // Llamo a la función para registrar el log de auditoria $log_description = "Se respondió a la Anotación con id: {{$incident->id}}"; Helpers::registerLog(4, $log_description); return Redirect::to('control_notebook_incidents/show_my_incident/' . $incident_id)->withInput(Input::all()); } } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
public function delete_academic_year() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_nuevo_anho_escolar', $data["actions"])) { $academic_year_id = Input::get('academic_year_id'); $academic_year = AcademicYear::find($academic_year_id); // verificar si existen matriculas en el año escolar $exist_enrollments = $academic_year->enrollments; if ($exist_enrollments->isEmpty()) { // elimino los comunicados $academic_year->notices()->delete(); // elimino las tareas $academic_year->homeworks()->delete(); // elimino las evaluaciones $academic_year->evaluations()->delete(); // elimino el año escolar $academic_year->delete(); // borro las carpetas $success = File::deleteDirectory('files/' . $academic_year->dir_name . '/'); // Llamo a la función para registrar el log de auditoria $log_description = "Se eliminó el Año escolar con id {{$academic_year->id}}"; Helpers::registerLog(5, $log_description); Session::flash('message', 'Se eliminó correctamente el Año escolar.'); return Redirect::to('academic_years/list_academic_years'); } else { Session::flash('error', 'Hay alumnos matriculados en este Año Escolar. No es posible eliminarlo.'); return Redirect::to('academic_years/edit_academic_year/' . $academic_year->id); } } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
public function show_homework($id) { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_mis_tareas', $data["actions"])) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return View::make('homeworks/academic_year_error', $data); } $data["homework_info"] = Homework::find($id); if (!$data["homework_info"]) { Session::flash('error', 'No se encontró la Tarea solicitada.'); return Redirect::to('homeworks/my_homeworks'); } $data["course_info"] = $data["homework_info"]->course; $data["level_info"] = $data["course_info"]->level; return View::make('homeworks/show_homework', $data); } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
public static function getCurrentAcademicYear() { $today = date('Y-m-d'); return AcademicYear::where('initial_date', '<=', $today)->where('final_date', '>=', $today)->first(); }
public function submit_offline_enrollments() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_matricula_offline', $data["actions"])) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return View::make('enrollments/academic_year_error', $data); } $students = Input::get('students'); if (!$students) { Session::flash('error', 'No seleccionó ningún alumno.'); return Redirect::to('enrollments/offline_enrollment'); } foreach ($students as $student_id) { $enrollment = new Enrollment(); $enrollment->date = date('Y-m-d'); $enrollment->state = 'A'; $enrollment->student_id = $student_id; $enrollment->academic_year_id = $current_ay->id; $enrollment->level_id = Student::find($student_id)->getLevelToEnroll()->id; $enrollment->doc_name = null; $enrollment->save(); // Llamo a la función para registrar el log de auditoria $log_description = "Se creó la Matrícula con id: {{$enrollment->id}}"; Helpers::registerLog(3, $log_description); } Session::flash('message', 'Los alumnos fueron matriculados exitosamente.'); return Redirect::to('enrollments/offline_enrollment'); } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return AcademicYear the loaded model * @throws CHttpException */ public function loadModel($id) { $model = AcademicYear::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function show_notice($id) { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_ver_comunicados', $data["actions"])) { $current_ay = AcademicYear::getCurrentAcademicYear(); if (!$current_ay) { return View::make('notices/academic_year_error', $data); } $data["notice_info"] = Notice::find($id); if (!$data["notice_info"]) { Session::flash('error', 'No se encontró el Comunicado solicitado.'); return Redirect::to('notices/view_notices'); } if ($data["user"]->profiles()->where('name', '=', 'Alumno')->first()) { $data["can_delete"] = false; } elseif ($data["user"]->profiles()->where('name', '=', 'Director')->first()) { $data["can_delete"] = true; } elseif ($data["user"]->profiles()->where('name', '=', 'Profesor')->first()) { if ($data["user"]->teacher->id == $data["notice_info"]->teacher_id) { $data["can_delete"] = true; } else { $data["can_delete"] = false; } } elseif ($data["user"]->profiles()->where('name', '=', 'Personal Administrativo')->first()) { if (AdministrativeStaff::where('user_id', '=', $data["user"]->id)->first()->id == $data["notice_info"]->administrative_staff_id) { $data["can_delete"] = true; } else { $data["can_delete"] = false; } } else { $data["can_delete"] = true; } return View::make('notices/show_notice', $data); } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }