/** * @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!!"); } }
if ($cmd == 'exRmAssig') { $assignment->delete(); //notify eventmanager $eventNotifier->notifyCourseEvent('work_deleted', claro_get_current_course_id(), claro_get_current_tool_id(), $assigId, claro_get_current_group_id(), '0'); $dialogBox->success(get_lang('Assignment deleted')); } /*-------------------------------------------------------------------- MODIFY AN ASSIGNMENT --------------------------------------------------------------------*/ /*----------------------------------- STEP 2 : check & query -------------------------------------*/ // edit an assignment / form has been sent if ($cmd == 'exEditAssig') { // check validity of the data if (!is_null($assigId) && $assignment->validate()) { $assignment->save(); $eventNotifier->notifyCourseEvent('work_updated', claro_get_current_course_id(), claro_get_current_tool_id(), $assigId, claro_get_current_group_id(), '0'); $dialogBox->success(get_lang('Assignment modified')); } else { if (claro_failure::get_last_failure() == 'assignment_no_title') { $dialogBox->error(get_lang('Assignment title required')); } if (claro_failure::get_last_failure() == 'assignment_title_already_exists') { $dialogBox->error(get_lang('Assignment title already exists')); } if (claro_failure::get_last_failure() == 'assignment_incorrect_dates') { $dialogBox->error(get_lang('Start date must be before end date ...')); } $cmd = 'rqEditAssig'; }