From 436cfa9fb36267d990c7c56018c17febc5161dd5 Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 10 Jan 2007 13:38:04 +0000 Subject: [PATCH] MDL-6987 assignment mod conversion to new forms lib --- course/mod.php | 7 +- mod/assignment/lib.php | 4 + mod/assignment/mod.html | 179 ------------------ mod/assignment/mod_form.php | 67 +++++++ mod/assignment/type/offline/mod.html | 3 - .../type/online/assignment.class.php | 19 ++ mod/assignment/type/online/mod.html | 54 ------ .../type/upload/assignment.class.php | 38 ++++ mod/assignment/type/upload/mod.html | 97 ---------- .../type/uploadsingle/assignment.class.php | 18 ++ mod/assignment/type/uploadsingle/mod.html | 52 ----- 11 files changed, 150 insertions(+), 388 deletions(-) delete mode 100644 mod/assignment/mod.html create mode 100644 mod/assignment/mod_form.php delete mode 100644 mod/assignment/type/offline/mod.html delete mode 100644 mod/assignment/type/online/mod.html delete mode 100644 mod/assignment/type/upload/mod.html delete mode 100644 mod/assignment/type/uploadsingle/mod.html diff --git a/course/mod.php b/course/mod.php index 78134941bf..dc1bc67313 100644 --- a/course/mod.php +++ b/course/mod.php @@ -45,11 +45,12 @@ if (!empty($add)){ $modname=$add; if (file_exists("../mod/$modname/mod_form.php")) { - $id = required_param('id', PARAM_INT); - $section = required_param('section', PARAM_INT); + $id = required_param('id', PARAM_INT); + $section = required_param('section', PARAM_INT); + $type = optional_param('type', '', PARAM_ALPHA); $returntomod = optional_param('return', 0, PARAM_BOOL); - redirect("modedit.php?add=$add&course=$id§ion=$section&return=$returntomod"); + redirect("modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod"); } }elseif (!empty($update)){ if (!$modname=get_field_sql("SELECT md.name diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 72f1836801..1426f8913a 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -311,6 +311,10 @@ class assignment_base { } + function setup_elements(&$mform) { + + } + /** * Print the setup form for the current assignment type * diff --git a/mod/assignment/mod.html b/mod/assignment/mod.html deleted file mode 100644 index a4a3b0f125..0000000000 --- a/mod/assignment/mod.html +++ /dev/null @@ -1,179 +0,0 @@ -dirroot/mod/assignment/lib.php"); - - if (empty($form->name)) { - $form->name = ""; - } - if (empty($form->description)) { - $form->description = ""; - } - if (empty($form->format)) { - $form->format = ""; - } - if (empty($form->assignmenttype)) { - $form->assignmenttype = "uploadsingle"; - } - if (!isset($form->grade)) { - $form->grade = 100; - } - if (!isset($form->timedue)) { - $form->timedue = time()+7*24*3600; - } - if (!isset($form->timeavailable)) { - $form->timeavailable = time(); - } - if (!isset($form->preventlate)) { - $form->preventlate = 0; - } - if (empty($form->maxbytes)) { - $form->maxbytes = $CFG->assignment_maxbytes; - } - -?> - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: - -
: -

- "; - helpbutton("questions", get_string("helpquestions"), "moodle", true, true); - echo "
"; - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle", true, true); - } else { - emoticonhelpbutton("form", "description"); - } - ?> -
- description); - - if ($usehtmleditor) { - echo ''; - } else { - echo '
'; - helpbutton("textformat", get_string("formattexttype")); - print_string("formattexttype"); - echo ': '; - if (!$form->format) { - $form->format = $defaultformat; - } - choose_from_menu(format_text_menu(), "format", $form->format, ""); - echo '
'; - } - ?> -
: - id, "grade", "$form->grade"); - ?> -
: - timeavailable) echo 'checked="checked"' ?> /> - timeavailable); - echo " - "; - print_time_selector("availablehour", "availableminute", $form->timeavailable); - ?> - - - - - -
: - timedue) echo 'checked="checked"' ?> /> - timedue); - echo " - "; - print_time_selector("duehour", "dueminute", $form->timedue); - ?> - - - - - -
 : - preventlate, ''); - ?> - -
 
: - assignmenttype, ''); - helpbutton('types', get_string('assignmenttype', 'assignment'), 'assignment'); - ?> -
-
-
-$assname)) { - echo ''."\n"; - } - } -?> - - -
-
- - - diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php new file mode 100644 index 0000000000..f6b90ef6d1 --- /dev/null +++ b/mod/assignment/mod_form.php @@ -0,0 +1,67 @@ +_form; + + // this hack is needed for different settings of each subtype + if (!empty($this->_instance)) { + if($ass = get_record('assignment', 'id', (int)$this->_instance)) { + $type = $ass->assignmenttype; + } else { + error('incorrect assignment'); + } + } else { + $type = required_param('type', PARAM_ALPHA); + } + $mform->addElement('hidden', 'assignmenttype', $type); + $mform->setDefault('assignmenttype', $type); + $mform->addElement('hidden', 'type', $type); + $mform->setDefault('type', $type); + + require($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php'); + $assignmentclass = 'assignment_'.$type; + $assignmentinstance = new $assignmentclass(); + +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('general', 'form')); + +// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment')); + + $mform->addElement('text', 'name', get_string('chatname', 'chat')); + $mform->setType('name', PARAM_TEXT); + $mform->addRule('name', null, 'required', null, 'client'); + + $mform->addElement('htmleditor', 'description', get_string('chatintro', 'chat')); + $mform->setType('description', PARAM_RAW); + $mform->setHelpButton('description', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton'); + $mform->addRule('description', get_string('required'), 'required', null, 'client'); + + $mform->addElement('modgrade', 'grade', get_string('grade')); + $mform->setDefault('grade', 100); + + $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional'=>true)); + $mform->setDefault('timeavailable', time()); + $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional'=>true)); + $mform->setDefault('timedue', time()+7*24*3600); + + $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + + $mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions); + $mform->setDefault('preventlate', 0); + + $mform->addElement('header', 'typedesc', get_string('type'.$type,'assignment')); + $assignmentinstance->setup_elements($mform); + + $this->standard_coursemodule_elements(); + + $this->add_action_buttons(); + } + + + +} +?> \ No newline at end of file diff --git a/mod/assignment/type/offline/mod.html b/mod/assignment/type/offline/mod.html deleted file mode 100644 index 375ca2f668..0000000000 --- a/mod/assignment/type/offline/mod.html +++ /dev/null @@ -1,3 +0,0 @@ -
-" /> -
diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index 336db2847f..fecda89464 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -238,6 +238,25 @@ class assignment_online extends assignment_base { } } + function setup_elements(&$mform) { + global $CFG, $COURSE; + + $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + + $mform->addElement('select', 'resubmit', get_string("allowresubmit", "assignment"), $ynoptions); + $mform->setHelpButton('resubmit', array('resubmit', get_string('allowresubmit', 'assignment'), 'assignment')); + $mform->setDefault('resubmit', 0); + + $mform->addElement('select', 'emailteachers', get_string("emailteachers", "assignment"), $ynoptions); + $mform->setHelpButton('emailteachers', array('emailteachers', get_string('emailteachers', 'assignment'), 'assignment')); + $mform->setDefault('emailteachers', 0); + + $mform->addElement('select', 'var1', get_string("commentinline", "assignment"), $ynoptions); + $mform->setHelpButton('var1', array('commentinline', get_string('commentinline', 'assignment'), 'assignment')); + $mform->setDefault('var1', 0); + + } + } class mod_assignment_online_edit_form extends moodleform { diff --git a/mod/assignment/type/online/mod.html b/mod/assignment/type/online/mod.html deleted file mode 100644 index 1f7a0d1508..0000000000 --- a/mod/assignment/type/online/mod.html +++ /dev/null @@ -1,54 +0,0 @@ -resubmit)) { - $form->resubmit = 1; - } - if (empty($form->emailteachers)) { - $form->emailteachers = 0; - } - if (empty($form->var1)) { - $form->var1 = 0; - } -?> - - - - - - - - - - - - - - - - - - - -
: - resubmit, ""); - helpbutton("resubmit", get_string("allowresubmit", "assignment"), "assignment"); - ?> -
: - emailteachers, ""); - helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment"); - ?> -
: - var1, ""); - helpbutton("commentinline", get_string("commentinline", "assignment"), "assignment"); - ?> -
- -
-
-" /> -
diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index fdf94a3038..bc2925a105 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -913,6 +913,44 @@ class assignment_upload extends assignment_base { return 0; } + function setup_elements(&$mform) { + global $CFG, $COURSE; + + $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + + $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); + $choices[1] = get_string('uploadnotallowed'); + $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; + $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices); + $mform->setDefault('maxbytes', $CFG->assignment_maxbytes); + + $mform->addElement('select', 'resubmit', get_string("allowdeleting", "assignment"), $ynoptions); + $mform->setHelpButton('resubmit', array('allowdeleting', get_string('allowdeleting', 'assignment'), 'assignment')); + $mform->setDefault('resubmit', 1); + + $options = array(); + for($i = 1; $i <= 20; $i++) { + $options[$i] = $i; + } + $mform->addElement('select', 'var1', get_string("allowmaxfiles", "assignment"), $options); + $mform->setHelpButton('var1', array('allowmaxfiles', get_string('allowmaxfiles', 'assignment'), 'assignment')); + $mform->setDefault('var1', 3); + + $mform->addElement('select', 'var2', get_string("allownotes", "assignment"), $ynoptions); + $mform->setHelpButton('var2', array('allownotes', get_string('allownotes', 'assignment'), 'assignment')); + $mform->setDefault('var2', 0); + + $mform->addElement('select', 'var3', get_string("hideintro", "assignment"), $ynoptions); + $mform->setHelpButton('var3', array('hideintro', get_string('hideintro', 'assignment'), 'assignment')); + $mform->setDefault('var3', 0); + + $mform->addElement('select', 'emailteachers', get_string("emailteachers", "assignment"), $ynoptions); + $mform->setHelpButton('emailteachers', array('emailteachers', get_string('emailteachers', 'assignment'), 'assignment')); + $mform->setDefault('emailteachers', 0); + + + } + } class mod_assignment_upload_notes_form extends moodleform { diff --git a/mod/assignment/type/upload/mod.html b/mod/assignment/type/upload/mod.html deleted file mode 100644 index daeafacb93..0000000000 --- a/mod/assignment/type/upload/mod.html +++ /dev/null @@ -1,97 +0,0 @@ -var1)) { - $form->var1 = 3; // max number of uploaded files - } - if (empty($form->var2)) { - $form->var2 = 0; // enable notes - } - if (empty($form->var3)) { - $form->var3 = 0; // force intro hiding before available date - } - if (empty($form->resubmit)) { - $form->resubmit = 1; // allow deleting - } - if (empty($form->maxbytes)) { - $form->maxbytes = $CFG->assignment_maxbytes; - } - if (empty($form->emailteachers)) { - $form->emailteachers = 0; - } -?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
: - maxbytes, $this->course->maxbytes); - choose_from_menu ($choices, "maxbytes", $form->maxbytes, ""); - ?> -
: - get_string("no"), 1=>get_string("yes")); - choose_from_menu($options, "resubmit", $form->resubmit, ""); - helpbutton("allowdeleting", get_string("allowdeleting", "assignment"), "assignment"); - ?> -
: - var1, ""); - helpbutton("allowmaxfiles", get_string("allowmaxfiles", "assignment"), "assignment"); - ?> -
: - get_string("no"), 1=>get_string("yes")); - choose_from_menu($options, "var2", $form->var2, ""); - helpbutton("allownotes", get_string("allownotes", "assignment"), "assignment"); - ?> -
: - get_string("no"), 1=>get_string("yes")); - choose_from_menu($options, "var3", $form->var3, ""); - helpbutton("hideintro", get_string("hideintro", "assignment"), "assignment"); - ?> -
: - get_string("no"), 1=>get_string("yes")); - choose_from_menu($options, "emailteachers", $form->emailteachers, ""); - helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment"); - ?> -
- -
-
-" /> -
diff --git a/mod/assignment/type/uploadsingle/assignment.class.php b/mod/assignment/type/uploadsingle/assignment.class.php index 523888df88..51293c6a52 100644 --- a/mod/assignment/type/uploadsingle/assignment.class.php +++ b/mod/assignment/type/uploadsingle/assignment.class.php @@ -158,8 +158,26 @@ class assignment_uploadsingle extends assignment_base { $this->view_footer(); } + function setup_elements(&$mform) { + global $CFG, $COURSE; + $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes')); + $mform->addElement('select', 'resubmit', get_string("allowresubmit", "assignment"), $ynoptions); + $mform->setHelpButton('resubmit', array('resubmit', get_string('allowresubmit', 'assignment'), 'assignment')); + $mform->setDefault('resubmit', 0); + + $mform->addElement('select', 'emailteachers', get_string("emailteachers", "assignment"), $ynoptions); + $mform->setHelpButton('emailteachers', array('emailteachers', get_string('emailteachers', 'assignment'), 'assignment')); + $mform->setDefault('emailteachers', 0); + + $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); + $choices[1] = get_string('uploadnotallowed'); + $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')'; + $mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices); + $mform->setDefault('maxbytes', $CFG->assignment_maxbytes); + + } } diff --git a/mod/assignment/type/uploadsingle/mod.html b/mod/assignment/type/uploadsingle/mod.html deleted file mode 100644 index eb0aa09577..0000000000 --- a/mod/assignment/type/uploadsingle/mod.html +++ /dev/null @@ -1,52 +0,0 @@ -resubmit)) { - $form->resubmit = 0; - } - if (empty($form->maxbytes)) { - $form->maxbytes = $CFG->assignment_maxbytes; - } - if (empty($form->emailteachers)) { - $form->emailteachers = ''; - } -?> - - - - - - - - - - - - - - - - - - -
: - maxbytes, $this->course->maxbytes); - choose_from_menu ($choices, "maxbytes", $form->maxbytes, ""); - ?> -
: - resubmit, ""); - helpbutton("resubmit", get_string("allowresubmit", "assignment"), "assignment"); - ?> -
: - emailteachers, ""); - helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment"); - ?> -
- -
-
-" /> -
-- 2.39.5