/** * @before _secure, _student */ public function index() { $this->setSEO(array("title" => "Students | Dashboard")); $this->getLayoutView()->set("cal", true); $view = $this->getActionView(); $session = Registry::get("session"); $enrollment = Enrollment::first(array("user_id = ?" => $this->user->id)); $classroom = Classroom::first(array("id = ?" => $enrollment->classroom_id)); $grade = Grade::first(array("id = ?" => $classroom->grade_id)); $courses = StudentService::$_courses; $d = StringMethods::month_se(); // find average attendance for the month $service = new \Shared\Services\Attendance(); $attendances = $service->find($d['start'], $d['end']); $present = 0; $total = 0; foreach ($attendances as $a) { $total++; if ($a['title'] == "Present") { $present++; } } $avg = (string) ($present / $total * 100); // find total assignments $service = new \Shared\Services\Assignment(); $asmt = $service->total($classroom, $courses); $view->set("enrollment", $enrollment)->set("classroom", $classroom)->set("grade", $grade)->set("courses", $courses)->set("assignments", $asmt)->set("attendance", substr($avg, 0, 5)); }
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'); } }
protected static function _findClasses($teaches) { $class_ids = array(); foreach ($teaches as $t) { $class_ids[] = $t->classroom_id; } $class_ids = array_unique($class_ids); $classes = array(); foreach ($class_ids as $key => $value) { $k = \Classroom::first(array("id = ?" => $value)); $g = \Grade::first(array("id = ?" => $k->grade_id)); $data = array("id" => $k->id, "grade_id" => $g->id, "grade" => $g->title, "section" => $k->section, "year" => $k->year, "educator_id" => $k->educator_id); $classes[$k->id] = ArrayMethods::toObject($data); } return $classes; }
/** * @before _secure, _school */ public function edit($grade_id) { $this->setSEO(array("title" => "School | Edit Class")); $view = $this->getActionView(); $grade = \Grade::first(array("id = ?" => $grade_id)); if (!$grade || $grade->organization_id != $this->organization->id) { self::redirect("/school"); } if (RequestMethods::post("action") == "editGrade") { $grade->title = RequestMethods::post("title"); $grade->description = RequestMethods::post("description"); $grade->save(); $view->set("success", "Grade edited successfully!"); } $view->set("grade", $grade); }
/** * @before _secure, _school */ public function edit($subject_id, $grade_id) { $course = \Course::first(array("id = ?" => $subject_id)); if (!$course || $course->organization_id != $this->organization->id || $course->grade_id != $grade_id) { self::redirect("/school"); } $grade = \Grade::first(array("id = ?" => $grade_id), array("id", "title", "organization_id")); $this->setSEO(array("title" => "School | Manage Subjects (Courses)")); $view = $this->getActionView(); if (RequestMethods::post("action") == "editSubject") { $course->title = RequestMethods::post("title"); $course->description = RequestMethods::post("description"); $course->save(); $view->set("success", "Subject Updated successfully!!"); } $view->set("course", $course); $view->set("grade", $grade); }
/** * @before _secure, _teacher */ public function create($course_id, $classroom_id) { $teach = \Teach::first(array("course_id = ?" => $course_id, "user_id = ?" => $this->user->id)); if (!$teach || $teach->classroom_id != $classroom_id) { self::redirect("/teacher"); } $this->setSEO(array("title" => "Teacher | Create Assignments")); $view = $this->getActionView(); $grade = Grade::first(array("id = ?" => $teach->grade_id), array("title", "id")); $classroom = Classroom::first(array("id = ?" => $classroom_id), array("section", "id")); $view->set("grade", $grade); $view->set("classroom", $classroom); if (RequestMethods::post("action") == "assignment") { $headers = getallheaders(); $attachment = $this->_upload("attachment", "assignments"); $assignment = new \Assignment(array("title" => RequestMethods::post("title"), "description" => RequestMethods::post("description"), "deadline" => RequestMethods::post("deadline"), "user_id" => $this->user->id, "organization_id" => $this->organization->id, "classroom_id" => $classroom_id, "course_id" => $course_id, "attachment" => $attachment)); if (!$assignment->validate()) { $view->set("success", "Invalid Request"); return; } $assignment->save(); $view->set("success", "Assignment Created successfully!!"); } }
/** * @before _secure, _teacher */ public function manageAttendance() { $this->setSEO(array("title" => "Manage Your Courses | Teacher")); $view = $this->getActionView(); $classroom = Classroom::first(array("educator_id = ?" => $this->educator->id), array("id", "section", "grade_id")); $grade = Grade::first(array("id = ?" => $classroom->grade_id), array("title")); $service = new Shared\Services\Classroom(); $response = $service->saveAttendance($classroom); if (isset($response["success"])) { $view->set("message", "Attendance Saved successfully!!"); } elseif (isset($response["saved"])) { $view->set("message", "Attendance Already saved for today"); } $students = $service->enrollments($classroom, array('table' => 'attendance')); $view->set("class", $grade->title . " - " . $classroom->section); $view->set("students", $students); }
/** * @before _secure, _school */ public function edit($classroom_id, $grade_id) { $classroom = \Classroom::first(array("id = ?" => $classroom_id)); $grade = \Grade::first(array("id = ?" => $grade_id), array("id", "title", "organization_id")); if (!$classroom || $classroom->organization_id != $this->organization->id) { self::redirect("/school"); } if (!$grade || $classroom->grade_id != $grade->id || $grade->organization_id != $this->organization->id) { self::redirect("/school"); } $this->setSEO(array("title" => "Edit Section | School")); $view = $this->getActionView(); if (RequestMethods::post("action") == "editClassroom") { $classroom->year = RequestMethods::post("year"); $classroom->section = RequestMethods::post("section"); $classroom->remarks = RequestMethods::post("remarks"); $classroom->educator_id = RequestMethods::post("educator"); $classroom->save(); $view->set("success", "Grade section edited successfully!!"); } $teachers = \Educator::all(array("organization_id = ?" => $this->organization->id), array("user_id", "organization_id", "id")); $view->set("teachers", $teachers); $view->set("grade", $grade); $view->set("classroom", $classroom); }