Gdn_DatabaseStructure::column PHP Method

column() public method

Defines a column to be added to $this->Table().
public column ( string $Name, mixed $Type, boolean $NullDefault = false, string $KeyType = false )
$Name string The name of the column to create.
$Type mixed The data type of the column to be created. Types with a length speecifty the length in barackets. * If an array of values is provided, the type will be set as "enum" and the array will be assigned as the column's Enum property. * If an array of two values is specified then a "set" or "enum" can be specified (ex. array('set', array('Short', 'Tall', 'Fat', 'Skinny')))
$NullDefault boolean Whether or not nulls are allowed, if not a default can be specified. * TRUE: Nulls are allowed. * FALSE: Nulls are not allowed. * Any other value: Nulls are not allowed, and the specified value will be used as the default.
$KeyType string What type of key is this column on the table? Options are primary, key, and FALSE (not a key).
    public function column($Name, $Type, $NullDefault = false, $KeyType = false)
    {
        if (is_null($NullDefault) || $NullDefault === true) {
            $Null = true;
            $Default = null;
        } elseif ($NullDefault === false) {
            $Null = false;
            $Default = null;
        } elseif (is_array($NullDefault)) {
            $Null = val('Null', $NullDefault);
            $Default = val('Default', $NullDefault, null);
        } else {
            $Null = false;
            $Default = $NullDefault;
        }
        // Check the key type for validity. A column can be in many keys by specifying an array as key type.
        $KeyTypes = (array) $KeyType;
        $KeyTypes1 = array();
        foreach ($KeyTypes as $KeyType1) {
            $Parts = explode('.', $KeyType1, 2);
            if (in_array($Parts[0], array('primary', 'key', 'index', 'unique', 'fulltext', false))) {
                $KeyTypes1[] = $KeyType1;
            }
        }
        if (count($KeyTypes1) == 0) {
            $KeyType = false;
        } elseif (count($KeyTypes1) == 1) {
            $KeyType = $KeyTypes1[0];
        } else {
            $KeyType = $KeyTypes1;
        }
        $Column = $this->_createColumn($Name, $Type, $Null, $Default, $KeyType);
        $this->_Columns[$Name] = $Column;
        return $this;
    }