本文整理汇总了PHP中xmldb_field::setLength方法的典型用法代码示例。如果您正苦于以下问题:PHP xmldb_field::setLength方法的具体用法?PHP xmldb_field::setLength怎么用?PHP xmldb_field::setLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmldb_field
的用法示例。
在下文中一共展示了xmldb_field::setLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: invoke
/**
* Invoke method, every class will have its own
* returns true/false on completion, setting both
* errormsg and output as necessary
*/
function invoke()
{
parent::invoke();
$result = true;
// Set own core attributes
$this->does_generate = ACTION_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
// These are always here
global $CFG, $XMLDB;
// Do the job, setting result as needed
// Get the dir containing the file
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
// Get the correct dirs
if (!empty($XMLDB->dbdirs)) {
$dbdir =& $XMLDB->dbdirs[$dirpath];
} else {
return false;
}
if (!empty($XMLDB->editeddirs)) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
}
// If the changeme table exists, just get it and continue
$changeme_exists = false;
if ($tables =& $structure->getTables()) {
if ($table =& $structure->getTable('changeme')) {
$changeme_exists = true;
}
}
if (!$changeme_exists) {
// Lets create the table
$field = new xmldb_field('id');
$field->setType(XMLDB_TYPE_INTEGER);
$field->setLength(10);
$field->setNotNull(true);
$field->setUnsigned(true);
$field->setSequence(true);
$field->setLoaded(true);
$field->setChanged(true);
$key = new xmldb_key('primary');
$key->setType(XMLDB_KEY_PRIMARY);
$key->setFields(array('id'));
$key->setLoaded(true);
$key->setChanged(true);
$table = new xmldb_table('changeme');
$table->setComment('Default comment for the table, please edit me');
$table->addField($field);
$table->addKey($key);
// Finally, add the whole retrofitted table to the structure
// in the place specified
$structure->addTable($table);
}
// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// Return ok if arrived here
return $result;
}
示例2: invoke
//.........这里部分代码省略.........
if (!(empty($default) || is_numeric($default) && !empty($default))) {
$errors[] = $this->str['defaultincorrect'];
}
}
/// Char checks
if ($type == XMLDB_TYPE_CHAR) {
if (!(is_numeric($length) && !empty($length) && intval($length) == floatval($length) && $length > 0 && $length <= 255)) {
$errors[] = $this->str['charincorrectlength'];
}
if ($default !== NULL && $default !== '') {
if (substr($default, 0, 1) == "'" || substr($default, -1, 1) == "'") {
$errors[] = $this->str['defaultincorrect'];
}
}
}
/// Text checks
if ($type == XMLDB_TYPE_TEXT) {
if ($length != 'small' && $length != 'medium' && $length != 'big') {
$errors[] = $this->str['textincorrectlength'];
}
if ($default !== NULL && $default !== '') {
if (substr($default, 0, 1) == "'" || substr($default, -1, 1) == "'") {
$errors[] = $this->str['defaultincorrect'];
}
}
}
/// Binary checks
if ($type == XMLDB_TYPE_BINARY) {
if ($length != 'small' && $length != 'medium' && $length != 'big') {
$errors[] = $this->str['binaryincorrectlength'];
}
}
if (!empty($errors)) {
$tempfield = new xmldb_field($name);
$tempfield->setType($type);
$tempfield->setLength($length);
$tempfield->setDecimals($decimals);
$tempfield->setUnsigned($unsigned);
$tempfield->setNotNull($notnull);
$tempfield->setSequence($sequence);
$tempfield->setDefault($default);
/// Prepare the output
$site = get_site();
$navlinks = array();
$navlinks[] = array('name' => $this->str['administration'], 'link' => '../index.php', 'type' => 'misc');
$navlinks[] = array('name' => 'XMLDB', 'link' => 'index.php', 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("{$site->shortname}: XMLDB", "{$site->fullname}", $navigation);
notice('<p>' . implode(', ', $errors) . '</p>
<p>' . $tempfield->readableInfo() . '</p>', 'index.php?action=edit_field&field=' . $field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
die;
/// re-die :-P
}
/// Continue if we aren't under errors
if (empty($errors)) {
/// If there is one name change, do it, changing the prev and next
/// atributes of the adjacent fields
if ($fieldparam != $name) {
$field->setName($name);
if ($field->getPrevious()) {
$prev =& $table->getField($field->getPrevious());
$prev->setNext($name);
$prev->setChanged(true);
}
if ($field->getNext()) {
$next =& $table->getField($field->getNext());
$next->setPrevious($name);
$next->setChanged(true);
}
}
/// Set comment
$field->setComment($comment);
/// Set the rest of fields
$field->setType($type);
$field->setLength($length);
$field->setDecimals($decimals);
$field->setUnsigned($unsigned);
$field->setNotNull($notnull);
$field->setSequence($sequence);
$field->setDefault($default);
/// If the hash has changed from the old one, change the version
/// and mark the structure as changed
$field->calculateHash(true);
if ($oldhash != $field->getHash()) {
$field->setChanged(true);
$table->setChanged(true);
/// Recalculate the structure hash
$structure->calculateHash(true);
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
/// Mark as changed
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
/// Return ok if arrived here
return $result;
}
示例3: xmldb_questionnaire_upgrade
//.........这里部分代码省略.........
if ($oldversion < 2008060401) {
$table = new xmldb_table('questionnaire_question');
$field = new xmldb_field('name');
$field->set_attributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null, 'survey_id');
$field->setNotnull(false);
$dbman->change_field_notnull($table, $field);
// Questionnaire savepoint reached.
upgrade_mod_savepoint(true, 2008060401, 'questionnaire');
}
if ($oldversion < 2008070702) {
$table = new xmldb_table('questionnaire_question_type');
$field = new xmldb_field('response_table');
$field->set_attributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, null, 'has_choices');
$field->setNotnull(false);
$dbman->change_field_notnull($table, $field);
// Questionnaire savepoint reached.
upgrade_mod_savepoint(true, 2008070702, 'questionnaire');
}
if ($oldversion < 2008070703) {
$table = new xmldb_table('questionnaire_resp_multiple');
$index = new xmldb_index('response_question');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('response_id', 'question_id', 'choice_id'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Questionnaire savepoint reached.
upgrade_mod_savepoint(true, 2008070703, 'questionnaire');
}
if ($oldversion < 2008070704) {
// CONTRIB-1542.
$table = new xmldb_table('questionnaire_survey');
$field = new xmldb_field('email');
$field->set_attributes(XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, null, null, 'title');
$field->setLength('255');
$dbman->change_field_precision($table, $field);
// Questionnaire savepoint reached.
upgrade_mod_savepoint(true, 2008070704, 'questionnaire');
}
if ($oldversion < 2008070705) {
// Rename summary field to 'intro' to adhere to new Moodle standard.
$table = new xmldb_table('questionnaire');
$field = new xmldb_field('summary');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, 'name');
$dbman->rename_field($table, $field, 'intro');
// Add 'introformat' to adhere to new Moodle standard.
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
$dbman->add_field($table, $field);
// Set all existing records to HTML format.
$DB->set_field('questionnaire', 'introformat', 1);
// Questionnaire savepoint reached.
upgrade_mod_savepoint(true, 2008070705, 'questionnaire');
}
if ($oldversion < 2008070706) {
// CONTRIB-1153.
$table = new xmldb_table('questionnaire_survey');
$field = new xmldb_field('public');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
$table = new xmldb_table('questionnaire_question');
$field = new xmldb_field('public');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Questionnaire savepoint reached.
upgrade_mod_savepoint(true, 2008070706, 'questionnaire');