當前位置: 首頁>>代碼示例>>PHP>>正文


PHP field::make_from_moodle_field方法代碼示例

本文整理匯總了PHP中field::make_from_moodle_field方法的典型用法代碼示例。如果您正苦於以下問題:PHP field::make_from_moodle_field方法的具體用法?PHP field::make_from_moodle_field怎麽用?PHP field::make_from_moodle_field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在field的用法示例。


在下文中一共展示了field::make_from_moodle_field方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: test_make_from_moodle_field

 /**
  * Test make_from_moodle_field function.
  *
  * @dataProvider dataprovider_make_from_moodle_field
  * @param object $mfielddata Data to create the initial moodle profile with.
  * @param array $expectedfielddata Expected data created for the field.
  * @param array $expectedmanualownerdata Expected field_owner data created.
  */
 public function test_make_from_moodle_field($mfielddata, $expectedfielddata, $expectedmanualownerdata)
 {
     require_once elis::file('eliscore/lib/data/customfield.class.php');
     require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
     global $DB;
     $mfieldid = $DB->insert_record('user_info_field', $mfielddata);
     $fieldcat = new field_category();
     $fieldcat->name = 'Moodle Fields';
     $fieldcat->save();
     $efield = field::make_from_moodle_field($mfieldid, $fieldcat, pm_moodle_profile::sync_from_moodle);
     $efieldrec = $DB->get_record(field::TABLE, array('shortname' => $efield->shortname));
     unset($efieldrec->id);
     unset($efieldrec->sortorder);
     $expectedfielddata['categoryid'] = (string) $fieldcat->id;
     $this->assertEquals($expectedfielddata, (array) $efieldrec);
     $manualowner = $DB->get_record(field_owner::TABLE, array('fieldid' => $efield->id, 'plugin' => 'manual'));
     ksort($expectedmanualownerdata);
     $actualparams = unserialize($manualowner->params);
     ksort($actualparams);
     $this->assertEquals($expectedmanualownerdata, $actualparams);
     $this->assertTrue(moodle_profile_can_sync($efield->shortname));
     if ($mfielddata['defaultdata'] != '') {
         switch ($efield->datatype) {
             case 'bool':
                 $fielddatatype = 'int';
                 break;
             case 'datetime':
                 $fielddatatype = 'int';
                 break;
             case 'char':
                 $fielddatatype = 'char';
                 break;
             default:
                 $fielddatatype = 'text';
         }
         $fielddataclass = 'field_data_' . $fielddatatype;
         $defaultdata = $DB->get_record($fielddataclass::TABLE, array('fieldid' => $efield->id));
         $this->assertNotEmpty($defaultdata);
         $this->assertEquals($mfielddata['defaultdata'], $defaultdata->data);
     }
 }
開發者ID:jamesmcq,項目名稱:elis,代碼行數:49,代碼來源:custom_field_makefrommoodlefield_test.php

示例2: local_elisprogram_upgrade_old_tables


//.........這裏部分代碼省略.........
    }
    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;
}
開發者ID:jamesmcq,項目名稱:elis,代碼行數:101,代碼來源:elis26_oldupgradesteps.php


注:本文中的field::make_from_moodle_field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。