iMath) - Computer Science Dep. of IME-USP (Brazil) * * License * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ // Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly. if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } require_once($CFG->libdir . '/formslib.php'); require_once($CFG->dirroot . '/course/moodleform_mod.php'); require_once($CFG->dirroot . '/mod/iassign/lib.php'); /// This class create form based moodleform. // @see moodleform class mod_iassign_form extends moodleform { /// Add elements to form function definition () { global $CFG, $COURSE, $USER, $DB, $OUTPUT; // $OUTPUT only used to get '$OUTPUT->help_icon(...)' $mform = $this->_form; $instance = $this->_customdata; // iGeom has special parameter 'script' $params = array('name' => '%iGeom%', 'parent' => 0); $igeom = $DB->get_records_sql( "SELECT s.id, s.name, s.parent FROM {iassign_ilm} s WHERE s.name LIKE :name AND s.parent = :parent", $params); $id = $COURSE->cm; foreach ($igeom as $item) $idigeom = $item->id; // get the last id of iGeom $all_ilm = $DB->get_records('iassign_ilm', array('enable' => 1)); // or use ./lib.php function: $all_ilm = search_iLM(1); $iassigns = $DB->get_records('iassign_statement', array('iassignid' => $COURSE->iassignid)); if ($all_ilm) { $ids = ""; $names = ""; $evaluates = ""; foreach ($all_ilm as $one_ilm) { $ids .= "'" . $one_ilm->id . "',"; $names .= "'" . $one_ilm->name . "',"; $evaluates .= "'" . $one_ilm->evaluate . "',"; } $ids .= "'0'"; $evaluates .= "'0'"; } $name_iassigns = ""; if ($iassigns) { foreach ($iassigns as $iassign) { $name_iassigns .= "'" . $iassign->name . "',"; } } $name_iassigns .= "''"; $error_name = get_string('error_iassign_name', 'iassign'); // @todo Código Javascript, verificar alternativa. $code_javascript = " "; //------------------------------------------------------------------------------- // Adding the "title_type_iassign" fieldset, where all the common settings are showed // Data is insert through 'locallib.php ! action() -> new_iassign($param) : 3433/6441' $mform->addElement('header', 'title_type_iassign', get_string('type_iassign', 'iassign')); $type_iassign = array(); $type_iassign[1] = get_string('example', 'iassign'); $type_iassign[2] = get_string('test', 'iassign'); $type_iassign[3] = get_string('exercise', 'iassign'); $mform->addElement('select', 'type_iassign', get_string('choose_type_activity', 'iassign'), $type_iassign, array('onChange' => 'config_type(this.value);')); $mform->setDefault('type_iassign', 3); // default type_iassign = 3 $mform->addHelpButton('type_iassign', 'helptypeiassign', 'iassign'); //------------------------------------------------------------------------------- // Adding the "data_activity" fieldset, where all the common settings are showed $mform->addElement('header', 'data_activity', get_string('data_activity', 'iassign')); $mform->addElement('static', 'author', get_string('author_id', 'iassign')); $mform->addElement('static', 'author_modified', get_string('author_id_modified', 'iassign')); // Adding the standard "name" field $mform->addElement('text', 'name', get_string('iassigntitle', 'iassign'), array('size' => '55', 'onChange' => 'confirm_name(this.value);')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', get_string('required', 'iassign'), 'required'); // Adding the standard "proposition" field //moodle2: $mform->addElement('htmleditor', 'proposition', get_string('proposition', 'iassign')); $mform->addElement('editor', 'proposition', get_string('proposition', 'iassign')); //moodle 3 $mform->setType('proposition', PARAM_RAW); $mform->addRule('proposition', get_string('required', 'iassign'), 'required'); //----------------------------------------------------------------------------- // Adding the "interactivy_learning_module" fieldset, where all the common settings are showed $mform->addElement('header', 'interactivy_learning_module', get_string('interactivy_learning_module', 'iassign')); //$mform->setExpanded('interactivy_learning_module'); // Search iLM registered in the database // Field : 'iassign_ilmid' // $ilms = search_iLM(1); $ilms = $all_ilm; //TODO Trick: was difficult to use 'mform->addGroup(...)', then I made by hand '; $html_div .= ''; $html_div .= ''; $mform->addElement('html', $html_div); //Applies only iLM iGeom $mform->addElement('selectyesno', 'special_param1', get_string('special_param', 'iassign')); //$ynoptions $mform->setDefault('special_param1', 0); $mform->addHelpButton('special_param1', 'helpspecial_param', 'iassign'); //----------------------------------------------------------------------------- //Applies only when the iLM is automatic evaluate. $mform->addElement('header', 'id_automatic_evaluate', get_string('only_automatic_evaluate', 'iassign')); // Using automatic evaluation activity? 0 - no / 1 – yes $mform->addElement('selectyesno', 'automatic_evaluate', get_string('automatic_evaluate', 'iassign'), array('onChange' => 'disable_answer(this.value);')); $mform->disabledIf('automatic_evaluate', 'type_iassign', 'eq', 1); //activity does not display if the type example $mform->setDefault('automatic_evaluate', 0); // @todo Ver código comentado //$mform->addHelpButton('automatic_evaluate', 'helpautomatic_evaluate', 'iassign'); //Show automatic evaluation results to students? 0 - no / 1 - yes $mform->addElement('selectyesno', 'show_answer', get_string('show_answer', 'iassign')); $mform->disabledIf('show_answer', 'type_iassign', 'eq', 1); //activity does not display if the type example // $mform->disabledIf('show_answer', 'automatic_evaluate', 'neq', 0); $mform->setDefault('show_answer', 0); //$mform->addHelpButton('show_answer', 'helpshow_answer', 'iassign'); //----------------------------------------------------------------------------- // Adding the "duration_activity" fieldset, where all the common settings are showed $mform->addElement('header', 'duration_activity', get_string('duration_activity', 'iassign')); $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'iassign')); $mform->setDefault('timeavailable', time()); $mform->disabledIf('timeavailable', 'type_iassign', 'eq', 1); // activity does not display if the type example $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'iassign')); $mform->setDefault('timedue', time() + 7 * 24 * 3600); $mform->disabledIf('timedue', 'type_iassign', 'eq', 1); //activity does not display if the type example //Allow sending late? 0 - no or unlocked / 1 - yes or locked $mform->addElement('selectyesno', 'preventlate', get_string('preventlate', 'iassign')); $mform->setDefault('preventlate', 0); $mform->addHelpButton('preventlate', 'helppreventlate', 'iassign'); $mform->disabledIf('preventlate', 'type_iassign', 'eq', 1); //activity does not display if the type example $mform->disabledIf('preventlate', 'type_iassign', 'eq', 2); //activity does not display if the type test //Allow test after delivery? 0 - no or unlocked / 1 - yes or locked $mform->addElement('selectyesno', 'test', get_string('permission_test', 'iassign')); $mform->setDefault('test', 0); $mform->addHelpButton('test', 'helptest', 'iassign'); $mform->disabledIf('test', 'type_iassign', 'eq', 1); //activity does not display if the type example $mform->disabledIf('test', 'type_iassign', 'eq', 2); //activity does not display if the type test //-------------- $mform->addElement('header', 'op_val', get_string('op_val', 'iassign')); $mform->addElement('modgrade', 'grade', get_string('grade', 'iassign')); $mform->setDefault('grade', 100); $mform->disabledIf('grade', 'type_iassign', 'eq', 1); //activity does not display if the type example $mform->disabledIf('grade', 'type_iassign', 'eq', 2); //activity does not display if the type test $max_experiment_options = array(0 => get_string('ilimit', 'iassign')); for ($i = 1; $i <= 20; $i++) $max_experiment_options[$i] = $i; $mform->addElement('select', 'max_experiment', get_string('experiment', 'iassign'), $max_experiment_options); $mform->setDefault('max_experiment', 0); $mform->addHelpButton('max_experiment', 'helpexperiment', 'iassign'); $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 1); //activity does not display if the type example $mform->disabledIf('max_experiment', 'type_iassign', 'eq', 2); //activity does not display if the type test if ($COURSE->iassign_list) { //-------------- dependency $mform->addElement('header', 'headerdependency', get_string('dependency', 'iassign')); $mform->addHelpButton('headerdependency', 'helpdependency', 'iassign'); foreach ($COURSE->iassign_list as $iassign) { $tmp = 'iassign_list[' . $iassign->id . ']'; if ($iassign->enable == 1) $mform->addElement('checkbox', $tmp, $iassign->name); } //foreach ($COURSE->iassign_list as $iassign) } //if ($COURSE->iassign_list) $mform->addElement('hidden', 'dependency'); $mform->setType('dependency', PARAM_RAW); //-------------- config $mform->addElement('header', 'config', get_string('general', 'iassign')); $visibleoptions = array(1 => get_string('show'), 0 => get_string('hide')); $mform->addElement('select', 'visible', get_string('visible', 'iassign'), $visibleoptions); $mform->setDefault('visible', 0); //------------------------------------------------------------------------------- // Hidden fields $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_TEXT); $mform->addElement('hidden', 'oldname'); $mform->setType('oldname', PARAM_TEXT); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_TEXT); $mform->addElement('hidden', 'iassign_id'); $mform->setType('iassign_id', PARAM_TEXT); $mform->addElement('hidden', 'file', '0'); $mform->setType('file', PARAM_INT); $mform->addElement('hidden', 'filename'); $mform->setType('filename', PARAM_TEXT); $mform->addElement('hidden', 'fileold'); $mform->setType('fileold', PARAM_TEXT); $mform->addElement('hidden', 'iassignid'); $mform->setType('iassignid', PARAM_TEXT); $mform->addElement('hidden', 'author_name'); $mform->setType('author_name', PARAM_TEXT); $mform->addElement('hidden', 'author_modified_name'); $mform->setType('author_modified_name', PARAM_TEXT); $mform->addElement('hidden', 'timecreated'); $mform->setType('timecreated', PARAM_TEXT); $mform->addElement('hidden', 'position'); $mform->setType('position', PARAM_TEXT); $mform->addElement('html', $code_javascript); // add standard elements, common to all modules $this->add_action_buttons(); } // function definition() function validation ($data, $files) { global $COURSE, $DB; $errors = parent::validation($data, $files); $mform = & $this->_form; $errors = array(); if ($mform->elementExists('name')) { $value = trim($data['name']); if ($value == '') { $errors['name'] = get_string('required', 'iassign'); } } if ($mform->elementExists('proposition')) { // echo "iassign_form.php : data['proposition'] :
"; print_r($data['proposition']); // $data['proposition'] = Array ([text] => ... [format] => ) - segundo esta' vazio! if (is_array($data['proposition'])) { // foreach ($data['proposition'] as $key => $value) echo "key=" . $key . " - value=" . $value . "
"; // $data['proposition'] = [format] => ) key=text - value= $aux = $data['proposition']; // Format JSON: {"em":"...","pt":"..."} if (isset($aux['text'])) $value = trim($aux['text']); else $value = trim($aux[0]); } else $value = trim($data['proposition']); if ($value == '') { $errors['proposition'] = get_string('required', 'iassign'); } } // echo "iassign_form.php : mform :
"; // print_r($mform); exit(); if ($mform->elementExists('file')) { $value = trim($data['file']); if ($value == 0) { $errors['iassign_ilmid'] = get_string('required_iassign_file', 'iassign'); } } return $errors; } // function validation($data, $files) } // class mod_iassign_form extends moodleform