/** * @before _secure, _school */ public function add() { $this->setSEO(array("title" => "School | Add Grades")); $view = $this->getActionView(); if (RequestMethods::post("action") == "addGrades") { $title = RequestMethods::post("title"); $description = RequestMethods::post("description"); foreach ($title as $key => $value) { $grade = new \Grade(array("title" => Markup::checkValue($value), "description" => Markup::checkValue($description[$key]), "organization_id" => $this->organization->id)); $grade->save(); } $view->set("success", 'Classes added successfully! See <a href="/grades/manage">Manage Classes</a>'); } }
/** * @before _secure, _school */ public function create() { $this->setSEO(array("title" => "Create Exam | School")); $view = $this->getActionView(); $grades = Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title")); if (RequestMethods::post("action") == "createExam") { $exams = $this->reArray($_POST); foreach ($exams as $e) { $course = $e["course"]; if (Markup::checkValue($course)) { $exam = new Exam(array("grade_id" => $e["grade"], "course_id" => $course, "user_id" => $this->user->id, "organization_id" => $this->organization->id, "type" => $e["type"], "start_date" => $e["start_date"], "start_time" => $e["start_time"] . ":00", "end_time" => $e["end_time"] . ":00")); $exam->save(); } } $view->set("success", "Exams created successfully!!"); } $view->set("grades", $grades); }
/** * @before _secure, _school */ public function add($grade_id) { $grade = \Grade::first(array("id = ?" => $grade_id), array("title", "id", "organization_id")); if (!$grade || $grade->organization_id != $this->organization->id) { self::redirect("/school"); } $this->setSEO(array("title" => "Add Courses | School")); $view = $this->getActionView(); if (RequestMethods::post("action") == "addCourses") { $title = RequestMethods::post("title"); $description = RequestMethods::post("description"); foreach ($title as $key => $value) { $subject_title = Markup::checkValue($value); if ($subject_title) { $course = new \Course(array("title" => Markup::checkValue($value), "description" => Markup::checkValue($description[$key]), "grade_id" => $grade_id, "user_id" => $this->user->id, "organization_id" => $this->organization->id)); $course->save(); } } $view->set("success", 'Courses added successfully! <a href="/subject/manage/' . $grade_id . '">Manage Courses</a>'); } $view->set("grade", $grade); }
/** * @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); }
/** * Creates new Users with unique username * @return null|object */ protected function _createUser($opts) { $name = $opts["name"]; $email = $opts["email"]; $phone = $opts["phone"]; $last = \User::first(array(), array("id"), "created", "desc"); $id = (int) $last->id + 1; $prefix = strtolower(array_shift(explode(" ", $this->organization->name))); if (Markup::checkValue($email)) { $found = \User::first(array("email = ?" => $email), array("id")); if ($found) { throw new \Exception("Email already exists"); } } if (Markup::checkValue($phone)) { $found = \User::first(array("phone = ?" => $phone), array("id")); if ($found) { throw new \Exception("Phone number already exists"); } } if (empty(Markup::checkValue($name))) { return NULL; // throw new \Exception("Please provide a name"); } $user = new \User(array("name" => $name, "email" => $email, "phone" => $phone, "username" => $prefix . "_" . $id, "password" => Markup::encrypt("password"))); $user->save(); return $user; }