Пример #1
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);
 }
Пример #2
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']);
 }
Пример #3
0
 public function results($course)
 {
     $exams = \Exam::all(array("course_id = ?" => $course->id), array("year", "type", "id"));
     $result = array();
     foreach ($exams as $e) {
         $whole_class = \ExamResult::all(array("exam_id = ?" => $e->id), array("marks", "user_id"));
         $total = 0;
         $highest = -1;
         $count = 0;
         $user_marks = 0;
         foreach ($whole_class as $w_c) {
             $total += $w_c->marks;
             if ((int) $w_c->marks > $highest) {
                 $highest = (int) $w_c->marks;
             }
             if ($w_c->user_id == self::$_student->user_id) {
                 $user_marks = (int) $w_c->marks;
             }
             ++$count;
         }
         $data = array("type" => $e->type, "year" => $e->year, "exam_id" => $e->id, "marks" => $user_marks, "highest" => $highest, "average" => $total / $count);
         $data = ArrayMethods::toObject($data);
         $result[] = $data;
     }
     return $result;
 }