require_capability('moodle/site:config', $context); $pluginwwwroot = str_replace($CFG->dirroot, $CFG->wwwroot, $plugindir); $baseurl = $pluginwwwroot . '/config_fields.php'; $tab = optional_param('tab', 'user', PARAM_CLEAN); //page header rlipimport_version1elis_page_setup($baseurl); echo $OUTPUT->header(); //tabs $tabs = rlipimport_version1elis_get_tabs($baseurl); print_tabs(array($tabs), $tab); //TODO: implement all necessary calls, etc, to make the rest of this code work //data from db $mappingdata = rlipimport_version1elis_get_mapping($tab); //options $plugin = new rlip_importplugin_version1elis(NULL, false); $options = $plugin->get_available_fields($tab); //body $form = new rlip_importfield_form(null, $options); //handle data submission if ($data = $form->get_data()) { if (isset($data->submitbutton)) { rlipimport_version1elis_save_mapping($tab, $options, $data); //notify to the user that settings were saved echo $OUTPUT->heading(get_string('mappingssaved', 'dhimport_version1elis')); } else { if (isset($data->reset)) { rlipimport_version1elis_reset_mappings($tab); redirect($baseurl . "?tab={$tab}&resetmessage=1", '', 0); } } } else {
/** * Validate restoring default field mappings */ public function testrestoredefaultmappingupdatesrecords() { global $CFG, $DB; $file = get_plugin_directory('dhimport', 'version1elis') . '/lib.php'; require_once $file; // Obtain available fields. $plugin = new rlip_importplugin_version1elis(null, false); $options = $plugin->get_available_fields('user'); // Persist default field. rlipimport_version1elis_save_mapping('user', $options, array()); // Setup validation. $select = 'standardfieldname = customfieldname'; $count = $DB->count_records_select(RLIPIMPORT_VERSION1ELIS_MAPPING_TABLE, $select); $this->assertEquals($count, count($options)); // Update all mapping values. $data = array(); foreach ($options as $option) { $data[$option] = $option . 'updated'; } // Persist updated values and validate. rlipimport_version1elis_save_mapping('user', $options, $data); $select = 'standardfieldname != customfieldname'; $count = $DB->count_records_select(RLIPIMPORT_VERSION1ELIS_MAPPING_TABLE, $select); $this->assertEquals($count, count($options)); // Reset and validate state. rlipimport_version1elis_reset_mappings('user'); $select = 'standardfieldname = customfieldname'; $count = $DB->count_records_select(RLIPIMPORT_VERSION1ELIS_MAPPING_TABLE, $select); $this->assertEquals($count, count($options)); }