helper_plugin_data::_replacePlaceholdersInSQL PHP Method

_replacePlaceholdersInSQL() public method

Replace placeholders in sql
public _replacePlaceholdersInSQL ( &$data )
    function _replacePlaceholdersInSQL(&$data)
    {
        global $USERINFO;
        // allow current user name in filter:
        $data['sql'] = str_replace('%user%', $_SERVER['REMOTE_USER'], $data['sql']);
        $data['sql'] = str_replace('%groups%', implode("','", (array) $USERINFO['grps']), $data['sql']);
        // allow current date in filter:
        $data['sql'] = str_replace('%now%', dformat(null, '%Y-%m-%d'), $data['sql']);
        // language filter
        $data['sql'] = $this->makeTranslationReplacement($data['sql']);
    }

Usage Example

 function testReplacePlaceholdersInSQL()
 {
     $helper = new helper_plugin_data();
     $data = array('sql' => '%user%');
     $_SERVER['REMOTE_USER'] = '******';
     $helper->_replacePlaceholdersInSQL($data);
     $this->assertEquals('test', $data['sql']);
     $data = array('sql' => '%now%');
     $helper->_replacePlaceholdersInSQL($data);
     $this->assertRegExp('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $data['sql']);
     $data = array('sql' => '%lang%');
     $helper->_replacePlaceholdersInSQL($data);
     $this->assertEquals('en', $data['sql']);
 }