mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
Fixed condition group bug.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8394 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
c40ccf777f
commit
4d2d18b53b
9 changed files with 178 additions and 19 deletions
111
classes/xml/xmlquery/argument/ConditionArgument.class.php
Normal file
111
classes/xml/xmlquery/argument/ConditionArgument.class.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
class ConditionArgument extends Argument {
|
||||
var $operation;
|
||||
|
||||
function ConditionArgument($name, $value, $operation){
|
||||
parent::Argument($name, $value);
|
||||
$this->operation = $operation;
|
||||
}
|
||||
|
||||
function createConditionValue(){
|
||||
if(!isset($this->value)) return;
|
||||
|
||||
$name = $this->column_name;
|
||||
$operation = $this->operation;
|
||||
$value = $this->value;
|
||||
|
||||
switch($operation) {
|
||||
case 'like_prefix' :
|
||||
$this->value = $value.'%';
|
||||
break;
|
||||
case 'like_tail' :
|
||||
$this-> value = '%'.$value;
|
||||
break;
|
||||
case 'like' :
|
||||
$this->value = '%'.$value.'%';
|
||||
break;
|
||||
}
|
||||
/*
|
||||
//if(!in_array($operation,array('in','notin','between')) && is_array($value)){
|
||||
// $value = join(',', $value);
|
||||
//}
|
||||
// Daca operatia nu este in, notin, between si coloana e de tip numeric
|
||||
// daca valoarea e array -> concatenare
|
||||
// daca valoarea nu e array si nici nu contine paranteze (nu e functie) -> return (int)
|
||||
// altfel return valoare
|
||||
|
||||
// if(!in_array($operation,array('in','notin','between')) && $type == 'number') {
|
||||
// if(is_array($value)){
|
||||
// $value = join(',',$value);
|
||||
// }
|
||||
// if(strpos($value, ',') === false && strpos($value, '(') === false) return (int)$value;
|
||||
// return $value;
|
||||
// }
|
||||
//
|
||||
// if(!is_array($value) && strpos($name, '.') !== false && strpos($value, '.') !== false) {
|
||||
// list($table_name, $column_name) = explode('.', $value);
|
||||
// if($column_type[$column_name]) return $value;
|
||||
// }
|
||||
|
||||
switch($operation) {
|
||||
case 'like_prefix' :
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
$value = $value.'%';
|
||||
break;
|
||||
case 'like_tail' :
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
$value = '%'.$value;
|
||||
break;
|
||||
case 'like' :
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
$value = '%'.$value.'%';
|
||||
break;
|
||||
// case 'notin' :
|
||||
// if(is_array($value))
|
||||
// {
|
||||
// $value = $this->addQuotesArray($value);
|
||||
// if($type=='number') return join(',',$value);
|
||||
// else return "'". join("','",$value)."'";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return $value;
|
||||
// }
|
||||
// break;
|
||||
// case 'in' :
|
||||
// if(is_array($value))
|
||||
// {
|
||||
// $value = $this->addQuotesArray($value);
|
||||
// if($type=='number') return join(',',$value);
|
||||
// else return "'". join("','",$value)."'";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return $value;
|
||||
// }
|
||||
// break;
|
||||
// case 'between' :
|
||||
// if(!is_array($value)) $value = array($value);
|
||||
// $value = $this->addQuotesArray($value);
|
||||
// if($type!='number')
|
||||
// {
|
||||
// foreach($value as $k=>$v)
|
||||
// {
|
||||
// $value[$k] = "'".$v."'";
|
||||
// }
|
||||
// }
|
||||
|
||||
//return $value;
|
||||
break;
|
||||
default:
|
||||
if(!is_array($value)) $value = preg_replace('/(^\'|\'$){1}/', '', $value);
|
||||
}
|
||||
$this->value = $value;
|
||||
//return "'".$this->addQuotes($value)."'";
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -4,9 +4,16 @@
|
|||
var $argument_name;
|
||||
var $argument_validator;
|
||||
var $column_name;
|
||||
var $operation;
|
||||
var $ignoreValue;
|
||||
|
||||
function QueryArgument($tag){
|
||||
$this->argument_name = $tag->attrs->var;
|
||||
if(!$this->argument_name) $this->ignoreValue = true;
|
||||
else $this->ignoreValue = false;
|
||||
|
||||
if(!$this->argument_name) $this->argument_name = $tag->attrs->name;
|
||||
if(!$this->argument_name) $this->argument_name = $tag->attrs->column;
|
||||
|
||||
$name = $tag->attrs->name;
|
||||
if(!$name) $name = $tag->attrs->column;
|
||||
|
|
@ -14,10 +21,9 @@
|
|||
else {
|
||||
list($prefix, $name) = explode('.', $name);
|
||||
$this->column_name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$this->argument_name) $this->argument_name = $tag->attrs->name;
|
||||
if(!$this->argument_name) $this->argument_name = str_replace('.', '_', $condition->attrs->column);
|
||||
if($tag->attrs->operation) $this->operation = $tag->attrs->operation;
|
||||
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/validator/QueryArgumentValidator.class.php');
|
||||
$this->argument_validator = new QueryArgumentValidator($tag);
|
||||
|
|
@ -37,11 +43,29 @@
|
|||
}
|
||||
|
||||
function toString(){
|
||||
$arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
, '$args->'.$this->argument_name);
|
||||
if($this->operation)
|
||||
$arg = sprintf("\n$%s_argument = new ConditionArgument('%s', %s, '%s');\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
, $this->ignoreValue ? 'null' : '$args->'.$this->argument_name
|
||||
, $this->operation
|
||||
);
|
||||
|
||||
else
|
||||
$arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
, $this->ignoreValue ? 'null' : '$args->'.$this->argument_name);
|
||||
|
||||
|
||||
$arg .= $this->argument_validator->toString();
|
||||
|
||||
if($this->operation){
|
||||
$arg .= sprintf("$%s_argument->createConditionValue();\n"
|
||||
, $this->argument_name
|
||||
);
|
||||
}
|
||||
|
||||
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
|
||||
, $this->argument_name
|
||||
, $this->argument_name
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
$conditions_string = substr($conditions_string, 0, -2);//remove ','
|
||||
$conditions_string .= ')';
|
||||
|
||||
return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ','.$this->pipe : '');
|
||||
return sprintf("new ConditionGroup(%s%s)", $conditions_string, $this->pipe ? ',\''.$this->pipe . '\'': '');
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
|
|
|
|||
|
|
@ -22,11 +22,17 @@
|
|||
$dbParser = XmlQueryParser::getDBParser();
|
||||
$this->column_name = $dbParser->parseColumnName($condition->attrs->column);
|
||||
|
||||
if($condition->attrs->var){
|
||||
$isColumnName = strpos($condition->attrs->default, '.');
|
||||
|
||||
if($condition->attrs->var || $isColumnName === false){
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/queryargument/QueryArgument.class.php');
|
||||
$this->argument_name = $condition->attrs->var;
|
||||
$this->argument = new QueryArgument($condition);
|
||||
//$this->argument_name = $condition->attrs->var;
|
||||
$this->argument = new QueryArgument($condition);
|
||||
$this->argument_name = $this->argument->getArgumentName();
|
||||
}
|
||||
//else if($isColumnName === false){
|
||||
// $this->default_column = $condition->attrs->default;
|
||||
//}
|
||||
else {
|
||||
$this->default_column = $dbParser->parseColumnName($condition->attrs->default);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
if(!is_array($xml_groups)) $xml_groups = array($xml_groups);
|
||||
require_once(_XE_PATH_.'classes/xml/xmlquery/tags/condition/ConditionGroupTag.class.php');
|
||||
foreach($xml_groups as $group){
|
||||
$this->condition_groups[] = new ConditionGroupTag($group->condition, $group->pipe);
|
||||
$this->condition_groups[] = new ConditionGroupTag($group->condition, $group->attrs->pipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toString(){
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@
|
|||
$output .= ')';
|
||||
return $output;
|
||||
}
|
||||
|
||||
function getLimitString(){
|
||||
|
||||
}
|
||||
|
||||
function getArguments(){
|
||||
$arguments = array();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue