当前位置: 首页>>代码示例>>PHP>>正文


PHP field::load方法代码示例

本文整理汇总了PHP中field::load方法的典型用法代码示例。如果您正苦于以下问题:PHP field::load方法的具体用法?PHP field::load怎么用?PHP field::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在field的用法示例。


在下文中一共展示了field::load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: build_elis_field_data

 /**
  * 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;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:42,代码来源:custom_field_sync_test.php

示例2: test_export_nonmultivaluedata_ignoresubsequentvalues

 /**
  * 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]);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:27,代码来源:version1elis_extrafields_test.php

示例3: local_elisprogram_upgrade_old_tables

/**
 * 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);
//.........这里部分代码省略.........
开发者ID:jamesmcq,项目名称:elis,代码行数:101,代码来源:elis26_oldupgradesteps.php

示例4: test_usersetgroups

 /**
  * 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);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:21,代码来源:miscellaneouscontexts_test.php

示例5: test_manual_field_is_view_or_editable_with_view_edit_permissions_on_userset

 /**
  * 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);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:44,代码来源:custom_field_permissions_test.php

示例6: make_from_moodle_field

 /**
  * 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;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:90,代码来源:customfield.class.php

示例7: customfieldpage


//.........这里部分代码省略.........
                     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();
         }
     }
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:101,代码来源:customfieldpage.class.php


注:本文中的field::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。