/** * Define this form - called by the parent constructor */ public function definition() { $sphereLib = new setask_sphere(); $compilers = $sphereLib->sphereGetCompilers(); //to be improved (maybe... - probably no need to rewrite here) # var_dump($compilers); $mform = $this->_form; list($setask, $data) = $this->_customdata; $mform->addElement('select', 'compiler', 'Compilers: ', $compilers); $setask->add_submission_form_elements($mform, $data); $this->add_action_buttons(true, get_string('savechanges', 'setask')); if ($data) { //ugly (but working) way of extracting data from text editor foreach ($data as $tes) { $ii = 0; foreach ($tes as $tes2) { if ($ii == 0) { $textToSend = $tes2; } //text from online editor - ugly way but it works... # var_dump($textToSend); $ii++; } } //extracting selected compiler $selectedItem =& $mform->getElement('compiler')->getSelected(); # var_dump($selectedItem); $this->set_data($data); } }
/** * Called to define this moodle form * * @return void */ public function definition() { global $CFG, $COURSE, $DB, $PAGE; $sphereLib; $mform = $this->_form; $sphereLib = new setask_sphere(); #here we get a list of problems from sphere engine $problems = $sphereLib->getProblemsToForm(); //sphereGetProblems(); #$sphereLib->getProblemsToForm();//s #var_dump($problems); $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('select', 'problem', 'Problem: ', $problems); $mform->addElement('text', 'name', get_string('setaskmentname', 'setask'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->standard_intro_elements(get_string('description', 'setask')); $mform->addElement('filemanager', 'introattachments', get_string('introattachments', 'setask'), null, array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes)); $mform->addHelpButton('introattachments', 'introattachments', 'setask'); $ctx = null; if ($this->current && $this->current->coursemodule) { $cm = get_coursemodule_from_instance('setask', $this->current->id, 0, false, MUST_EXIST); $ctx = context_module::instance($cm->id); } $setaskment = new setask($ctx, null, null); if ($this->current && $this->current->course) { if (!$ctx) { $ctx = context_course::instance($this->current->course); } $course = $DB->get_record('course', array('id' => $this->current->course), '*', MUST_EXIST); $setaskment->set_course($course); } $config = get_config('setask'); $mform->addElement('header', 'availability', get_string('availability', 'setask')); $mform->setExpanded('availability', true); $name = get_string('allowsubmissionsfromdate', 'setask'); $options = array('optional' => true); $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options); $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'setask'); $name = get_string('duedate', 'setask'); $mform->addElement('date_time_selector', 'duedate', $name, array('optional' => true)); $mform->addHelpButton('duedate', 'duedate', 'setask'); $name = get_string('cutoffdate', 'setask'); $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional' => true)); $mform->addHelpButton('cutoffdate', 'cutoffdate', 'setask'); $name = get_string('alwaysshowdescription', 'setask'); $mform->addElement('checkbox', 'alwaysshowdescription', $name); $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'setask'); $mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked'); $setaskment->add_all_plugin_settings($mform); $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'setask')); $name = get_string('submissiondrafts', 'setask'); $mform->addElement('selectyesno', 'submissiondrafts', $name); $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'setask'); $name = get_string('requiresubmissionstatement', 'setask'); $mform->addElement('selectyesno', 'requiresubmissionstatement', $name); $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'setask'); $mform->setType('requiresubmissionstatement', PARAM_BOOL); $options = array(ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_setask'), ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_setask'), ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_setask')); $mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_setask'), $options); $mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_setask'); $options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_setask')); $options += array_combine(range(1, 30), range(1, 30)); $mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_setask'), $options); $mform->addHelpButton('maxattempts', 'maxattempts', 'setask'); $mform->disabledIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE); $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'setask')); $name = get_string('teamsubmission', 'setask'); $mform->addElement('selectyesno', 'teamsubmission', $name); $mform->addHelpButton('teamsubmission', 'teamsubmission', 'setask'); if ($setaskment->has_submissions_or_grades()) { $mform->freeze('teamsubmission'); } $name = get_string('preventsubmissionnotingroup', 'setask'); $mform->addElement('selectyesno', 'preventsubmissionnotingroup', $name); $mform->addHelpButton('preventsubmissionnotingroup', 'preventsubmissionnotingroup', 'setask'); $mform->setType('preventsubmissionnotingroup', PARAM_BOOL); $mform->disabledIf('preventsubmissionnotingroup', 'teamsubmission', 'eq', 0); $name = get_string('requireallteammemberssubmit', 'setask'); $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name); $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'setask'); $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0); $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0); $groupings = groups_get_all_groupings($setaskment->get_course()->id); $options = array(); $options[0] = get_string('none'); foreach ($groupings as $grouping) { $options[$grouping->id] = $grouping->name; } $name = get_string('teamsubmissiongroupingid', 'setask'); $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options); $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'setask'); $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0); if ($setaskment->has_submissions_or_grades()) { $mform->freeze('teamsubmissiongroupingid'); } $mform->addElement('header', 'notifications', get_string('notifications', 'setask')); $name = get_string('sendnotifications', 'setask'); $mform->addElement('selectyesno', 'sendnotifications', $name); $mform->addHelpButton('sendnotifications', 'sendnotifications', 'setask'); $name = get_string('sendlatenotifications', 'setask'); $mform->addElement('selectyesno', 'sendlatenotifications', $name); $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'setask'); $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1); $name = get_string('sendstudentnotificationsdefault', 'setask'); $mform->addElement('selectyesno', 'sendstudentnotifications', $name); $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'setask'); // Plagiarism enabling form. if (!empty($CFG->enableplagiarism)) { require_once $CFG->libdir . '/plagiarismlib.php'; plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_setask'); } $this->standard_grading_coursemodule_elements(); $name = get_string('blindmarking', 'setask'); $mform->addElement('selectyesno', 'blindmarking', $name); $mform->addHelpButton('blindmarking', 'blindmarking', 'setask'); if ($setaskment->has_submissions_or_grades()) { $mform->freeze('blindmarking'); } $name = get_string('markingworkflow', 'setask'); $mform->addElement('selectyesno', 'markingworkflow', $name); $mform->addHelpButton('markingworkflow', 'markingworkflow', 'setask'); $name = get_string('markingallocation', 'setask'); $mform->addElement('selectyesno', 'markingallocation', $name); $mform->addHelpButton('markingallocation', 'markingallocation', 'setask'); $mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0); $this->standard_coursemodule_elements(); $this->apply_admin_defaults(); $this->add_action_buttons(); // Add warning popup/noscript tag, if grades are changed by user. $hasgrade = false; if (!empty($this->_instance)) { $hasgrade = $DB->record_exists_select('setask_grades', 'setaskment = ? AND grade <> -1', array($this->_instance)); } if ($mform->elementExists('grade') && $hasgrade) { $module = array('name' => 'mod_setask', 'fullpath' => '/mod/setask/module.js', 'requires' => array('node', 'event'), 'strings' => array(array('changegradewarning', 'mod_setask'))); $PAGE->requires->js_init_call('M.mod_setask.init_grade_change', null, false, $module); // Add noscript tag in case. $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_setask'))); $mform->insertElementBefore($noscriptwarning, 'grade'); } }
/** * Update this instance in the database. * * @param stdClass $formdata - the data submitted from the form * @return bool false if an error occurs */ public function update_instance($formdata) { global $DB; $adminconfig = $this->get_admin_config(); $update = new stdClass(); $update->id = $formdata->instance; $update->name = $formdata->name; $update->timemodified = time(); $update->course = $formdata->course; $update->intro = $formdata->intro; $update->introformat = $formdata->introformat; $update->alwaysshowdescription = !empty($formdata->alwaysshowdescription); $update->submissiondrafts = $formdata->submissiondrafts; $update->requiresubmissionstatement = $formdata->requiresubmissionstatement; $update->sendnotifications = $formdata->sendnotifications; $update->sendlatenotifications = $formdata->sendlatenotifications; $update->sendstudentnotifications = $adminconfig->sendstudentnotifications; if (isset($formdata->sendstudentnotifications)) { $update->sendstudentnotifications = $formdata->sendstudentnotifications; } $update->duedate = $formdata->duedate; $update->cutoffdate = $formdata->cutoffdate; $update->allowsubmissionsfromdate = $formdata->allowsubmissionsfromdate; $update->grade = $formdata->grade; if (!empty($formdata->completionunlocked)) { $update->completionsubmit = !empty($formdata->completionsubmit); } $update->teamsubmission = $formdata->teamsubmission; $update->requireallteammemberssubmit = $formdata->requireallteammemberssubmit; if (isset($formdata->teamsubmissiongroupingid)) { $update->teamsubmissiongroupingid = $formdata->teamsubmissiongroupingid; } $update->blindmarking = $formdata->blindmarking; $update->attemptreopenmethod = ASSIGN_ATTEMPT_REOPEN_METHOD_NONE; if (!empty($formdata->attemptreopenmethod)) { $update->attemptreopenmethod = $formdata->attemptreopenmethod; } if (!empty($formdata->maxattempts)) { $update->maxattempts = $formdata->maxattempts; } if (isset($formdata->preventsubmissionnotingroup)) { $update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup; } $update->markingworkflow = $formdata->markingworkflow; $update->markingallocation = $formdata->markingallocation; if (empty($update->markingworkflow)) { // If marking workflow is disabled, make sure allocation is disabled. $update->markingallocation = 0; } $result = $DB->update_record('setask', $update); $this->instance = $DB->get_record('setask', array('id' => $update->id), '*', MUST_EXIST); $this->save_intro_draft_files($formdata); // Load the setaskment so the plugins have access to it. // Call save_settings hook for submission plugins. foreach ($this->submissionplugins as $plugin) { if (!$this->update_plugin_instance($plugin, $formdata)) { print_error($plugin->get_error()); return false; } } foreach ($this->feedbackplugins as $plugin) { if (!$this->update_plugin_instance($plugin, $formdata)) { print_error($plugin->get_error()); return false; } } $this->update_calendar($this->get_course_module()->id); $this->update_gradebook(false, $this->get_course_module()->id); $update = new stdClass(); $update->id = $this->get_instance()->id; $update->nosubmissions = !$this->is_any_submission_plugin_enabled() ? 1 : 0; $DB->update_record('setask', $update); $problemId = $formdata->problem; $sphereLib = new setask_sphere(); $sphereLib->sphereAddInstance($returnid, $problemId); return $result; }