public function actionEnroll() { $enrollmentModel = new Enrollment(); $userCourseEnrollmentModel = new UserCourseEnrollment(); $courseModel = new Course(); $userCourseEnrollmentModel->scenario = "enroll"; if (isset($_POST['Enrollment']) && isset($_POST['UserCourseEnrollment']) && isset($_POST['Course'])) { $enrollmentModel->attributes = $_POST['Enrollment']; $userCourseEnrollmentModel->attributes = $_POST['UserCourseEnrollment']; $courseModel->attributes = $_POST['Course']; $courseModel->course_code = $userCourseEnrollmentModel->course_code; //var_dump($courseModel); //echo $courseModel->exists('course_code=:code',array('code'=>$courseModel->course_code)); $transaction = Enrollment::model()->dbConnection->beginTransaction(); try { $enrollmentModel->datetime_created = new CDbExpression('now()'); if ($enrollmentModel->save()) { $userCourseEnrollmentModel->enrollment_id = $enrollmentModel->uid; $userCourseEnrollmentModel->enrolled_by = Yii::app()->getUser()->getId(); if ($userCourseEnrollmentModel->save()) { $transaction->commit(); $userCourseEnrollmentModel->refresh(); Yii::app()->user->setFlash('success', strtr('The Student was Enrolled in {course_code} assigned successfully.', array('{course_code}' => $courseModel->course_code))); $this->render('view', array('model' => $userCourseEnrollmentModel)); Yii::app()->end(); } else { $transaction->rollback(); } } } catch (Exception $ex) { $transaction->rollback(); } } $this->render('enroll', array('enrollmentModel' => $enrollmentModel, 'userCourseEnrollmentModel' => $userCourseEnrollmentModel, 'courseModel' => $courseModel)); }
/** * @before _secure, _school */ public function addToClass($user_id) { $usr = \User::first(array("id = ?" => $user_id), array("id")); if (!$usr) { self::redirect("/school"); } $this->setSEO(array("title" => "Parent Info | Student | School")); $view = $this->getActionView(); $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title")); $enrollment = Enrollment::first(array("user_id = ?" => $user_id)); if ($enrollment) { $view->set("success", "Student has already been added! Response will be updated"); } if (RequestMethods::post("action") == "addToClass") { $classroom = Markup::checkValue(RequestMethods::post("classroom")); if (!$enrollment) { $enrollment = new Enrollment(array()); } $enrollment->user_id = $usr->id; $enrollment->classroom_id = $classroom; $enrollment->organization_id = $this->organization->id; if ($enrollment->validate()) { $enrollment->save(); $view->set("success", "Student successfully added to classroom"); } } if ($enrollment) { $class = Classroom::first(array("id = ?" => $enrollment->classroom_id), array("id", "grade_id", "section")); foreach ($grades as $g) { if ($g->id == $class->grade_id) { $grade = $g->id; break; } } $view->set("class", $class); } if (!isset($grade)) { $grade = null; } $view->set("grade", $grade); $view->set("enrollment", $enrollment); $view->set("grades", $grades); }
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'); } }