rhymix/classes/xml/xmlquery/queryargument/DefaultValue.class.php
flyskyko e4306a789f Merge 1.5.2.3 (~r10623)
git-svn-id: http://xe-core.googlecode.com/svn/trunk@10624 201d5d3c-b55e-5fd7-737f-ddc643e51545
2012-04-26 09:17:29 +00:00

108 lines
3.7 KiB
PHP

<?php
class DefaultValue {
var $column_name;
var $value;
var $is_sequence = false;
var $is_operation = false;
var $operation = '';
var $_is_string = false; ///< Checks if value is plain string or name of XE function (ipaddress, plus, etc).
var $_is_string_from_function = false; //< Checks if value is string resulted from evaluating a piece of PHP code (see $_SERVER[REMOTE_ADDR])
function DefaultValue($column_name, $value){
$dbParser = &DB::getParser();
$this->column_name = $dbParser->parseColumnName($column_name);
$this->value = $value;
$this->value = $this->_setValue();
}
function isString(){
return $this->_is_string;
$str_pos = strpos($this->value, '(');
if($str_pos===false) return true;
return false;
}
function isStringFromFunction(){
return $this->_is_string_from_function;
}
function isSequence(){
return $this->is_sequence;
}
function isOperation(){
return $this->is_operation;
}
function getOperation(){
return $this->operation;
}
function _setValue(){
if(!isset($this->value)) return;
// If value contains comma separated values and does not contain paranthesis
// -> default value is an array
if(strpos($this->value, ',') !== false && strpos($this->value, '(') === false) {
return sprintf('array(%s)', $this->value);
}
$str_pos = strpos($this->value, '(');
// // TODO Replace this with parseExpression
if($str_pos===false) {
$this->_is_string = true;
return '\''.$this->value.'\'';
}
//if($str_pos===false) return $this->value;
$func_name = substr($this->value, 0, $str_pos);
$args = substr($this->value, $str_pos+1, -1);
switch($func_name) {
case 'ipaddress' :
$val = '$_SERVER[\'REMOTE_ADDR\']';
$this->_is_string_from_function = true;
break;
case 'unixtime' :
$val = 'time()';
break;
case 'curdate' :
$val = 'date("YmdHis")';
$this->_is_string_from_function = true;
break;
case 'sequence' :
$this->is_sequence = true;
$val = '$sequence';
break;
case 'plus' :
$args = abs($args);
$this->is_operation = true;
$this->operation = '+';
$val = sprintf('%d', $args);
break;
case 'minus' :
$args = abs($args);
$this->is_operation = true;
$this->operation = '-';
$val = sprintf('%d', $args);
break;
case 'multiply' :
$args = intval($args);
$this->is_operation = true;
$this->operation = '*';
$val = sprintf('%d', $args);
break;
default :
$val = '\'' . $this->value . '\'';
//$val = $this->value;
}
return $val;
}
function toString(){
return $this->value;
}
}