/**
  * Method to create ELIS field & owner objects given test data array.
  *
  * @param array $inputarray The test data array with params to build elis field object & owner
  *        input array format:
  *        array('field' => array(fieldparam => fieldparam_value [,...]),
  *              'context' => contextlevel,
  *              'manual' => array(fieldowners_manual_param => fomp_value [,...]),
  *              'moodle_profile' => array(fieldowners_moodleprofile_param => fompp_value [,...]),
  *        )
  * @return object The ELIS field object created
  */
 public function build_elis_field_data($inputarray)
 {
     $field = new field((object) $inputarray['field']);
     $field->save();
     $fieldcontext = new field_contextlevel();
     $fieldcontext->fieldid = $field->id;
     $fieldcontext->contextlevel = $inputarray['context'];
     $fieldcontext->save();
     if (isset($inputarray['manual'])) {
         $manual = new field_owner();
         $manual->fieldid = $field->id;
         $manual->plugin = 'manual';
         foreach ($inputarray['manual'] as $key => $val) {
             $manual->{'param_' . $key} = $val;
         }
         $manual->save();
     }
     if (isset($inputarray['moodle_profile'])) {
         $moodleprofile = new field_owner();
         $moodleprofile->fieldid = $field->id;
         $moodleprofile->plugin = 'moodle_profile';
         foreach ($inputarray['moodle_profile'] as $key => $val) {
             $moodleprofile->{$key} = $val;
         }
         $moodleprofile->save();
     }
     $field->load();
     // TDB.
     return $field;
 }
 /**
  * Validate that if a menu of choices field is converted from multi-valued to non-multi-valued value, users with multi-values
  * just have the first reported back.
  */
 public function test_export_nonmultivaluedata_ignoresubsequentvalues()
 {
     global $CFG, $DB;
     // Setup.
     $this->load_csv_data();
     $fieldid = $this->create_custom_field();
     $this->create_field_mapping('testcustomfields', 'field_' . $fieldid);
     $data = array('option1', 'option2', 'option3');
     $this->create_field_data($fieldid, $data);
     // Make non-multi-valued.
     $field = new field($fieldid);
     $field->load();
     $field->multivalued = 0;
     $field->save();
     // Obtain data.
     $data = $this->get_export_data();
     // Validation.
     $this->assertEquals(3, count($data));
     $header = $data[0];
     $this->assertEquals('Header', $header[10]);
     $firstuser = $data[1];
     $this->assertEquals('option1', $firstuser[10]);
 }
/**
 * Upgrade old ELIS tables.
 *
 * @param int $oldversion The old ELIS version.
 * @return bool Success/Failure.
 */
function local_elisprogram_upgrade_old_tables($oldversion)
{
    global $DB, $CFG;
    $dbman = $DB->get_manager();
    $result = true;
    if ($result && $oldversion < 2013031400) {
        // ELIS-8066: remove blank/empty menu options from custom field menu/checkbox and defaults using them.
        $customfields = $DB->get_recordset('local_eliscore_field', null, '', 'id');
        foreach ($customfields as $id => $unused) {
            $field = new field($id);
            $field->load();
            if (isset($field->owners['manual'])) {
                $manual = new field_owner($field->owners['manual']);
                $control = $manual->param_control;
                $options = $manual->param_options;
                if (!empty($options) && empty($manual->param_options_source) && ($control == 'menu' || $control == 'checkbox')) {
                    $options = str_replace("\r", '', $options);
                    // Strip CRs.
                    $options = preg_replace("/\n+/", "\n", $options);
                    $manual->param_options = rtrim($options, "\n");
                    $manual->save();
                    // Remove any empty defaults.
                    $DB->delete_records_select($field->data_table(), "contextid IS NULL AND fieldid = ? AND data = ''", array($id));
                }
            }
        }
        upgrade_plugin_savepoint($result, 2013031400, 'elis', 'program');
    }
    // ELIS-7780: remove deprecated capabilites.
    if ($result && $oldversion < 2013041900) {
        $capstodelete = array('elis/program:viewgroupreports', 'elis/program:viewreports');
        list($inorequal, $params) = $DB->get_in_or_equal($capstodelete);
        $where = "capability {$inorequal}";
        $DB->delete_records_select('role_capabilities', $where, $params);
        $where = "name {$inorequal}";
        $DB->delete_records_select('capabilities', $where, $params);
        upgrade_plugin_savepoint($result, 2013041900, 'elis', 'program');
    }
    // Remove any duplicate user track records before attempting to apply an index.
    pm_fix_duplicate_usertrack_records('crlm_user_track');
    if ($result && $oldversion < 2013042900) {
        // Add indexes to {crlm_user_track} table.
        $table = new xmldb_table('crlm_user_track');
        if ($dbman->table_exists($table)) {
            // Array of indexes to drop.
            $dropindexes = array(new xmldb_index('any_userid_ix', XMLDB_INDEX_UNIQUE, array('userid')), new xmldb_index('any_trackid_ix', XMLDB_INDEX_UNIQUE, array('trackid')), new xmldb_index('any_userid_trackid_ix', XMLDB_INDEX_NOTUNIQUE, array('userid', 'trackid')));
            foreach ($dropindexes as $index) {
                // Drop unwanted indexes if they exist.
                if ($dbman->index_exists($table, $index)) {
                    $dbman->drop_index($table, $index);
                }
            }
            // Array of indexes to create.
            $createindexes = array(new xmldb_index('userid_ix', XMLDB_INDEX_NOTUNIQUE, array('userid')), new xmldb_index('trackid_ix', XMLDB_INDEX_NOTUNIQUE, array('trackid')), new xmldb_index('userid_trackid_ix', XMLDB_INDEX_UNIQUE, array('userid', 'trackid')));
            foreach ($createindexes as $index) {
                // Create desired indexes as required.
                if (!$dbman->index_exists($table, $index)) {
                    $dbman->add_index($table, $index);
                }
            }
        }
        upgrade_plugin_savepoint($result, 2013042900, 'elis', 'program');
    }
    if ($result && $oldversion < 2013051500) {
        // Change results engine action min/max fields from integer to float.
        $table = new xmldb_table('crlm_results_action');
        if ($dbman->table_exists($table)) {
            $field = new xmldb_field('minimum', XMLDB_TYPE_NUMBER, '10,5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'actiontype');
            $dbman->change_field_type($table, $field);
            $field = new xmldb_field('maximum', XMLDB_TYPE_NUMBER, '10,5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'minimum');
            $dbman->change_field_type($table, $field);
        }
        upgrade_plugin_savepoint($result, 2013051500, 'elis', 'program');
    }
    if ($result && $oldversion < 2013051502) {
        // Define table crlm_certificate_settings to be created
        // Conditionally launch create table for crlm_certificate_settings.
        $table = new xmldb_table('crlm_certificate_settings');
        if (!$dbman->table_exists($table)) {
            // Adding fields to table crlm_certificate_settings.
            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
            $table->add_field('entity_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
            $table->add_field('entity_type', XMLDB_TYPE_CHAR, '9', null, XMLDB_NOTNULL, null, null);
            $table->add_field('cert_border', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
            $table->add_field('cert_seal', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
            $table->add_field('cert_template', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
            $table->add_field('disable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
            $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
            $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
            // Adding keys to table crlm_certificate_settings.
            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
            // Adding indexes to table crlm_certificate_settings.
            $table->add_index('ent_id_type_ix', XMLDB_INDEX_UNIQUE, array('entity_id', 'entity_type'));
            $dbman->create_table($table);
        }
        // Define table crlm_certificate_issued to be created.
        $table = new xmldb_table('crlm_certificate_issued');
        // Conditionally launch create table for crlm_certificate_issued.
        if (!$dbman->table_exists($table)) {
            // Adding fields to table crlm_certificate_issued.
            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
            $table->add_field('cm_userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
            $table->add_field('cert_setting_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
            $table->add_field('cert_code', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
            $table->add_field('timeissued', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
            $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
            // Adding keys to table crlm_certificate_issued.
            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
            // Adding indexes to table crlm_certificate_issued.
            $table->add_index('cert_code_ix', XMLDB_INDEX_UNIQUE, array('cert_code'));
            $table->add_index('cm_userid_ix', XMLDB_INDEX_NOTUNIQUE, array('cm_userid'));
            $dbman->create_table($table);
        }
        // ELIS savepoint reached.
        upgrade_plugin_savepoint($result, 2013051502, 'elis', 'program');
    }
    // ELIS-8528: remove orphaned LOs.
    if ($result && $oldversion < 2013051503) {
        $where = 'NOT EXISTS (SELECT \'x\' FROM {crlm_course} cc WHERE cc.id = {crlm_course_completion}.courseid)';
        $DB->delete_records_select('crlm_course_completion', $where);
        upgrade_plugin_savepoint($result, 2013051503, 'elis', 'program');
    }
    if ($result && $oldversion < 2013082100) {
        // Change password field length to 255.
        $table = new xmldb_table('crlm_user');
        $field = new xmldb_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'username');
        $dbman->change_field_precision($table, $field);
        upgrade_plugin_savepoint($result, 2013082100, 'elis', 'program');
    }
    if ($result && $oldversion < 2013082101) {
        require_once elis::file('eliscore/fields/manual/custom_fields.php');
        require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
        $fieldcat = field_category::ensure_exists_for_contextlevel(get_string('moodlefields', 'local_elisprogram'), CONTEXT_ELIS_USER);
        $sql = 'SELECT m.id
                  FROM {user_info_field} m
                 WHERE NOT EXISTS(
                           SELECT *
                             FROM {local_eliscore_field} e
                            WHERE e.shortname = m.shortname
                       )';
        $fieldstosync = $DB->get_records_sql($sql);
        foreach ($fieldstosync as $mfield) {
            // Create field.
            $efield = field::make_from_moodle_field($mfield->id, $fieldcat, pm_moodle_profile::sync_from_moodle);
            // Sync profile field information from Moodle into ELIS.
            sync_profile_field_from_moodle($efield);
        }
        upgrade_plugin_savepoint($result, 2013082101, 'elis', 'program');
    }
    if ($result && $oldversion < 2013082103) {
        // ELIS-8441 & ELIS-8569: Fix Program timetocomplete & frequency defaults of '0y'.
        $table = new xmldb_table('crlm_curriculum');
        if ($dbman->table_exists($table)) {
            $field = new xmldb_field('timetocomplete', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, 'timemodified');
            $dbman->change_field_default($table, $field);
            $field = new xmldb_field('frequency', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, 'timetocomplete');
            $dbman->change_field_default($table, $field);
            $sql = 'UPDATE {crlm_curriculum} SET timetocomplete = "" WHERE timetocomplete = "0y"';
            $DB->execute($sql);
            $sql = 'UPDATE {crlm_curriculum} SET frequency = "" WHERE frequency = "0y"';
            $DB->execute($sql);
        }
        upgrade_plugin_savepoint($result, 2013082103, 'elis', 'program');
    }
    if ($result && $oldversion < 2013082104) {
        require_once dirname(__FILE__) . '/../../../lib/lib.php';
        pm_set_config('notify_addedtowaitlist_user', 1);
        pm_set_config('notify_enroledfromwaitlist_user', 1);
        pm_set_config('notify_incompletecourse_user', 1);
        upgrade_plugin_savepoint($result, 2013082104, 'elis', 'program');
    }
    return $result;
}
 /**
  * Test contexts for userset_groups
  *
  * Covers:
  * local/elisprogram/plugins/usetgroups/lib.php:643
  * local/elisprogram/plugins/usetgroups/lib.php:308
  * local/elisprogram/plugins/usetgroups/lib.php:601
  */
 public function test_usersetgroups()
 {
     global $DB;
     set_config('userset_groupings', true, 'elisprogram_usetgroups');
     $field = new field(array('shortname' => 'userset_groupings'));
     $field->load();
     $userset = $this->create_userset($field);
     userset_groups_grouping_helper($userset->id, $userset->name);
     $field = new field(array('shortname' => 'userset_group'));
     $field->load();
     $userset = $this->create_userset($field);
     userset_groups_userset_allows_groups($userset->id);
 }
 /**
  * Test user with view and edit permissions on a userset.
  * This test only rund when local/elisprogram/setuplib.php exists.
  */
 public function test_manual_field_is_view_or_editable_with_view_edit_permissions_on_userset()
 {
     global $DB, $CFG;
     // Skip test if local/elisprogram doesn't exist.
     if (!file_exists($CFG->dirroot . '/local/elisprogram/lib/setup.php')) {
         $this->markTestSkipped('Requires local/elisprogram to be installed.');
     }
     $this->resetAfterTest(true);
     $this->load_libraries_for_additional_tests();
     // Load CSV data.
     $this->load_csv_data();
     // Setup place holders for capabilities.
     $editcap = 'local/elisprogram:user_edit';
     $viewcap = 'local/elisprogram:user_view';
     // Retrieve the PM user id to be assigned to a userset
     $param = array('id' => 103);
     $pmuserinusersetid = $DB->get_field('local_elisprogram_usr', 'id', $param);
     // Retrieve the user who will be assigned a role in the user set.
     $param = array('id' => 101);
     $userroleinuserset = $DB->get_record('user', $param);
     // Set user with role as logged in user
     $this->setUser($userroleinuserset);
     // Get the userset context.
     $usersetcontext = \local_elisprogram\context\userset::instance(1);
     // System context.
     $syscontext = context_system::instance();
     // Create role and assign capabilites to it.
     $roleid = create_role('testrole', 'testrole', 'testrole');
     assign_capability($editcap, CAP_ALLOW, $roleid, $syscontext->id);
     assign_capability($viewcap, CAP_ALLOW, $roleid, $syscontext->id);
     // Assin role to user in the userset context.
     role_assign($roleid, $userroleinuserset->id, $usersetcontext->id);
     // Add user to cluster/userset.
     $usersetassign = new clusterassignment(array('clusterid' => 1, 'userid' => $pmuserinusersetid, 'plugin' => 'manual'));
     $usersetassign->save();
     $field = new field(array('id' => 101));
     $field->load();
     $result = manual_field_is_view_or_editable($field, $syscontext, $editcap, $viewcap, 'user', $pmuserinusersetid);
     $this->assertEquals(MANUAL_FIELD_EDITABLE, $result);
 }
Exemple #6
0
 /**
  * Create a user-level ELIS field from an existing Moodle user profile field.
  *
  * @param int $mfieldid The ID of a Moodle user profile field.
  * @param field_category $category An ELIS field_category object to add the new field to.
  * @param boolean $syncdir Data Sync Direction.
  *                         Possible values:
  *                             false = no syncing
  *                             pm_moodle_profile::sync_from_moodle = sync from moodle.
  *                             pm_moodle_profile::sync_to_moodle = sync to moodle.
  * @return field The new field object.
  */
 public static function make_from_moodle_field($mfieldid, field_category $category, $syncdir = false)
 {
     require_once elis::file('eliscore/fields/manual/custom_fields.php');
     require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
     global $DB;
     // Get moodle field information.
     $mfield = $DB->get_record('user_info_field', array('id' => $mfieldid));
     if (empty($mfield)) {
         return null;
     }
     if (!defined('CONTEXT_ELIS_USER')) {
         return null;
     }
     // Initially elis field data is the same as moodle field data.
     $field = (array) $mfield;
     unset($field['id']);
     $field['datatype'] = 'text';
     $field['categoryid'] = $category->id;
     // Manual field owner data.
     $fieldmanualowner = new field_owner();
     $fieldmanualowner->plugin = 'manual';
     $fieldmanualowner->param_control = $mfield->datatype;
     $fieldmanualowner->param_required = (bool) (int) $mfield->required;
     // Set data based on moodle field's datatype.
     switch ($mfield->datatype) {
         case static::CHECKBOX:
             $field['datatype'] = 'bool';
             break;
         case static::DATETIME:
             $field['datatype'] = 'datetime';
             $fieldmanualowner->param_startyear = $mfield->param1;
             $fieldmanualowner->param_stopyear = $mfield->param2;
             $fieldmanualowner->param_inctime = $mfield->param3;
             break;
         case static::MENU:
             $field['datatype'] = 'char';
             $fieldmanualowner->param_options = $mfield->param1;
             break;
         case static::TEXTAREA:
             $fieldmanualowner->param_columns = !empty($mfield->param1) ? $mfield->param1 : 30;
             $fieldmanualowner->param_rows = !empty($mfield->param2) ? $mfield->param2 : 10;
             break;
         case static::TEXT:
             if ($mfield->param3) {
                 $fieldmanualowner->param_control = 'password';
             }
             $fieldmanualowner->param_columns = $mfield->param1;
             $fieldmanualowner->param_maxlength = $mfield->param2;
             break;
     }
     // Create field.
     $field = new field($field);
     $field->save();
     // Create moodle profile owner.
     if ($syncdir === pm_moodle_profile::sync_from_moodle || $syncdir === pm_moodle_profile::sync_from_moodle) {
         $fieldmoodleprofileowner = new field_owner(array('fieldid' => $field->id, 'plugin' => 'moodle_profile', 'exclude' => $syncdir));
         $fieldmoodleprofileowner->save();
     }
     // Create manual owner.
     $fieldmanualowner->fieldid = $field->id;
     $fieldmanualowner->save();
     // Update field context level.
     static::ensure_field_exists_for_context_level($field, CONTEXT_ELIS_USER, $category);
     // Reload field object.
     $field = new field($field->id);
     $field->load();
     if ($syncdir === pm_moodle_profile::sync_from_moodle) {
         sync_profile_field_settings_from_moodle($field);
     }
     // Set default data.
     if (isset($mfield->defaultdata) && $mfield->defaultdata !== '') {
         field_data::set_for_context_and_field(null, $field, $mfield->defaultdata);
     }
     // Reload field object.
     $field = new field($field->id);
     $field->load();
     return $field;
 }
 function display_editfield()
 {
     global $CFG, $DB;
     $level = $this->required_param('level', PARAM_ACTION);
     $ctxlvl = \local_eliscore\context\helper::get_level_from_name($level);
     if (!$ctxlvl) {
         print_error('invalid_context_level', 'local_elisprogram');
     }
     $id = $this->optional_param('id', NULL, PARAM_INT);
     require_once elispm::file('form/customfieldform.class.php');
     $tmppage = new customfieldpage(array('level' => $level, 'action' => 'editfield'), $this);
     $form = new customfieldform($tmppage->url, array('id' => $id, 'level' => $level, 'from' => optional_param('from', '', PARAM_CLEAN)));
     if ($form->is_cancelled()) {
         $tmppage = new customfieldpage(array('level' => $level));
         redirect($tmppage->url, get_string('edit_cancelled', 'local_elisprogram'));
     } else {
         if ($data = $form->get_data()) {
             $src = !empty($data->manual_field_options_source) ? $data->manual_field_options_source : '';
             // ELIS-8066: strip CRs "\r" from menu options & default data (below)
             if (!empty($data->manual_field_options)) {
                 $data->manual_field_options = str_replace("\r", '', $data->manual_field_options);
             }
             switch ($data->manual_field_control) {
                 case 'checkbox':
                     if (!$data->multivalued && !empty($src)) {
                         $elem = "defaultdata_radio_{$src}";
                         $data->defaultdata = isset($data->{$elem}) ? $data->{$elem} : '';
                         // radio buttons unset by default
                         // error_log("/local/elisprogram/customfieldpage.class.php:: defaultdata->{$elem} = {$data->defaultdata}");
                     } else {
                         if (!$data->multivalued && !empty($data->manual_field_options)) {
                             $data->defaultdata = str_replace("\r", '', $data->defaultdata_radio);
                         } else {
                             $data->defaultdata = $data->defaultdata_checkbox;
                         }
                     }
                     break;
                 case 'menu':
                     $elem = !empty($src) ? "defaultdata_menu_{$src}" : "defaultdata_menu";
                     $data->defaultdata = $data->{$elem};
                     if (empty($src)) {
                         $data->defaultdata = str_replace("\r", '', $data->defaultdata);
                     }
                     break;
                 case 'datetime':
                     $data->defaultdata = $data->defaultdata_datetime;
                     break;
                 default:
                     $data->defaultdata = $data->defaultdata_text;
                     break;
             }
             $field = new field($data);
             if ($id) {
                 $field->id = $id;
                 $field->save();
             } else {
                 $field->save();
                 // assume each field only belongs to one context level (for now)
                 $fieldcontext = new field_contextlevel();
                 $fieldcontext->fieldid = $field->id;
                 $fieldcontext->contextlevel = $ctxlvl;
                 $fieldcontext->save();
             }
             //don't use !empty here because we might be storing a 0 or similar value
             if ($data->defaultdata != '') {
                 // save the default value
                 $defaultdata = $data->defaultdata;
                 if ($field->multivalued && is_string($defaultdata)) {
                     // parse as a CSV string
                     // until we can use str_getcsv from PHP 5.3...
                     $temp = fopen("php://memory", "rw");
                     fwrite($temp, $defaultdata);
                     rewind($temp);
                     $defaultdata = fgetcsv($temp);
                     fclose($temp);
                 } else {
                     if (!$field->multivalued && is_array($defaultdata)) {
                         foreach ($defaultdata as $val) {
                             $defaultdata = $val;
                             break;
                         }
                     }
                 }
                 field_data::set_for_context_and_field(NULL, $field, $defaultdata);
             } else {
                 if ($field->multivalued) {
                     field_data::set_for_context_and_field(NULL, $field, array());
                 } else {
                     field_data::set_for_context_and_field(NULL, $field, NULL);
                 }
             }
             $plugins = core_component::get_plugin_list('elisfields');
             foreach ($plugins as $plugin => $dir) {
                 if (is_readable($CFG->dirroot . '/local/eliscore/fields/' . $plugin . '/custom_fields.php')) {
                     require_once elis::plugin_file('elisfields_' . $plugin, 'custom_fields.php');
                     if (function_exists("{$plugin}_field_save_form_data")) {
                         call_user_func("{$plugin}_field_save_form_data", $form, $field, $data);
                     }
                 }
             }
             $tmppage = new customfieldpage(array('level' => $level));
             redirect($tmppage->url, get_string('field_saved', 'local_elisprogram', $field));
         } else {
             if (!empty($id)) {
                 if ($this->optional_param('from', NULL, PARAM_CLEAN) == 'moodle' && $level == 'user') {
                     $moodlefield = $DB->get_record('user_info_field', array('id' => $id));
                     if (!$moodlefield) {
                         print_error('invalid_field_id', 'local_elisprogram');
                     }
                     unset($moodlefield->id);
                     $data = $moodlefield;
                     $data_array = (array) $moodlefield;
                     $data_array['datatype'] = 'text';
                     $data_array['manual_field_control'] = $moodlefield->datatype;
                     switch ($moodlefield->datatype) {
                         case field::CHECKBOX:
                             $data_array['datatype'] = 'bool';
                             break;
                         case field::DATETIME:
                             $data_array['datatype'] = 'datetime';
                             $data_array['manual_field_startyear'] = $moodlefield->param1;
                             $data_array['manual_field_stopyear'] = $moodlefield->param2;
                             $data_array['manual_field_inctime'] = $moodlefield->param3;
                             break;
                         case field::MENU:
                             $data_array['datatype'] = 'char';
                             $data_array['manual_field_options'] = $moodlefield->param1;
                             break;
                         case field::TEXTAREA:
                             $data_array['manual_field_columns'] = $moodlefield->param1;
                             $data_array['manual_field_rows'] = $moodlefield->param2;
                             break;
                         case field::TEXT:
                             if ($moodlefield->param3) {
                                 $data_array['manual_field_control'] = 'password';
                             }
                             $data_array['manual_field_columns'] = $moodlefield->param1;
                             $data_array['manual_field_maxlength'] = $moodlefield->param2;
                             break;
                     }
                 } else {
                     $data = new field($id);
                     $data->load();
                     $manual = new field_owner(!isset($field->owners) || !isset($field->owners['manual']) ? false : $field->owners['manual']);
                     $menu_src = !empty($manual->options_source) ? $manual->options_source : 0;
                     $data_array = $data->to_array();
                     $field_record = $DB->get_record(field::TABLE, array('id' => $id));
                     if (!empty($field_record)) {
                         foreach ($field_record as $field_item => $field_value) {
                             $data_array[$field_item] = $field_value;
                         }
                     }
                     $defaultdata = field_data::get_for_context_and_field(NULL, $data);
                     if (!empty($defaultdata)) {
                         if ($data->multivalued) {
                             $values = array();
                             foreach ($defaultdata as $defdata) {
                                 $values[] = $defdata->data;
                             }
                             $defaultdata = $values;
                         } else {
                             foreach ($defaultdata as $defdata) {
                                 $defaultdata = $defdata->data;
                                 break;
                             }
                         }
                     }
                     $field = new field();
                     // Format decimal numbers
                     if ($data_array['datatype'] == 'num' && $manual->param_control != 'menu') {
                         $defaultdata = $field->format_number($defaultdata);
                     }
                     if (!is_object($defaultdata)) {
                         $data_array['defaultdata'] = $defaultdata;
                     }
                     $plugins = core_component::get_plugin_list('elisfields');
                     foreach ($plugins as $plugin => $dir) {
                         if (is_readable($CFG->dirroot . '/local/eliscore/fields/' . $plugin . '/custom_fields.php')) {
                             include_once $CFG->dirroot . '/local/eliscore/fields/' . $plugin . '/custom_fields.php';
                             if (function_exists("{$plugin}_field_get_form_data")) {
                                 $data_array += call_user_func("{$plugin}_field_get_form_data", $form, $data);
                             }
                         }
                     }
                 }
                 if (isset($data_array['defaultdata'])) {
                     // ELIS-6699 -- load the field to determine the data type used, $data may be a field_data_* or field object
                     if (isset($data->fieldid)) {
                         $field->id = $data->fieldid;
                         $field->load();
                     } else {
                         $field = $data;
                     }
                     $data_array['defaultdata_checkbox'] = !empty($data_array['defaultdata']);
                     // ELIS-6699 -- If this is not a datetime field, then we can't use the default data value as a timestamp
                     $data_array['defaultdata_datetime'] = $field->datatype == 'datetime' ? $data_array['defaultdata'] : time();
                     $data_array['defaultdata_text'] = strval($data_array['defaultdata']);
                     $data_array[empty($menu_src) ? 'defaultdata_menu' : "defaultdata_menu_{$menu_src}"] = $data_array['defaultdata'];
                     $data_array[empty($menu_src) ? 'defaultdata_radio' : "defaultdata_radio_{$menu_src}"] = $data_array['defaultdata'];
                 }
                 $form->set_data($data_array);
             }
             $form->display();
         }
     }
 }