예제 #1
0
 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));
 }
예제 #2
0
/**
 * get data for an individual study based on 
 * the user's researcher_id and a supplied study_id
 * creates $study smarty variable
 */
function smarty_function_study($params, &$smarty)
{
    if (!Check::digits($params['study_id'])) {
        $smarty->assign('study', array());
        return;
    }
    $s = new Study();
    $study = $s->study($_SESSION['user']['researcher_id'], $params['study_id']);
    $p = new Enrollment();
    $participants = $p->howmany(array(" where study_id=%u and active>0 ", $params['study_id']));
    $smarty->assign('study', $study);
    $smarty->assign('participants', $participants);
}
예제 #3
0
 protected static function _init()
 {
     $session = Registry::get("session");
     if (!self::$_classroom) {
         if (!$session->get('StudentService:$classroom')) {
             $enrollment = \Enrollment::first(array("user_id = ?" => self::$_student->user_id), array("classroom_id"));
             $c = \Classroom::first(array("id = ?" => $enrollment->classroom_id), array("grade_id", "section", "year", "id", "created"));
             $g = \Grade::first(array("id = ?" => $c->grade_id), array("title", "id"));
             $classroom = array("id" => $c->id, "grade" => $g->title, "grade_id" => $g->id, "section" => $c->section, "year" => $c->year, "created" => $c->created);
             $classroom = ArrayMethods::toObject($classroom);
             $session->set('StudentService:$classroom', $classroom);
         }
         self::$_classroom = $session->get('StudentService:$classroom');
     }
     if (!self::$_courses) {
         if (!$session->get('StudentService:$courses')) {
             $courses = \Course::all(array("grade_id = ?" => self::$_classroom->grade_id));
             $subject = array();
             foreach ($courses as $c) {
                 $subject[$c->id] = $c;
             }
             $session->set('StudentService:$courses', $subject);
         }
         self::$_courses = $session->get('StudentService:$courses');
     }
 }
예제 #4
0
 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.*');
     }
 }
예제 #5
0
 /**
  * @before _secure, _school
  */
 public function enrollments($classroom_id, $grade_id)
 {
     $classroom = \Classroom::first(array("id = ?" => $classroom_id), array("id", "organization_id", "grade_id", "educator_id"));
     if (!$classroom || $classroom->organization_id != $this->organization->id || $classroom->grade_id != $grade_id) {
         self::redirect("/school");
     }
     $this->setSEO(array("title" => "School | View students in section"));
     $view = $this->getActionView();
     $enrollments = \Enrollment::all(array("classroom_id = ?" => $classroom_id));
     $students = array();
     foreach ($enrollments as $e) {
         $student = \Scholar::first(array("id = ?" => $e->scholar_id), array("user_id", "dob", "parent_id"));
         $parent = \StudentParent::first(array("id = ?" => $student->parent_id), array("name", "relation"));
         $usr = \User::first(array("id = ?" => $student->user_id));
         $students[] = array("name" => $usr->name, "parent_name" => $parent->name, "parent_relation" => $parent->relation, "dob" => $student->dob, "username" => $usr->username);
     }
     $students = ArrayMethods::toObject($students);
     $view->set("students", $students);
 }
예제 #6
0
 public function save()
 {
     # Set rules for validation
     $rules = ['firstname' => 'required', 'lastname' => 'required', 'email' => 'required|email', 'location' => 'required', 'skills' => 'required', 'programme' => 'required', 'period' => 'required', 'certificate' => 'required', 'passport' => 'mimes:gif,jpg,jpeg,png,size:2000'];
     $validator = Validator::make(Input::all(), $rules);
     # Handle validation failure
     if ($validator->fails() or !Input::hasFile('passport')) {
         return View::make('error')->with(['message' => 'Please ensure to fulfil all requirements.']);
     }
     # Proceed on valid form data
     $email = Input::get('email');
     # Upload passport photograph
     $filename = '';
     $dest_path = '';
     $extension = Input::file('passport')->getClientOriginalExtension();
     $size = Input::file('passport')->getSize();
     $dest_path = storage_path() . '/passport/';
     $filename = $email . '.' . $extension;
     Input::file('passport')->move($dest_path, $filename);
     #Create new record or update existing one
     $student = Enrollment::firstOrCreate(['email' => $email]);
     if (!empty($student->first_name)) {
         $student = new Application();
         $student->email = $email;
     }
     $student->first_name = Input::get('firstname');
     $student->last_name = Input::get('lastname');
     $student->email = Input::get('email');
     $student->phone = Input::get('phone');
     $student->programme = Input::get('programme');
     $student->period = Input::get('period');
     $student->certificate = Input::get('certificate');
     $student->location = Input::get('location');
     $student->skills = Input::get('skills');
     $student->passport = $dest_path . $filename;
     $student->save();
     # Shoot email to chene academy
     Mail::send('emails.enrol', array(Input::all()), function ($message) {
         $message->to('*****@*****.**')->subject('Enrolment for ' . Input::get('programme') . '-' . Input::get('fullname'));
     });
     return View::make('thank_you')->with(['person' => 'Trainers']);
 }
예제 #7
0
 public function enrollments($classroom, $opts = array())
 {
     $enrollments = \Enrollment::all(array("classroom_id = ?" => $classroom->id), array("user_id"));
     $students = array();
     foreach ($enrollments as $e) {
         $usr = \User::first(array("id = ?" => $e->user_id), array("name", "username"));
         if (!isset($opts['only_user'])) {
             $scholar = \Scholar::first(array("user_id = ?" => $e->user_id), array("roll_no"));
         }
         $extra = $this->_extraFields($e, $opts);
         if (isset($opts['conversation'])) {
             $extra = array('username' => $usr->username, 'class' => $classroom->grade, 'section' => $classroom->section, 'display' => $usr->name . " (Class: " . $classroom->grade . " - " . $classroom->section . ") Roll No: " . $scholar->roll_no);
         }
         if (!isset($opts['only_user'])) {
             $data = array("user_id" => $e->user_id, "name" => $usr->name, "roll_no" => $scholar->roll_no);
         } else {
             $data = array("user_id" => $e->user_id);
         }
         $data = array_merge($data, $extra);
         $data = ArrayMethods::toObject($data);
         $students[] = $data;
     }
     return $students;
 }
예제 #8
0
 /**
  * @before _secure, _school
  */
 public function remove($user_id)
 {
     $this->noview();
     $sub = Registry::get("MongoDB")->submission;
     $scholar = Scholar::first(array("user_id = ?" => $user_id));
     if (!$scholar || $scholar->organization_id != $this->organization->id) {
         self::redirect("/404");
     }
     $user = User::first(array("id = ?" => $user_id));
     if (!$user) {
         self::redirect("/404");
     }
     $enrollment = Enrollment::first(array("user_id = ?" => $user->id));
     $submissions = $sub->find(array("user_id" => (int) $user->id));
     $examResults = ExamResult::all(array("user_id = ?" => $user->id));
     foreach ($examResults as $r) {
         // $r->delete();
     }
     foreach ($submissions as $s) {
         // $s->remove();
     }
     // $enrollment->delete();
     // $user->delete();
     // $scholar->delete();
     self::redirect($_SERVER['HTTP_REFERER']);
 }
예제 #9
0
 /**
  * unsave from my course list
  *
  * @param  string  $email
  * @return Response
  */
 public static function removeFromMyCourses($idCourse, $idUser)
 {
     $app = \Slim\Slim::getInstance();
     if (!User::find($idUser)) {
         $app->response->setStatus(400);
         return "User does not exist";
     }
     if (!Course::find($idCourse)) {
         $app->response->setStatus(400);
         return "Course does not exist";
     }
     if (Enrollment::where('user_id', $idUser)->where('course_id', $idCourse)->count()) {
         $app->response->setStatus(400);
         return "You already enrolled this course";
     }
     MyCourses::where('user_id', $idUser)->where('course_id', $idCourse)->delete();
     return "success";
 }
예제 #10
0
 private function _findStudents()
 {
     $session = Registry::get("session");
     if (RequestMethods::post("action") == "findStudents") {
         $exam = RequestMethods::post("exam");
         preg_match("/(.*);(.*)/", $exam, $matches);
         $exam_type = $matches[1];
         $exam_year = $matches[2];
         $classroom_id = RequestMethods::post("classroom_id");
         $grade_id = RequestMethods::post("grade");
         $enrollments = Enrollment::all(array("classroom_id = ?" => $classroom_id));
         $exams = Exam::all(array("grade_id = ?" => $grade_id, "type = ?" => $exam_type), array("id", "grade_id", "course_id"));
         $courses = Course::all(array("organization_id = ?" => $this->organization->id), array("title", "id"));
         $arr = array();
         foreach ($courses as $c) {
             $arr["{$c->id}"] = $c->title;
         }
         $courses = array();
         foreach ($exams as $e) {
             $courses[] = array("title" => $arr["{$e->course_id}"], "id" => $e->course_id);
         }
         $courses = ArrayMethods::toObject($courses);
         $session->set('Exams\\Result:$exams', $exams);
         $session->set('Exams\\Result:$grade_id', $grade_id);
         return array("courses" => $courses, "exams" => $exams, "enrollments" => $enrollments);
     }
     return false;
 }
예제 #11
0
 public function changepartstatus()
 {
     try {
         if (Check::digits($_POST['study_id'], $empty = false)) {
             $study_id = $_POST['study_id'];
         } else {
             throw new Exception("bad study id!");
         }
         if (Check::digits($_POST['participant_id'])) {
             $part_id = $_POST['participant_id'];
         } else {
             throw new Exception("bad participant id!");
         }
         $active = $_POST['active'] ? 1 : 0;
         $e = new Enrollment();
         if ($e->upd(array('participant_id' => $part_id, 'study_id' => $study_id), array('active' => $active)) === false) {
             throw new Exception($e->err());
         }
         View::assign('study_id', $study_id);
         return 'participants.tpl';
     } catch (Exception $e) {
         $this->err($e);
         View::assign('error', $this->error);
         return 'error.tpl';
     }
 }
 public function download_payment_document($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_matricularse', $data["actions"]) || in_array('side_aprobar_matriculas_online', $data["actions"])) {
             $enrollment = Enrollment::find($id);
             $path = $enrollment->doc_path . $enrollment->doc_name;
             $headers = array('Content-Type', mime_content_type($path));
             // Llamo a la función para registrar el log de auditoria
             $log_description = "Se descargó la boleta de la Matrícula con id {{$enrollment->id}}";
             Helpers::registerLog(9, $log_description);
             return Response::download($path, basename($enrollment->doc_title), $headers);
         } else {
             // Llamo a la función para registrar el log de auditoria
             $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
             Helpers::registrarLog(10, $descripcion_log);
             Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.');
             return Redirect::to('/dashboard');
         }
     } else {
         return View::make('error/error');
     }
 }
예제 #13
0
 public static function launchCourse($idCourse, $token, $page)
 {
     $app = \Slim\Slim::getInstance();
     if (!Course::find($idCourse)) {
         $app->halt("404");
     }
     $auth = Auth_Token::where('token', '=', $token)->first();
     if (!$auth || Enrollment::where('user_id', '=', $auth->user_id)->where('course_id', '=', $idCourse)->count() == 0) {
         $app->response->headers->set('Content-Type', 'text/html');
         $app->render('course_launch_401.php');
         $app->stop();
     }
     FileController::readCourse($idCourse, $page);
 }
 public static function download($idUser, $idCourse)
 {
     $app = \Slim\Slim::getInstance();
     if (!Course::find($idCourse)) {
         $app->response->setStatus(404);
         return json_encode("Course not found");
     }
     if (!Enrollment::where('user_id', '=', $idUser)->where('course_id', '=', $idCourse)->count()) {
         $app->response->setStatus(401);
         return json_encode("You have to enroll this course first.");
     }
     FileController::downloadCourse($idCourse);
 }