Ejemplo n.º 1
0
//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 {
    if ($form->is_cancelled()) {
        redirect($baseurl . "?tab={$tab}&cancelmessage=1", '', 0);
    }
}
//message handling
$resetmessage = optional_param('resetmessage', 0, PARAM_INT);
if ($resetmessage) {
    //notify the user that the settings were reset to defaults
    echo $OUTPUT->heading(get_string('mappingsreset', 'dhimport_version1elis'));
}
$cancelmessage = optional_param('cancelmessage', 0, PARAM_INT);
 /**
  * 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));
 }