view_table_php.class.php

来自「很棒的在线教学系统」· PHP 代码 · 共 1,064 行 · 第 1/3 页

PHP
1,064
字号
        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$field = $table->getField($field)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Calculate the default tip text        $default = $field->getDefault() === null ? 'drop it' : $field->getDefault();    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Changing the default of field ' . $field->getName() . ' on table ' . $table->getName() . ' to ' . $default . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $field = new XMLDBField(' . "'" . $field->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $field->setAttributes(' . $field->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch change of default for field ' . $field->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && change_field_default($table, $field);' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate all the PHP code needed to     * create one key using XMLDB objects and functions     *     * @param XMLDBStructure structure object containing all the info     * @param string table table name     * @param string key key name to be created     * @return string PHP code to be used to create the key     */    function add_key_php($structure, $table, $key) {        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$key = $table->getKey($key)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Define key ' . $key->getName() . ' ('. $key->getXMLDBKeyName($key->getType()) . ') to be added to ' . $table->getName() . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $key = new XMLDBKey(' . "'" . $key->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $key->setAttributes(' . $key->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch add key ' . $key->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && add_key($table, $key);' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate all the PHP code needed to     * drop one key using XMLDB objects and functions     *     * @param XMLDBStructure structure object containing all the info     * @param string table table name     * @param string key key name to be dropped     * @return string PHP code to be used to drop the key     */    function drop_key_php($structure, $table, $key) {        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$key = $table->getKey($key)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Define key ' . $key->getName() . ' ('. $key->getXMLDBKeyName($key->getType()) . ') to be dropped form ' . $table->getName() . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $key = new XMLDBKey(' . "'" . $key->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $key->setAttributes(' . $key->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch drop key ' . $key->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && drop_key($table, $key);' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate all the PHP code needed to     * rename one key using XMLDB objects and functions     *     * @param XMLDBStructure structure object containing all the info     * @param string table table name     * @param string key key name to be renamed     * @return string PHP code to be used to rename the key     */    function rename_key_php($structure, $table, $key) {        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$key = $table->getKey($key)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Prepend warning. This function isn't usable!        $result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Define key ' . $key->getName() . ' ('. $key->getXMLDBKeyName($key->getType()) . ') to be renamed to NEWNAMEGOESHERE' . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $key = new XMLDBKey(' . "'" . $key->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $key->setAttributes(' . $key->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch rename key ' . $key->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && rename_key($table, $key, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate all the PHP code needed to     * create one index using XMLDB objects and functions     *     * @param XMLDBStructure structure object containing all the info     * @param string table table name     * @param string index index name to be created     * @return string PHP code to be used to create the index     */    function add_index_php($structure, $table, $index) {        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$index = $table->getIndex($index)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Define index ' . $index->getName() . ' ('. ($index->getUnique() ? 'unique' : 'not unique') . ') to be added to ' . $table->getName() . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $index = new XMLDBIndex(' . "'" . $index->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $index->setAttributes(' . $index->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch add index ' . $index->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && add_index($table, $index);' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate all the PHP code needed to     * drop one index using XMLDB objects and functions     *     * @param XMLDBStructure structure object containing all the info     * @param string table table name     * @param string index index name to be dropped     * @return string PHP code to be used to drop the index     */    function drop_index_php($structure, $table, $index) {        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$index = $table->getIndex($index)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Define index ' . $index->getName() . ' ('. ($index->getUnique() ? 'unique' : 'not unique') . ') to be dropped form ' . $table->getName() . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $index = new XMLDBIndex(' . "'" . $index->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $index->setAttributes(' . $index->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch drop index ' . $index->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && drop_index($table, $index);' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate all the PHP code needed to     * rename one index using XMLDB objects and functions     *     * @param XMLDBStructure structure object containing all the info     * @param string table table name     * @param string index index name to be renamed     * @return string PHP code to be used to rename the index     */    function rename_index_php($structure, $table, $index) {        $result = '';    /// Validate if we can do it        if (!$table = $structure->getTable($table)) {            return false;        }        if (!$index = $table->getIndex($index)) {            return false;        }        if ($table->getAllErrors()) {            return false;        }    /// Prepend warning. This function isn't usable!        $result .= 'DON\'T USE THIS FUNCTION (IT\'S ONLY EXPERIMENTAL). SOME DBs DON\'T SUPPORT IT!' . XMLDB_LINEFEED . XMLDB_LINEFEED;    /// Add the standard PHP header        $result .= XMLDB_PHP_HEADER;    /// Add contents        $result .= XMLDB_LINEFEED;        $result .= '    /// Define index ' . $index->getName() . ' ('. ($index->getUnique() ? 'unique' : 'not unique') . ') to be renamed to NEWNAMEGOESHERE' . XMLDB_LINEFEED;        $result .= '        $table = new XMLDBTable(' . "'" . $table->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $index = new XMLDBIndex(' . "'" . $index->getName() . "'" . ');' . XMLDB_LINEFEED;        $result .= '        $index->setAttributes(' . $index->getPHP(true) . ');' . XMLDB_LINEFEED;    /// Launch the proper DDL        $result .= XMLDB_LINEFEED;        $result .= '    /// Launch rename index ' . $index->getName() . XMLDB_LINEFEED;        $result .= '        $result = $result && rename_index($table, $index, ' . "'" . 'NEWNAMEGOESHERE' . "'" . ');' . XMLDB_LINEFEED;    /// Add the proper upgrade_xxxx_savepoint call        $result .= $this->upgrade_savepoint_php ($structure);    /// Add standard PHP footer        $result .= XMLDB_PHP_FOOTER;        return $result;    }    /**     * This function will generate the PHP code needed to     * implement the upgrade_xxxx_savepoint() php calls in     * upgrade code generated from the editor     *     * @param XMLDBStructure structure object containing all the info     * @return string PHP code to be used to stabilish a savepoint     */    function upgrade_savepoint_php ($structure) {        $path = $structure->getPath();        $result = '';        switch ($path) {            case 'lib/db':                $result = XMLDB_LINEFEED .                          '    /// Main savepoint reached' . XMLDB_LINEFEED .                          '        upgrade_main_savepoint($result, XXXXXXXXXX);' . XMLDB_LINEFEED;                break;        }        return $result;    }}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?