/**
  * Test updating configuration.
  */
 public function test_rlipexport_version1elis_extrafields_update_config()
 {
     global $DB;
     // Generate initial config.
     for ($i = 0; $i < 6; $i++) {
         $record = new stdClass();
         $record->header = 'Test Field ' . $i;
         $record->fieldorder = $i;
         $record->fieldset = 'fieldset' . $i;
         $record->field = 'field' . $i;
         $record->id = $DB->insert_record(RLIPEXPORT_VERSION1ELIS_FIELD_TABLE, $record);
     }
     // Update config.
     $updateddata = array('fieldset0/field0' => array('header' => 'Updated Field 0', 'fieldset' => 'fieldset0', 'field' => 'field0', 'fieldorder' => 0), 'fieldset1/field1' => array('header' => 'Test Field 1', 'fieldset' => 'fieldset1', 'field' => 'field1', 'fieldorder' => 1), 'fieldset3/field3' => array('header' => 'Test Field 3', 'fieldset' => 'fieldset3', 'field' => 'field3', 'fieldorder' => 2), 'fieldset6/field6' => array('header' => 'Test Field 6', 'fieldset' => 'fieldset6', 'field' => 'field6', 'fieldorder' => 3), 'fieldset5/field5' => array('header' => 'Test Field 5', 'fieldset' => 'fieldset5', 'field' => 'field5', 'fieldorder' => 4), 'fieldset4/field4' => array('header' => 'Test Field 4', 'fieldset' => 'fieldset4', 'field' => 'field4', 'fieldorder' => 5), 'fieldset7/field7' => array('header' => 'Test Field 7', 'fieldset' => 'fieldset7', 'field' => 'field7', 'fieldorder' => 7));
     rlipexport_version1elis_extrafields::update_config($updateddata);
     // Verify update.
     $records = $DB->get_records(RLIPEXPORT_VERSION1ELIS_FIELD_TABLE, array(), 'fieldorder ASC');
     $this->assertNotEmpty($records);
     $this->assertEquals(7, count($records));
     $records = array_values($records);
     $expected = array_values($updateddata);
     for ($i = 0; $i < 6; $i++) {
         $this->assertEquals($expected[$i]['header'], $records[$i]->header);
         $this->assertEquals($expected[$i]['fieldset'], $records[$i]->fieldset);
         $this->assertEquals($expected[$i]['field'], $records[$i]->field);
         $this->assertEquals($expected[$i]['fieldorder'], $records[$i]->fieldorder);
     }
 }
Exemplo n.º 2
0
require_once $file;
// Permissions checking.
require_login();
$context = context_system::instance();
require_capability('moodle/site:config', $context);
// Handle submitted actions.
$baseurl = $CFG->wwwroot . '/local/datahub/exportplugins/version1elis/config_fields.php';
$data_submitted = optional_param('data_submitted', false, PARAM_INT);
if (!empty($data_submitted)) {
    require_sesskey();
    $submitted_fields = optional_param_array('fields', array(), PARAM_SAFEPATH);
    // Safepath needed for '/'.
    $submitted_fieldnames = optional_param_array('fieldnames', array(), PARAM_ALPHANUM);
    $submitted_data = array('fields' => $submitted_fields, 'fieldnames' => $submitted_fieldnames);
    $processed_formdata = rlipexport_version1elis_extrafields::process_config_formdata($submitted_data);
    rlipexport_version1elis_extrafields::update_config($processed_formdata);
    redirect($baseurl);
}
$available_fields = rlipexport_version1elis_extrafields::get_available_fields();
$enabled_fields = rlipexport_version1elis_extrafields::get_enabled_fields();
$fieldsets = array();
$fields_by_fieldset = array();
$active_fields_by_fieldset_unordered = array();
$active_fields_by_fieldset_order = array();
$name_overrides = array();
foreach ($available_fields as $fieldset => $fields) {
    $fieldset_class = rlipexport_version1elis_extrafields::FIELDSET_PREFIX . $fieldset;
    $fieldsets[$fieldset] = $fieldset_class::get_label();
    foreach ($fields as $field => $header) {
        if (isset($enabled_fields[$fieldset][$field])) {
            $enabled_field_rec = $enabled_fields[$fieldset][$field];