public function definition() { global $CFG; $mform = $this->_form; // Don't forget the underscore! $term = $this->_customdata['term']; // this contains the data of this form $vid = $this->_customdata['vid']; // this contains the data of this form $data = taxonomy_vocabulary_list(); $vocabularies = array(); foreach ($data as $vocabulary) { $vocabularies[$vocabulary->id] = $vocabulary->name; } $mform->addElement('select', 'vid', get_string('parentvocabulary', 'local_taxonomy'), $vocabularies); $mform->setType('vid', PARAM_INT); $mform->addRule('vid', get_string('error'), 'required'); if (!empty($vid)) { $mform->setDefault('vid', $vid); } $mform->addElement('text', 'name', get_string('termname', 'local_taxonomy')); // Add elements to your form $mform->setType('name', PARAM_TEXT); //Set type of element $mform->addRule('name', get_string('error'), 'required', 'extraruledata', 'server', false, false); $mform->addRule('name', get_string('error'), 'maxlength', '255', 'server', false, false); $mform->addElement('text', 'shortname', get_string('termshortname', 'local_taxonomy')); // Add elements to your form $mform->setType('shortname', PARAM_TEXT); //Set type of element $mform->addRule('shortname', get_string('error'), 'required', 'extraruledata', 'server', false, false); $mform->setType('shortname', PARAM_TEXT); //Set type of element $mform->addRule('shortname', get_string('error'), 'maxlength', '255', 'server', false, false); // doit etre unique $mform->addElement('textarea', 'description', get_string('termdescription', 'local_taxonomy'), 'wrap="virtual" rows="10" cols="50"'); $mform->setType('description', PARAM_TEXT); //Set type of element //tableau contenant le poids du terme $array_weight = array(); for ($cpt = -50; $cpt <= 50; $cpt++) { $array_weight[$cpt] = $cpt; } $mform->addElement('select', 'weight', get_string('termweight', 'local_taxonomy'), $array_weight); $mform->setType('weight', PARAM_INT); $mform->setDefault('weight', 0); $this->add_action_buttons(); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); // Finally set the current form data $this->set_data($term); }
public function definition() { global $CFG; $mform = $this->_form; // Don't forget the underscore! $tid = $this->_customdata['tid']; // this contains the data of this form $instanceid = $this->_customdata['instanceid']; // this contains the data of this form $componenttype = $this->_customdata['componenttype']; // this contains the data of this form $data = taxonomy_vocabulary_list(); //var_dump($data); foreach ($data as $vocabulary) { $terms = null; $terms[] = 'Faites votre choix'; $vocabularies[$vocabulary->id] = $vocabulary->name; // il nous faut la liste des termes pour ce vocabulaire $terms_list = taxonomy_term_list($vocabulary->id); // var_dump($terms_list); foreach ($terms_list as $term) { $terms[$term->id] = $term->name; } // var_dump($terms); $myselect = $mform->addElement('select', 'voc_id_' . $vocabulary->id, $vocabulary->name, $terms); $myselect->setMultiple(true); $mform->setType('voc_id_' . $vocabulary->id, PARAM_INT); // $mform->addRule('voc'.$vocabulary->id, get_string('error'), 'required'); //echo "ajout $vocabulary->id : $vocabulary->name"; } $this->add_action_buttons(); $mform->addElement('hidden', 'instanceid', $instanceid); $mform->setType('instanceid', PARAM_INT); $mform->addElement('hidden', 'componenttype', $componenttype); $mform->setType('componenttype', PARAM_INT); // Finally set the current form data //$this->set_data($id); }
require_login(); $context = context_system::instance(); $PAGE->set_context($context); $PAGE->set_url('/local/taxonomy/index.php'); $PAGE->set_pagelayout('standard'); $PAGE->set_heading('Taxonomy'); $site = get_site(); $PAGE->set_title($site->fullname); $PAGE->navbar->add(get_string('navbartaxonomy', 'local_taxonomy'), new moodle_url('/local/taxonomy/index.php')); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('vocabularytitle', 'local_taxonomy')); $table = new html_table(); $table->head = array(); $table->head[] = 'ID'; $table->head[] = 'NAME'; $table->head[] = 'DESCRIPTION'; $table->head[] = 'WEIGHT'; $table->head[] = 'ACTIONS'; $table->size = array('5%', '40%', '40%', '5%', '10%'); $records = taxonomy_vocabulary_list(); foreach ($records as $key => $record) { $id = $record->id; $actions = array(); $actions[] = html_writer::link(new moodle_url(sprintf('/local/taxonomy/forms/VocabularyEditPage.php?id=%d', $id)), get_string('modifyvocabulary', 'local_taxonomy')); $actions[] = html_writer::link(new moodle_url(sprintf('/local/taxonomy/forms/VocabularyDeletePage.php?id=%d', $id)), get_string('deletevocabulary', 'local_taxonomy')); $table->data[] = array($id, html_writer::link(new moodle_url(sprintf('/local/taxonomy/viewterms.php?id=%d', $id)), $record->name), $record->description, $record->weight, implode('<br/>', $actions)); } echo html_writer::table($table); $add_new_url = new moodle_url('/local/taxonomy/forms/VocabularyEditPage.php'); echo html_writer::link($add_new_url, get_string('addnewvocabulary', 'local_taxonomy')); echo $OUTPUT->footer();