helper_plugin_data::_column PHP Method

_column() public method

Split a column name into its parts
public _column ( string $col )
$col string column name
    function _column($col)
    {
        preg_match('/^([^_]*)(?:_(.*))?((?<!s)|s)$/', $col, $matches);
        $column = array('colname' => $col, 'multi' => $matches[3] === 's', 'key' => utf8_strtolower($matches[1]), 'origkey' => $matches[1], 'title' => $matches[1], 'type' => utf8_strtolower($matches[2]));
        // fix title for special columns
        static $specials = array('%title%' => array('page', 'title'), '%pageid%' => array('title', 'page'), '%class%' => array('class'), '%lastmod%' => array('lastmod', 'timestamp'));
        if (isset($specials[$column['title']])) {
            $s = $specials[$column['title']];
            $column['title'] = $this->getLang($s[0]);
            if ($column['type'] === '' && isset($s[1])) {
                $column['type'] = $s[1];
            }
        }
        // check if the type is some alias
        $aliases = $this->_aliases();
        if (isset($aliases[$column['type']])) {
            $column['origtype'] = $column['type'];
            $column['type'] = $aliases[$column['type']];
        }
        // use custom localization for keys
        if (isset($this->locs[$column['key']])) {
            $column['title'] = $this->locs[$column['key']];
        }
        return $column;
    }

Usage Example

 function testColumn()
 {
     global $conf;
     $helper = new helper_plugin_data();
     $this->assertEquals($this->createColumnEntry('type', false, 'type', 'type', ''), $helper->_column('type'));
     $this->assertEquals($this->createColumnEntry('types', true, 'type', 'type', ''), $helper->_column('types'));
     $this->assertEquals($this->createColumnEntry('', false, '', '', ''), $helper->_column(''));
     $this->assertEquals($this->createColumnEntry('type_url', false, 'type', 'type', 'url'), $helper->_column('type_url'));
     $this->assertEquals($this->createColumnEntry('type_urls', true, 'type', 'type', 'url'), $helper->_column('type_urls'));
     $this->assertEquals($this->createColumnEntry('type_hidden', false, 'type', 'type', 'hidden'), $helper->_column('type_hidden'));
     $this->assertEquals($this->createColumnEntry('type_hiddens', true, 'type', 'type', 'hidden'), $helper->_column('type_hiddens'));
     $this->assertEquals($this->createColumnEntry('%title%', false, '%title%', 'Page', 'title'), $helper->_column('%title%'));
     $this->assertEquals($this->createColumnEntry('%pageid%', false, '%pageid%', 'Title', 'page'), $helper->_column('%pageid%'));
     $this->assertEquals($this->createColumnEntry('%class%', false, '%class%', 'Page Class', ''), $helper->_column('%class%'));
     $this->assertEquals($this->createColumnEntry('%lastmod%', false, '%lastmod%', 'Last Modified', 'timestamp'), $helper->_column('%lastmod%'));
     // test translated key name
     $this->assertEquals($this->createColumnEntry('trans_urls', true, 'trans', 'Translated Title', 'url'), $helper->_column('trans_urls'));
     // retry in different language
     $conf['lang'] = 'de';
     $helper = new helper_plugin_data();
     $this->assertEquals($this->createColumnEntry('trans_urls', true, 'trans', 'Übersetzter Titel', 'url'), $helper->_column('trans_urls'));
 }