Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/workshop/mod_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00031 defined('MOODLE_INTERNAL') || die();
00032 
00033 require_once($CFG->dirroot . '/course/moodleform_mod.php');
00034 require_once(dirname(__FILE__) . '/locallib.php');
00035 require_once($CFG->libdir . '/filelib.php');
00036 
00040 class mod_workshop_mod_form extends moodleform_mod {
00041 
00043     protected $course = null;
00044 
00048     public function __construct($current, $section, $cm, $course) {
00049         $this->course = $course;
00050         parent::__construct($current, $section, $cm, $course);
00051     }
00052 
00058     public function definition() {
00059         global $CFG;
00060 
00061         $workshopconfig = get_config('workshop');
00062         $mform = $this->_form;
00063 
00064         // General --------------------------------------------------------------------
00065         $mform->addElement('header', 'general', get_string('general', 'form'));
00066 
00067         // Workshop name
00068         $label = get_string('workshopname', 'workshop');
00069         $mform->addElement('text', 'name', $label, array('size'=>'64'));
00070         if (!empty($CFG->formatstringstriptags)) {
00071             $mform->setType('name', PARAM_TEXT);
00072         } else {
00073             $mform->setType('name', PARAM_CLEANHTML);
00074         }
00075         $mform->addRule('name', null, 'required', null, 'client');
00076         $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
00077 
00078         // Introduction
00079         $this->add_intro_editor(false, get_string('introduction', 'workshop'));
00080 
00081         // Workshop features ----------------------------------------------------------
00082         $mform->addElement('header', 'workshopfeatures', get_string('workshopfeatures', 'workshop'));
00083 
00084         $label = get_string('useexamples', 'workshop');
00085         $text = get_string('useexamples_desc', 'workshop');
00086         $mform->addElement('checkbox', 'useexamples', $label, $text);
00087         $mform->addHelpButton('useexamples', 'useexamples', 'workshop');
00088 
00089         $label = get_string('usepeerassessment', 'workshop');
00090         $text = get_string('usepeerassessment_desc', 'workshop');
00091         $mform->addElement('checkbox', 'usepeerassessment', $label, $text);
00092         $mform->addHelpButton('usepeerassessment', 'usepeerassessment', 'workshop');
00093 
00094         $label = get_string('useselfassessment', 'workshop');
00095         $text = get_string('useselfassessment_desc', 'workshop');
00096         $mform->addElement('checkbox', 'useselfassessment', $label, $text);
00097         $mform->addHelpButton('useselfassessment', 'useselfassessment', 'workshop');
00098 
00099         // Grading settings -----------------------------------------------------------
00100         $mform->addElement('header', 'gradingsettings', get_string('gradingsettings', 'workshop'));
00101 
00102         $grades = workshop::available_maxgrades_list();
00103         $gradecategories = grade_get_categories_menu($this->course->id);
00104 
00105         $label = get_string('submissiongrade', 'workshop');
00106         $mform->addGroup(array(
00107             $mform->createElement('select', 'grade', '', $grades),
00108             $mform->createElement('select', 'gradecategory', '', $gradecategories),
00109             ), 'submissiongradegroup', $label, ' ', false);
00110         $mform->setDefault('grade', $workshopconfig->grade);
00111         $mform->addHelpButton('submissiongradegroup', 'submissiongrade', 'workshop');
00112 
00113         $label = get_string('gradinggrade', 'workshop');
00114         $mform->addGroup(array(
00115             $mform->createElement('select', 'gradinggrade', '', $grades),
00116             $mform->createElement('select', 'gradinggradecategory', '', $gradecategories),
00117             ), 'gradinggradegroup', $label, ' ', false);
00118         $mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
00119         $mform->addHelpButton('gradinggradegroup', 'gradinggrade', 'workshop');
00120 
00121         $label = get_string('strategy', 'workshop');
00122         $mform->addElement('select', 'strategy', $label, workshop::available_strategies_list());
00123         $mform->setDefault('strategy', $workshopconfig->strategy);
00124         $mform->addHelpButton('strategy', 'strategy', 'workshop');
00125 
00126         $options = array();
00127         for ($i=5; $i>=0; $i--) {
00128             $options[$i] = $i;
00129         }
00130         $label = get_string('gradedecimals', 'workshop');
00131         $mform->addElement('select', 'gradedecimals', $label, $options);
00132         $mform->setAdvanced('gradedecimals');
00133         $mform->setDefault('gradedecimals', $workshopconfig->gradedecimals);
00134 
00135         // Submission settings --------------------------------------------------------
00136         $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'workshop'));
00137 
00138         $label = get_string('instructauthors', 'workshop');
00139         $mform->addElement('editor', 'instructauthorseditor', $label, null,
00140                             workshop::instruction_editors_options($this->context));
00141 
00142         $options = array();
00143         for ($i=7; $i>=0; $i--) {
00144             $options[$i] = $i;
00145         }
00146         $label = get_string('nattachments', 'workshop');
00147         $mform->addElement('select', 'nattachments', $label, $options);
00148         $mform->setDefault('nattachments', 1);
00149 
00150         $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes);
00151         $options[0] = get_string('courseuploadlimit') . ' ('.display_size($this->course->maxbytes).')';
00152         $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'workshop'), $options);
00153         $mform->setDefault('maxbytes', $workshopconfig->maxbytes);
00154 
00155         $label = get_string('latesubmissions', 'workshop');
00156         $text = get_string('latesubmissions_desc', 'workshop');
00157         $mform->addElement('checkbox', 'latesubmissions', $label, $text);
00158         $mform->addHelpButton('latesubmissions', 'latesubmissions', 'workshop');
00159         $mform->setAdvanced('latesubmissions');
00160 
00161         // Assessment settings --------------------------------------------------------
00162         $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'workshop'));
00163 
00164         $label = get_string('instructreviewers', 'workshop');
00165         $mform->addElement('editor', 'instructreviewerseditor', $label, null,
00166                             workshop::instruction_editors_options($this->context));
00167 
00168         $label = get_string('examplesmode', 'workshop');
00169         $options = workshop::available_example_modes_list();
00170         $mform->addElement('select', 'examplesmode', $label, $options);
00171         $mform->setDefault('examplesmode', $workshopconfig->examplesmode);
00172         $mform->disabledIf('examplesmode', 'useexamples');
00173         $mform->setAdvanced('examplesmode');
00174 
00175         // Access control -------------------------------------------------------------
00176         $mform->addElement('header', 'accesscontrol', get_string('accesscontrol', 'workshop'));
00177 
00178         $label = get_string('submissionstart', 'workshop');
00179         $mform->addElement('date_time_selector', 'submissionstart', $label, array('optional' => true));
00180         $mform->setAdvanced('submissionstart');
00181 
00182         $label = get_string('submissionend', 'workshop');
00183         $mform->addElement('date_time_selector', 'submissionend', $label, array('optional' => true));
00184         $mform->setAdvanced('submissionend');
00185 
00186         $label = get_string('assessmentstart', 'workshop');
00187         $mform->addElement('date_time_selector', 'assessmentstart', $label, array('optional' => true));
00188         $mform->setAdvanced('assessmentstart');
00189 
00190         $label = get_string('assessmentend', 'workshop');
00191         $mform->addElement('date_time_selector', 'assessmentend', $label, array('optional' => true));
00192         $mform->setAdvanced('assessmentend');
00193 
00194         // Common module settings, Restrict availability, Activity completion etc. ----
00195         $features = array('groups'=>true, 'groupings'=>true, 'groupmembersonly'=>true,
00196                 'outcomes'=>true, 'gradecat'=>false, 'idnumber'=>false);
00197 
00198         $this->standard_coursemodule_elements();
00199 
00200         // Standard buttons, common to all modules ------------------------------------
00201         $this->add_action_buttons();
00202     }
00203 
00213     public function data_preprocessing(&$data) {
00214         if ($this->current->instance) {
00215             // editing an existing workshop - let us prepare the added editor elements (intro done automatically)
00216             $draftitemid = file_get_submitted_draft_itemid('instructauthors');
00217             $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
00218                                 'mod_workshop', 'instructauthors', 0,
00219                                 workshop::instruction_editors_options($this->context),
00220                                 $data['instructauthors']);
00221             $data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
00222             $data['instructauthorseditor']['itemid'] = $draftitemid;
00223 
00224             $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
00225             $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
00226                                 'mod_workshop', 'instructreviewers', 0,
00227                                 workshop::instruction_editors_options($this->context),
00228                                 $data['instructreviewers']);
00229             $data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
00230             $data['instructreviewerseditor']['itemid'] = $draftitemid;
00231         } else {
00232             // adding a new workshop instance
00233             $draftitemid = file_get_submitted_draft_itemid('instructauthors');
00234             file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0);    // no context yet, itemid not used
00235             $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
00236 
00237             $draftitemid = file_get_submitted_draft_itemid('instructreviewers');
00238             file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0);    // no context yet, itemid not used
00239             $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
00240         }
00241     }
00242 
00246     public function definition_after_data() {
00247 
00248         $mform =& $this->_form;
00249 
00250         if ($id = $mform->getElementValue('update')) {
00251             $instance   = $mform->getElementValue('instance');
00252 
00253             $gradeitems = grade_item::fetch_all(array(
00254                 'itemtype'      => 'mod',
00255                 'itemmodule'    => 'workshop',
00256                 'iteminstance'  => $instance,
00257                 'courseid'      => $this->course->id));
00258 
00259             if (!empty($gradeitems)) {
00260                 foreach ($gradeitems as $gradeitem) {
00261                     // here comes really crappy way how to set the value of the fields
00262                     // gradecategory and gradinggradecategory - grrr QuickForms
00263                     if ($gradeitem->itemnumber == 0) {
00264                         $group = $mform->getElement('submissiongradegroup');
00265                         $elements = $group->getElements();
00266                         foreach ($elements as $element) {
00267                             if ($element->getName() == 'gradecategory') {
00268                                 $element->setValue($gradeitem->categoryid);
00269                             }
00270                         }
00271                     } else if ($gradeitem->itemnumber == 1) {
00272                         $group = $mform->getElement('gradinggradegroup');
00273                         $elements = $group->getElements();
00274                         foreach ($elements as $element) {
00275                             if ($element->getName() == 'gradinggradecategory') {
00276                                 $element->setValue($gradeitem->categoryid);
00277                             }
00278                         }
00279                     }
00280                 }
00281             }
00282         }
00283 
00284         parent::definition_after_data();
00285     }
00286 }
 All Data Structures Namespaces Files Functions Variables Enumerations