mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
git-svn-id: http://xe-core.googlecode.com/svn/trunk@1103 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
60ebbe4e02
commit
94c12ff8bf
6 changed files with 386 additions and 409 deletions
|
|
@ -10,78 +10,255 @@
|
|||
|
||||
class XmlQueryParser extends XmlParser {
|
||||
|
||||
/**
|
||||
* @brief 조건문에서 조건을 등호로 표시하는 변수
|
||||
**/
|
||||
var $cond_operation = array(
|
||||
'equal' => '=',
|
||||
'more' => '>=',
|
||||
'excess' => '>',
|
||||
'less' => '<=',
|
||||
'below' => '<',
|
||||
'notequal' => '!=',
|
||||
'notnull' => 'is not null',
|
||||
'null' => 'is null',
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief 쿼리 파일을 찾아서 파싱하고 캐싱한다
|
||||
**/
|
||||
function parse($query_id, $xml_file, $cache_file) {
|
||||
// query xml 파일을 찾아서 파싱, 결과가 없으면 return
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$buff = FileHandler::readFile($xml_file);
|
||||
$xml_obj = parent::parse($buff);
|
||||
if(!$xml_obj) return;
|
||||
unset($buff);
|
||||
|
||||
// 쿼리 스크립트를 만들때 필요한 변수들
|
||||
$filter_script = $notnull_script = $column_script = $default_script = '';
|
||||
list($module, $id) = explode('.',$query_id);
|
||||
|
||||
// insert, update, delete, select등의 action
|
||||
$action = strtolower($xml_obj->query->attrs->action);
|
||||
if(!$action) return;
|
||||
|
||||
// 테이블 정리 (배열코드로 변환)
|
||||
$tables = $this->_getTablesScript($xml_obj);
|
||||
$tables = $xml_obj->query->tables->table;
|
||||
if(!$tables) return;
|
||||
if(!is_array($tables)) $tables = array($tables);
|
||||
foreach($tables as $key => $val) {
|
||||
// 테이블과 alias의 이름을 구함
|
||||
$table_name = $val->attrs->name;
|
||||
$alias = $val->attrs->alias;
|
||||
if(!$alias) $alias = $table_name;
|
||||
|
||||
$output->tables[$table_name] = $alias;
|
||||
|
||||
// 테이블을 찾아서 컬럼의 속성을 구함
|
||||
$table_file = sprintf('./modules/%s/schemas/%s.xml', $module, $table_name);
|
||||
$table_xml = FileHandler::readFile($table_file);
|
||||
$table_obj = parent::parse($table_xml);
|
||||
if($table_obj->table) {
|
||||
foreach($table_obj->table->column as $k => $v) {
|
||||
$buff .= sprintf('$output->column_type["%s"] = "%s";%s', $v->attrs->name, $v->attrs->type, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
$column_script = $this->_getColumnsScript($xml_obj, $default_script, $notnull_script, $filter_script, $action);
|
||||
$columns = $xml_obj->query->columns->column;
|
||||
if(!$columns) {
|
||||
$output->column[] = array("*" => "*");
|
||||
} else {
|
||||
if(!is_array($columns)) $columns = array($columns);
|
||||
foreach($columns as $key => $val) {
|
||||
$name = $val->attrs->name;
|
||||
/*
|
||||
if(strpos('.',$name)===false && count($output->tables)==1) {
|
||||
$tmp = array_values($output->tables);
|
||||
$name = sprintf('%s.%s', $tmp[0], $val->attrs->name);
|
||||
}
|
||||
*/
|
||||
|
||||
$output->columns[] = array(
|
||||
"name" => $name,
|
||||
"var" => $val->attrs->var,
|
||||
"default" => $val->attrs->default,
|
||||
"notnull" => $val->attrs->notnull,
|
||||
"filter" => $val->attrs->filter,
|
||||
"minlength" => $val->attrs->minlength,
|
||||
"maxlength" => $val->attrs->maxlength,
|
||||
"alias" => $val->attrs->alias,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
$condition_script = $this->_getConditionScript($xml_obj, $default_script, $notnull_script, $filter_script);
|
||||
$conditions = $xml_obj->query->conditions;
|
||||
|
||||
$condition = $conditions->condition;
|
||||
if($condition) {
|
||||
$obj->condition = $condition;
|
||||
unset($condition);
|
||||
$condition = array($obj);
|
||||
}
|
||||
|
||||
$condition_group = $conditions->group;
|
||||
if($condition_group && !is_array($condition_group)) $condition_group = array($condition_group);
|
||||
|
||||
if($condition && $condition_group) $cond = array_merge($condition, $condition_group);
|
||||
elseif($condition_group) $cond = $condition_group;
|
||||
else $cond = $condition;
|
||||
|
||||
if($cond) {
|
||||
foreach($cond as $key => $val) {
|
||||
unset($cond_output);
|
||||
|
||||
if($val->attrs->pipe) $cond_output->pipe = $val->attrs->pipe;
|
||||
else $cond_output->pipe = null;
|
||||
|
||||
if(!$val->condition) continue;
|
||||
if(!is_array($val->condition)) $val->condition = array($val->condition);
|
||||
|
||||
foreach($val->condition as $k => $v) {
|
||||
$obj = $v->attrs;
|
||||
if(!$obj->alias) $obj->alias = $obj->column;
|
||||
$cond_output->condition[] = $obj;
|
||||
}
|
||||
|
||||
$output->conditions[] = $cond_output;
|
||||
}
|
||||
}
|
||||
|
||||
// group 정리
|
||||
$group_script = $this->_getGroupScript($xml_obj);
|
||||
$groups = $xml_obj->query->groups->group;
|
||||
if($groups) {
|
||||
if(!is_array($group_list)) $group_list = array($group_list);
|
||||
for($i=0;$i<count($group_list);$i++) {
|
||||
$group = $group_list[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
$group_column_list[] = $column;
|
||||
}
|
||||
if(count($group_column_list)) $output->groups = $group_column_list;
|
||||
}
|
||||
|
||||
// 네비게이션 정리
|
||||
$navigation_script = $this->_getNavigationScript($xml_obj);
|
||||
$navigation = $xml_obj->query->navigation;
|
||||
if($navigation) {
|
||||
$order = $navigation->index;
|
||||
if($order) {
|
||||
if(!is_array($order)) $order = array($order);
|
||||
foreach($order as $order_info) {
|
||||
$output->order[] = $order_info->attrs;
|
||||
}
|
||||
}
|
||||
|
||||
// 캐쉬 내용 작성
|
||||
$buff =
|
||||
sprintf(
|
||||
'<?php if(!defined("__ZBXE__")) exit();'."\n".
|
||||
'$pass_quotes = array();'."\n".
|
||||
'$id = \'%s\';'."\n".
|
||||
'$action = \'%s\';'."\n".
|
||||
'$tables = array(%s);'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'%s'."\n".
|
||||
'$group_script = \'%s\''."\n".
|
||||
'?>',
|
||||
$query_id,
|
||||
$action,
|
||||
$tables,
|
||||
$default_script,
|
||||
$column_script,
|
||||
$notnull_script,
|
||||
$filter_script,
|
||||
$condition_script,
|
||||
$navigation_script,
|
||||
$group_script
|
||||
);
|
||||
$list_count = $navigation->list_count->attrs;
|
||||
$output->list_count = $list_count;
|
||||
|
||||
$page_count = $navigation->page_count->attrs;
|
||||
$output->page_count = $page_count;
|
||||
|
||||
$page = $navigation->page->attrs;
|
||||
$output->page = $page ;
|
||||
}
|
||||
|
||||
$column_count = count($output->columns);
|
||||
$condition_count = count($output->conditions);
|
||||
|
||||
// php script 생성
|
||||
|
||||
// table 정리
|
||||
$buff .= '$output->tables = array( ';
|
||||
foreach($output->tables as $key => $val) {
|
||||
$buff .= sprintf('"%s"=>"%s",', $key, $val);
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
|
||||
// column 정리
|
||||
if($column_count) {
|
||||
$buff .= '$output->columns = array ( ';
|
||||
foreach($output->columns as $key => $val) {
|
||||
$val['default'] = $this->getDefault($val['name'], $val['default']);
|
||||
if($val['var']) {
|
||||
$buff .= sprintf('array("name"=>"%s", "value"=>$args->%s?$args->%s:%s),%s', $val['name'], $val['var'], $val['var'], $val['default'] ,"\n");
|
||||
if($val['notnull']) $notnull_list[] = $val['var'];
|
||||
if($val['minlength']) $minlength_list[$val['var']] = $val['minlength'];
|
||||
if($val['maxlength']) $maxlength_list[$val['var']] = $val['maxlength'];
|
||||
} else {
|
||||
$buff .= sprintf('array("name"=>"%s", "value"=>%s),%s', $val['name'], $val['default'] ,"\n");
|
||||
}
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
}
|
||||
|
||||
// conditions 정리
|
||||
if($condition_count) {
|
||||
$buff .= '$output->conditions = array ( ';
|
||||
foreach($output->conditions as $key => $val) {
|
||||
$buff .= sprintf('array("pipe"=>"%s",%s"condition"=>array(', $val->pipe,"\n");
|
||||
foreach($val->condition as $k => $v) {
|
||||
$v->default = $this->getDefault($v->column, $v->default);
|
||||
if($v->var) {
|
||||
if(strpos($v->var,".")===false) {
|
||||
if($v->filter) $filter_list[] = $v;
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n");
|
||||
} else {
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
|
||||
}
|
||||
} else {
|
||||
$buff .= sprintf('array("name"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->name, $v->default ,$v->pipe, $v->operation,"\n");
|
||||
}
|
||||
}
|
||||
$buff .= ')),'."\n";
|
||||
}
|
||||
|
||||
$buff .= ' );'."\n";
|
||||
}
|
||||
|
||||
// order 정리
|
||||
if($output->order) {
|
||||
$buff .= '$output->order = array(';
|
||||
foreach($output->order as $key => $val) {
|
||||
$buff .= sprintf('"%s"=>"%s",', $val->var, $val->order);
|
||||
}
|
||||
$buff .= ');'."\n";
|
||||
}
|
||||
|
||||
// list_count 정리
|
||||
if($output->list_count) {
|
||||
$buff .= sprintf('$output->list_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->list_count->var, $output->list_count->var, $output->list_count->var, $output->list_count->default,"\n");
|
||||
}
|
||||
|
||||
// page_count 정리
|
||||
if($output->page_count) {
|
||||
$buff .= sprintf('$output->page_count = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page_count->var, $output->page_count->var, $output->page_count->var, $output->list_count->default,"\n");
|
||||
}
|
||||
|
||||
// page 정리
|
||||
if($output->page) {
|
||||
$buff .= sprintf('$output->page = array("var"=>"%s", "value"=>$args->%s?$args->%s:"%s");%s', $output->page->var, $output->page->var, $output->page->var, $output->list->default,"\n");
|
||||
}
|
||||
|
||||
// not null check
|
||||
if(count($notnull_list)) {
|
||||
foreach($notnull_list as $key => $val) {
|
||||
$pre_buff .= 'if(!$args->'.$val.') return new Object(-1, sprintf($lang->filter->isnull, $lang->'.$val.'?$lang->'.$val.':\''.$val.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// minlength check
|
||||
if(count($minlength_list)) {
|
||||
foreach($minlength_list as $key => $val) {
|
||||
$pre_buff .= 'if(strlen($args->'.$key.')<'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// maxlength check
|
||||
if(count($maxlength_list)) {
|
||||
foreach($maxlength_list as $key => $val) {
|
||||
$pre_buff .= 'if(strlen($args->'.$key.')>'.$val.') return new Object(-1, sprintf($lang->filter->outofrange, $lang->'.$key.'?$lang->'.$key.':\''.$key.'\'));'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// filter check
|
||||
if(count($filter_list)) {
|
||||
foreach($filter_list as $key => $val) {
|
||||
$pre_buff .= sprintf('unset($output); $output = $this->_checkFilter("%s",$args->%s,"%s"); if(!$output->toBool()) return $output;%s',$val->var,$val->var,$val->filter,"\n");
|
||||
}
|
||||
}
|
||||
|
||||
$buff = "<?php if(!defined('__ZBXE__')) exit();\n"
|
||||
. sprintf('$output->query_id = "%s";%s', $query_id, "\n")
|
||||
. sprintf('$output->action = "%s";%s', $action, "\n")
|
||||
. $pre_buff
|
||||
. $buff
|
||||
. 'return $output; ?>';
|
||||
|
||||
// 저장
|
||||
FileHandler::writeFile($cache_file, $buff);
|
||||
|
|
@ -90,17 +267,16 @@
|
|||
/**
|
||||
* @brief column, condition등의 key에 default 값을 세팅
|
||||
**/
|
||||
function _getDefaultCode($name, $value) {
|
||||
if($value == NULL) return;
|
||||
if(substr($value, -1)!=')') return sprintf('if(!$args->%s) $args->%s = \'%s\';'."\n", $name, $name, $value);
|
||||
|
||||
function getDefault($name, $value) {
|
||||
$str_pos = strpos($value, '(');
|
||||
if($str_pos===false) return '"'.$value.'"';
|
||||
|
||||
$func_name = substr($value, 0, $str_pos);
|
||||
$args = substr($value, $str_pos+1, strlen($value)-1);
|
||||
|
||||
switch($func_name) {
|
||||
case 'ipaddress' :
|
||||
$val = '\''.$_SERVER['REMOTE_ADDR'].'\'';
|
||||
$val = '"$_SERVER[\'REMOTE_ADDR\']"';
|
||||
break;
|
||||
case 'unixtime' :
|
||||
$val = 'time()';
|
||||
|
|
@ -113,257 +289,16 @@
|
|||
break;
|
||||
case 'plus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s+%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
$val = sprintf('%s+%d', $name, $args);
|
||||
break;
|
||||
case 'minus' :
|
||||
$args = abs($args);
|
||||
$val = sprintf('\'%s-%d\'', $name, $args);
|
||||
$pass_quotes = true;
|
||||
$val = sprintf('%s-%d', $name, $args);
|
||||
break;
|
||||
}
|
||||
|
||||
$output = sprintf('if(!$args->%s) $args->%s = %s;'."\n", $name, $name, $val);
|
||||
if($pass_quotes) $output .= sprintf('$pass_quotes[] = \'%s\';'."\n",$name);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 필터 체크
|
||||
**/
|
||||
function _getFilterCode($key, $type, $minlength, $maxlength, $var='column', $notnull='') {
|
||||
if(!$type||!$minlength||!$maxlength) return;
|
||||
if(!$notnull) $notnull_code = sprintf('if($%s->%s) ', $var, $key);
|
||||
|
||||
return
|
||||
sprintf(
|
||||
'unset($output); %s$output = $this->_checkFilter(\'%s\', $%s->%s, \'%s\', \'%d\', \'%d\'); if(!$output->toBool()) return $output;'."\n",
|
||||
$notnull_code,
|
||||
$key,
|
||||
$var,
|
||||
$key,
|
||||
$type,
|
||||
(int)$minlength,
|
||||
(int)$maxlength
|
||||
);
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief not null 체크된 항목에 대한 처리
|
||||
**/
|
||||
function _getNotNullCode($name, $var='column') {
|
||||
return
|
||||
sprintf(
|
||||
'if(!$%s->%s) return new Object(-1, sprintf($lang->filter->isnull, $lang->%s?$lang->%s:\'%s\'));'."\n",
|
||||
$var,
|
||||
$name,
|
||||
$name,
|
||||
$name,
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 대상 테이블에 대한 처리
|
||||
**/
|
||||
function _getTablesScript($xml_obj) {
|
||||
$obj_tables = $xml_obj->query->tables->table;
|
||||
if(!is_array($obj_tables)) $obj_tables = array('', $obj_tables);
|
||||
|
||||
foreach($obj_tables as $table_info) {
|
||||
$name = trim($table_info->attrs->name);
|
||||
if(!$name) continue;
|
||||
$alias = trim($table_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$table_list[] = sprintf('\'%s\'=>\'%s\'', $name, $alias);
|
||||
}
|
||||
return implode(",",$table_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 컬럼 처리
|
||||
**/
|
||||
function _getColumnsScript($xml_obj, &$default_script, &$notnull_script, &$filter_script, $action) {
|
||||
$obj_columns = $xml_obj->query->columns->column;
|
||||
if(!is_array($obj_columns)) $obj_columns = array('', $obj_columns);
|
||||
|
||||
foreach($obj_columns as $column_info) {
|
||||
$name = trim($column_info->attrs->name);
|
||||
if(!$name || $name == '*') continue;
|
||||
|
||||
$var = trim($column_info->attrs->var);
|
||||
$alias = trim($column_info->attrs->alias);
|
||||
if(!$alias) $alias = $name;
|
||||
$default = trim($column_info->attrs->default);
|
||||
$notnull = trim($column_info->attrs->notnull);
|
||||
|
||||
$filter_type = trim($column_info->attrs->filter);
|
||||
$minlength = (int)trim($column_info->attrs->minlength);
|
||||
$maxlength = (int)trim($column_info->attrs->maxlength);
|
||||
|
||||
$column_script .= sprintf('$column->%s = $args->%s;'."\n", $alias, $var?$var:$alias);
|
||||
$invert_columns[] = sprintf('\'%s\'=>\'%s\'', $alias, $name);
|
||||
|
||||
$default_script .= $this->_getDefaultCode($alias, $default);
|
||||
if($action != 'select') {
|
||||
if($filter_type) $filter_script .= $this->_getFilterCode($alias, $filter_type, $minlength, $maxlength, 'column', $notnull);
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($alias);
|
||||
}
|
||||
}
|
||||
if(is_array($invert_columns)) $column_script .= sprintf('$invert_columns = array(%s);'."\n", implode(',',$invert_columns));
|
||||
return $column_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 조건절 처리
|
||||
**/
|
||||
function _getConditionScript($xml_obj, &$default_script, &$notnull_script, &$filter_script) {
|
||||
$cond_idx = 0;
|
||||
|
||||
$obj_conditions = $xml_obj->query->conditions->condition;
|
||||
|
||||
$condition_script = $condition = $this->_getConditionQuery($cond_idx++, $obj_conditions, NULL, $notnull_script, $filter_script);
|
||||
|
||||
$obj_groups = $xml_obj->query->conditions->group;
|
||||
if(!is_array($obj_groups)) $obj_groups = array('', $obj_groups);
|
||||
|
||||
foreach($obj_groups as $obj_group) {
|
||||
$group_pipe = $obj_group->attrs->pipe;
|
||||
if(!$group_pipe) continue;
|
||||
$buff = $this->_getConditionQuery($cond_idx++, $obj_group->condition, $group_pipe, $notnull_script, $filter_script);
|
||||
$condition_script .= $buff;
|
||||
}
|
||||
|
||||
$condition_script .= '$condition = $this->_combineCondition($cond_group, $group_pipe);'."\n";
|
||||
return $condition_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 조건문의 쿼리를 만들어 줌
|
||||
**/
|
||||
function _getConditionQuery($cond_idx, $obj, $group_pipe, &$notnull_script, &$filter_script) {
|
||||
if(!is_array($obj)) $obj = array('', $obj);
|
||||
|
||||
$idx = 0;
|
||||
foreach($obj as $obj_cond) {
|
||||
$operation = $obj_cond->attrs->operation;
|
||||
if(!$operation) continue;
|
||||
|
||||
$column = $obj_cond->attrs->column;
|
||||
$var = $obj_cond->attrs->var;
|
||||
$filter = $obj_cond->attrs->filter;
|
||||
$notnull = $obj_cond->attrs->notnull;
|
||||
$pipe = $obj_cond->attrs->pipe;
|
||||
if(!$pipe) $pipe = 'and';
|
||||
$default = $obj_cond->attrs->default;
|
||||
|
||||
// 비교 대상이 다른 혹은 같은 테이블의 column일 경우
|
||||
if(eregi("\.", $var)) {
|
||||
switch($operation) {
|
||||
case 'in' :
|
||||
$buff = sprintf('%s in (%s)', $column, $var);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if(!$operation) $operation = 'and';
|
||||
$buff = sprintf('%s %s %s', $column, $operation, $var);
|
||||
break;
|
||||
}
|
||||
$condition_script .= sprintf('$cond_group[%d][][\'%s\'] = \'%s\';'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
// 입력받을 변수일 경우
|
||||
} else {
|
||||
switch($operation) {
|
||||
case 'like' :
|
||||
$buff = sprintf('sprintf("%s like \'%%%%%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'like_prefix' :
|
||||
$buff = sprintf('sprintf("%s like \'%%s%%%%\' ", $this->addQuotes($args->%s))', $column, $var);
|
||||
break;
|
||||
case 'in' :
|
||||
//$buff = sprintf('sprintf("%s in (%%s) ", $this->addQuotes($args->%s))', $column, $var);
|
||||
$buff = sprintf('sprintf("%s in (%%s) ", $args->%s)', $column, $var);
|
||||
break;
|
||||
case 'notnull' :
|
||||
case 'null' :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
unset($var);
|
||||
$buff = sprintf('"%s %s "', $column, $operation);
|
||||
break;
|
||||
default :
|
||||
$operation = $this->cond_operation[$operation];
|
||||
if($default) $buff = sprintf('sprintf("%s %s \'%%s\' ", $args->%s?$this->addQuotes($args->%s):\'%s\')', $column, $operation, $var?$var:$column, $var?$var:$column, $default);
|
||||
else $buff = sprintf('sprintf("%s %s \'%%s\' ", $this->addQuotes($args->%s))', $column, $operation, $var?$var:$column);
|
||||
break;
|
||||
}
|
||||
|
||||
$buff = sprintf('$cond_group[%d][][\'%s\'] = %s;'."\n",$cond_idx, $pipe, $buff);
|
||||
|
||||
if(!$notnull && $var) $buff = sprintf('if($args->%s) ', $var).$buff;
|
||||
$condition_script .= $buff;
|
||||
if($notnull) $notnull_script .= $this->_getNotNullCode($var?$var:$column, 'args');
|
||||
if($filter) $filter_script .= $this->_getFilterCode($var, $filter, 0, 0, 'args', $notnull);
|
||||
}
|
||||
}
|
||||
$condition_script .= sprintf('$group_pipe[%d] = \'%s\';'."\n", $cond_idx, $group_pipe);
|
||||
return $condition_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief group by 쿼리 처리
|
||||
**/
|
||||
function _getGroupScript($xml_obj) {
|
||||
$group_list = $xml_obj->query->groups->group;
|
||||
if(!$group_list) return;
|
||||
if(!is_array($group_list)) $group_list = array($group_list);
|
||||
for($i=0;$i<count($group_list);$i++) {
|
||||
$group = $group_list[$i];
|
||||
$column = trim($group->attrs->column);
|
||||
if(!$column) continue;
|
||||
$group_column_list[] = $column;
|
||||
}
|
||||
|
||||
if(count($group_column_list)) {
|
||||
return ' GROUP BY '.implode(" , ", $group_column_list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief page navigation 처리
|
||||
**/
|
||||
function _getNavigationScript($xml_obj) {
|
||||
$obj_navigation = $xml_obj->query->navigation;
|
||||
if(!$obj_navigation) return;
|
||||
|
||||
$obj_index = $obj_navigation->index->attrs;
|
||||
$index_list = array();
|
||||
if(!is_array($obj_index)) $obj_index = array('', $obj_index);
|
||||
foreach($obj_index as $index_info) {
|
||||
$var = trim($index_info->var);
|
||||
if(!$var) continue;
|
||||
$default = trim($index_info->default);
|
||||
$order = trim($index_info->order);
|
||||
if(!$order) $order = 'asc';
|
||||
|
||||
$navigation_script .= sprintf('$navigation->index[] = array($args->%s?$args->%s:\'%s\', \'%s\');'."\n", $var, $var, $default, $order);
|
||||
}
|
||||
|
||||
$obj_list_count = $obj_navigation->list_count->attrs;
|
||||
$count_var = $obj_list_count->var;
|
||||
$count_default = $obj_list_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->list_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
|
||||
$obj_page_count = $obj_navigation->page_count->attrs;
|
||||
$count_var = $obj_page_count->var;
|
||||
$count_default = $obj_page_count->default;
|
||||
if($count_var) $navigation_script .= sprintf('$navigation->page_count = $args->%s?$args->%s%s;'."\n", $count_var, $count_var, $count_default?':'.$count_default:'');
|
||||
|
||||
$obj_page = $obj_navigation->page->attrs;
|
||||
$page_var = $obj_page->var;
|
||||
$page_default = $obj_page->default;
|
||||
if($page_var) $navigation_script .= sprintf('$navigation->page = $args->%s?$args->%s%s;'."\n", $page_var, $page_var, $page_default?':'.$page_default:'');
|
||||
|
||||
return $navigation_script;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue