Ejemplo n.º 1
0
 /**
  * @before _secure, _teacher
  */
 public function manage($course_id = null)
 {
     $this->setSEO(array("title" => "Manage Your assignments | Teacher"));
     $view = $this->getActionView();
     $where = array("user_id = ?" => $this->user->id);
     $fields = array("title", "created", "course_id", "classroom_id", "deadline", "live", "id");
     $course_id = RequestMethods::post("course", $course_id);
     if ($course_id) {
         $assignments = \Assignment::all(array_merge($where, array("course_id = ?" => $course_id)), $fields);
     } else {
         $assignments = \Assignment::all($where, $fields);
     }
     $results = array();
     $grades = Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $storedGrades = array();
     foreach ($grades as $g) {
         $storedGrades[$g->id] = $g->title;
     }
     $courses = TeacherService::$_courses;
     $classrooms = array();
     $message = Registry::get("session")->get('$redirectMessage');
     if ($message) {
         $view->set("message", $message);
         Registry::get("session")->erase('$redirectMessage');
     }
     $notification = Registry::get("MongoDB")->notifications;
     foreach ($assignments as $a) {
         $course = $courses[$a->course_id];
         $grade = $storedGrades[$course->grade_id];
         if (!isset($classrooms[$a->classroom_id])) {
             $classroom = $classrooms[$a->classroom_id] = \Classroom::first(array("id = ?" => $a->classroom_id), array("section"));
         } else {
             $classroom = $classrooms[$a->classroom_id];
         }
         $record = $notification->findOne(array('sender' => 'user', 'sender_id' => (int) $this->user->id, 'type' => 'assignment', 'type_id' => (int) $a->id));
         if (isset($record)) {
             $notify = false;
         } else {
             $notify = true;
         }
         $data = array("id" => $a->id, "course" => $course->title, "title" => $a->title, "class" => $grade, "notified" => !$notify, "live" => $a->live, "section" => $classroom->section, "deadline" => $a->deadline, "created" => $a->created, "course_id" => $a->course_id, "classroom_id" => $a->classroom_id);
         $data = ArrayMethods::toObject($data);
         $results[] = $data;
     }
     $view->set("assignments", $results)->set("courses", $courses)->set("course_id", $course_id);
 }
Ejemplo n.º 2
0
 /**
  * @before _secure, _school
  */
 public function addToClass($user_id)
 {
     $usr = \User::first(array("id = ?" => $user_id), array("id"));
     if (!$usr) {
         self::redirect("/school");
     }
     $this->setSEO(array("title" => "Parent Info | Student | School"));
     $view = $this->getActionView();
     $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $enrollment = Enrollment::first(array("user_id = ?" => $user_id));
     if ($enrollment) {
         $view->set("success", "Student has already been added! Response will be updated");
     }
     if (RequestMethods::post("action") == "addToClass") {
         $classroom = Markup::checkValue(RequestMethods::post("classroom"));
         if (!$enrollment) {
             $enrollment = new Enrollment(array());
         }
         $enrollment->user_id = $usr->id;
         $enrollment->classroom_id = $classroom;
         $enrollment->organization_id = $this->organization->id;
         if ($enrollment->validate()) {
             $enrollment->save();
             $view->set("success", "Student successfully added to classroom");
         }
     }
     if ($enrollment) {
         $class = Classroom::first(array("id = ?" => $enrollment->classroom_id), array("id", "grade_id", "section"));
         foreach ($grades as $g) {
             if ($g->id == $class->grade_id) {
                 $grade = $g->id;
                 break;
             }
         }
         $view->set("class", $class);
     }
     if (!isset($grade)) {
         $grade = null;
     }
     $view->set("grade", $grade);
     $view->set("enrollment", $enrollment);
     $view->set("grades", $grades);
 }
Ejemplo n.º 3
0
 /**
  * @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);
 }
Ejemplo n.º 4
0
 /**
  * @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);
 }