Exemplo n.º 1
0
 protected function _checkLogin()
 {
     if (RequestMethods::post("action") == "logmein") {
         $username = RequestMethods::post("username");
         $password = RequestMethods::post("password");
         $user = User::first(array("username = ?" => $username, "live = ?" => true));
         if (!$user) {
             return array("error" => "Invalid username/password");
         }
         if (!Markup::checkHash($password, $user->password)) {
             return array("error" => "Invalid username/password");
         }
         $session = Registry::get("session");
         $this->setUser($user);
         if ($user->admin) {
             self::redirect("/admin");
         }
         $headers = getallheaders();
         $scholar = Scholar::first(array("user_id = ?" => $user->id));
         if ($scholar) {
             $session->set('scholar', $scholar);
             $organization = Organization::first(array("id = ?" => $scholar->organization_id));
             $session->set('organization', $organization);
             if (isset($headers["X-Student-App"])) {
                 $meta = $this->_meta($user, "student");
                 return array("success" => true, "meta" => $meta, "scholar" => $scholar);
             } else {
                 self::redirect("/student");
             }
         }
         $organization = Organization::first(array("user_id = ?" => $user->id));
         if ($organization) {
             $session->set('organization', $organization);
             self::redirect("/school");
         }
         $educator = Educator::first(array("user_id = ?" => $user->id));
         if ($educator) {
             $session->set('educator', $educator);
             $organization = Organization::first(array("id = ?" => $educator->organization_id));
             $session->set('organization', $organization);
             if (isset($headers["X-Teacher-App"])) {
                 $meta = $this->_meta($user, "teacher");
                 return array("success" => true, "meta" => $meta, "educator" => $educator);
             } else {
                 self::redirect("/teacher");
             }
         }
         return array("error" => "Something went wrong please try again later");
     } else {
         return array("error" => "Invalid Request");
     }
 }
Exemplo n.º 2
0
 /**
  * @before _secure, _school
  */
 public function index()
 {
     $this->setSEO(array("title" => "Admin | School | Dashboard"));
     $view = $this->getActionView();
     $counts = array();
     $counts["students"] = Scholar::count(array("organization_id = ?" => $this->organization->id));
     $counts["teachers"] = Educator::count(array("organization_id = ?" => $this->organization->id));
     $counts["classes"] = Grade::count(array("organization_id = ?" => $this->organization->id));
     $counts = ArrayMethods::toObject($counts);
     $session = Registry::get("session");
     $message = $session->get("redirectMessage");
     if ($message) {
         $view->set("message", $message);
         $session->erase("redirectMessage");
     }
     $view->set("counts", $counts);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /**
  * @before _secure, _school
  */
 public function edit($user_id)
 {
     $this->setSEO(array("title" => "Edit Student Info | School"));
     $view = $this->getActionView();
     $user = User::first(array("id = ?" => $user_id));
     $scholar = Scholar::first(array("user_id = ?" => $user->id));
     if (!$scholar || $scholar->organization_id != $this->organization->id) {
         self::redirect("/404");
     }
     $location = Location::first(array("user_id = ?" => $user->id));
     if (RequestMethods::post("action") == "updateInfo") {
         $user->name = RequestMethods::post("name");
         $user->email = RequestMethods::post("email");
         $user->phone = RequestMethods::post("phone");
         $user->save();
         $location->address = RequestMethods::post("address");
         $location->city = RequestMethods::post("city");
         if ($location->validate()) {
             $location->save();
         }
         $scholar->dob = RequestMethods::post("dob");
         $scholar->roll_no = RequestMethods::post("roll_no");
         if ($scholar->validate()) {
             $scholar->save();
         }
         $view->set("success", "Saved successfully!!");
     }
     $view->set("usr", $user);
     $view->set("scholar", $scholar);
     $view->set("location", $location);
 }
Exemplo n.º 6
0
 /**
  * @before _secure, _school
  */
 public function marks()
 {
     $this->setSEO(array("title" => "View Marks | School"));
     $view = $this->getActionView();
     $session = Registry::get("session");
     $view->set("results", array());
     $grades = Grade::all(array("organization_id = ?" => $this->organization->id));
     if (RequestMethods::post("action") == "findStudents") {
         $exam = RequestMethods::post("exam");
         preg_match("/(.*);(.*)/", $exam, $matches);
         $exam_type = $matches[1];
         $exam_year = $matches[2];
         $grade = RequestMethods::post("grade");
         $classroom_id = RequestMethods::post("classroom_id");
         /*** Stores courses in an array ***/
         $courses = Course::all(array("grade_id = ?" => $grade), array("id", "title"));
         $setCourses = array();
         foreach ($courses as $c) {
             $setCourses["{$c->id}"] = $c->title;
         }
         /*** Store exams in an array ***/
         $exams = Exam::all(array("type = ?" => $exam_type, "grade_id = ?" => $grade));
         foreach ($exams as $e) {
             $setExams["{$e->id}"] = array("course_id" => $e->course_id);
         }
         /*** Find all students in class and store his details in an array ***/
         $users = Enrollment::all(array("classroom_id = ?" => $classroom_id));
         $results = array();
         foreach ($users as $u) {
             $usr = User::first(array("id = ?" => $u->user_id), array("name"));
             $scholar = Scholar::first(array("user_id = ?" => $u->user_id), array("roll_no"));
             $result = ExamResult::all(array("user_id = ?" => $u->user_id));
             /*** We need to find marks of the all the subject ***/
             $marks = array();
             foreach ($result as $r) {
                 if (!array_key_exists($r->exam_id, $setExams)) {
                     continue;
                 }
                 $c_id = $setExams["{$r->exam_id}"]["course_id"];
                 $marks[] = array("subject" => $setCourses["{$c_id}"], "marks" => $r->marks);
             }
             $results[] = array("name" => $usr->name, "user_id" => $u->user_id, "roll_no" => $scholar->roll_no, "results" => $marks);
         }
         $session->set('Exams\\Marks:$exam', array("type" => $exam_type, "year" => $exam_year, "grade_id" => $grade));
         $session->set('Exams\\Marks:$marks', ArrayMethods::toObject($marks));
         $session->set('Exams\\Marks:$results', ArrayMethods::toObject($results));
     }
     $view->set('exam', $session->get('Exams\\Marks:$exam'))->set("marks", $session->get('Exams\\Marks:$marks'))->set("results", $session->get('Exams\\Marks:$results'))->set("grades", $grades);
 }
Exemplo n.º 7
0
 /**
  * @before _secure, _teacher
  */
 public function submissions($assgmt_id)
 {
     $assignment = \Assignment::first(array("id = ?" => $assgmt_id));
     if (!$assignment || $assignment->user_id != $this->user->id) {
         self::redirect("/404");
     }
     $this->setSEO(array("title" => "View Assignment Submissions | Teacher"));
     $view = $this->getActionView();
     $classroom = TeacherService::$_classes[$assignment->classroom_id];
     $sub = Registry::get("MongoDB")->submission;
     $find = $sub->find(array('assignment_id' => (int) $assgmt_id));
     $submissions = array();
     foreach ($find as $f) {
         $usr = \User::first(array("id = ?" => $f['user_id']), array("name"));
         $student = \Scholar::first(array("user_id = ?" => $f['user_id']), array("roll_no"));
         $submissions[] = array("student" => $usr->name, "student_roll_no" => $student->roll_no, "response" => $f['response'], "live" => $f['live'], "submitted_on" => date('Y-m-d H:i:s', $f['created']->sec));
     }
     $submissions = ArrayMethods::toObject($submissions);
     $view->set("class", $klass);
     $view->set("submissions", $submissions);
     $view->set("assignment", $assignment);
 }