/** * Assign which course will the teacher will teach * @before _secure, _school */ public function assign($user_id) { $usr = \User::first(array("id = ?" => $user_id), array("id")); if (!$usr) { self::redirect("/school"); } $this->setSEO(array("title" => "Assign Teachers for different subjects")); $view = $this->getActionView(); $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title")); $view->set("grades", $grades); if (RequestMethods::post("action") == "assignTeacher") { $teaches = $this->reArray($_POST); foreach ($teaches as $t) { if (!empty($t["section"]) || !empty($t["course"])) { continue; } $teach = new \Teach(array("grade_id" => $t["grade"], "classroom_id" => $t["section"], "course_id" => $t["course"], "user_id" => $usr->id, "organization_id" => $this->organization->id)); if ($teach->validate()) { $teach->save(); } } $view->set("success", "Subjects assigned!!"); } $teaches = Teach::all(array("user_id = ?" => $usr->id, "live = ?" => true)); $view->set("teaches", $teaches); }