/** * @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); }
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; }
/** * @before _secure, _school */ public function manage() { $this->setSEO(array("title" => "School | Manage Students")); $view = $this->getActionView(); $session = Registry::get("session"); $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("title", "id")); if (RequestMethods::post("action") == "findStudents") { $classroom_id = RequestMethods::post("classroom_id"); $enrollment = \Enrollment::all(array("classroom_id = ?" => $classroom_id)); $students = array(); foreach ($enrollment as $e) { $s = Scholar::first(array("user_id = ?" => $e->user_id)); $students[] = $s; } } else { $students = \Scholar::all(array("organization_id = ?" => $this->organization->id), array("*"), "created", "desc", 30, 1); } $setGrades = array(); foreach ($grades as $g) { $setGrades["{$g->id}"] = $g->title; } $view->set("defGrades", $grades); $view->set("grades", $setGrades); $view->set("students", $students); }
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; }