/** * @before _secure, _student */ public function courses() { $this->setSEO(array("title" => "Result | Student")); $view = $this->getActionView(); $session = Registry::get("session"); $courses = StudentService::$_courses; $result = array(); $sub = Registry::get("MongoDB")->submission; foreach ($courses as $c) { $a = Assignment::count(array("course_id = ?" => $c->id)); $s = $sub->count(array("course_id" => (int) $c->id, "user_id" => (int) $this->user->id)); $data = array("_title" => $c->title, "_description" => $c->description, "_grade_id" => $c->grade_id, "_id" => $c->id, "_assignments" => $a, "_assignment_submitted" => $s); $data = ArrayMethods::toObject($data); $result[] = $data; } $view->set("courses", $result); }
/** * Find all the courses to which the teacher is assigned * @before _secure, _teacher */ public function courses() { $this->setSEO(array("title" => "Manage Your Courses | Teacher")); $view = $this->getActionView(); $teaches = \Teach::all(array("user_id = ?" => $this->user->id, "live = ?" => true)); $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title")); $storedGrades = array(); foreach ($grades as $g) { $storedGrades[$g->id] = $g; } $courses = TeacherService::$_courses; $classes = TeacherService::$_classes; $result = array(); foreach ($teaches as $t) { $grade = $storedGrades[$t->grade_id]; $class = $classes[$t->classroom_id]; $course = $courses[$t->course_id]; $asgmnt = \Assignment::count(array("course_id = ?" => $t->course_id)); $data = array("grade" => $grade->title, "grade_id" => $g->id, "section" => $class->section, "course" => $course->title, "course_id" => $course->id, "classroom_id" => $class->id, "assignments" => $asgmnt); $data = ArrayMethods::toObject($data); $result[] = $data; } $session = Registry::get("session"); if ($session->get('Notification\\Students:$sent')) { $view->set("success", "Notification sent to students"); $session->erase('Notification\\Students:$sent'); } $view->set("courses", $result); }