* Finish task #111655.

This commit is contained in:
songchenxuan
2024-01-26 16:19:52 +08:00
parent 88acf74613
commit 9e02e33e15
8 changed files with 48 additions and 13 deletions
+3 -2
View File
@@ -263,16 +263,17 @@ class pivot extends control
* @param string $type
* @param string $object
* @param string $field
* @param string $saveAs
* @access public
* @return string
*/
public function ajaxGetSysOptions($type, $object = '', $field = '')
public function ajaxGetSysOptions($type, $object = '', $field = '', $saveAs = '')
{
$sql = isset($_POST['sql']) ? $_POST['sql'] : '';
$filters = isset($_POST['filters']) ? $_POST['filters'] : '';
$sql = $this->loadModel('chart')->parseSqlVars($sql, $filters);
$options = $this->pivot->getSysOptions($type, $object, $field, $sql);
$options = $this->pivot->getSysOptions($type, $object, $field, $sql, $saveAs);
return print(html::select('default[]', array('' => '') + $options, '', "class='form-control form-select picker-select' multiple"));
}
+4 -3
View File
@@ -260,8 +260,9 @@ function initQueryControl(container, filter, object, field)
function initResultControl(container, filter, object, field)
{
var type = filter.type;
var value = filter.default;
var type = filter.type;
var value = filter.default;
var saveAs = 'saveAs' in filter ? filter.saveAs : '';
container.find('.default-block').addClass('hidden');
container.find('.default-block input[name^="default"]').val('');
@@ -307,7 +308,7 @@ function initResultControl(container, filter, object, field)
if(value !== '') pickerOptions.defaultValue = value;
var pivotParams = {sql: pivot.sql, filters: getQueryFilters(pivot)};
$.post(createLink('pivot', 'ajaxGetSysOptions', 'type=' + options + '&object=' + object + '&field=' + field), pivotParams, function(resp)
$.post(createLink('pivot', 'ajaxGetSysOptions', 'type=' + options + '&object=' + object + '&field=' + field + '&saveAs=' + saveAs), pivotParams, function(resp)
{
control.html($(resp).html());
control.picker(pickerOptions);
+1
View File
@@ -225,6 +225,7 @@ $lang->pivot->resultFilter = 'Result Filter';
$lang->pivot->queryFilter = 'Query Filter';
$lang->pivot->noName = 'Unnamed';
$lang->pivot->filterName = 'Name';
$lang->pivot->showAs = 'Show as';
$lang->pivot->default = 'Default';
$lang->pivot->unlimited = 'Unlimited';
$lang->pivot->colon = 'To';
+1
View File
@@ -225,6 +225,7 @@ $lang->pivot->resultFilter = 'Result Filter';
$lang->pivot->queryFilter = 'Query Filter';
$lang->pivot->noName = 'Unnamed';
$lang->pivot->filterName = 'Name';
$lang->pivot->showAs = 'Show as';
$lang->pivot->default = 'Default';
$lang->pivot->unlimited = 'Unlimited';
$lang->pivot->colon = 'To';
+1
View File
@@ -225,6 +225,7 @@ $lang->pivot->resultFilter = 'Result Filter';
$lang->pivot->queryFilter = 'Query Filter';
$lang->pivot->noName = 'Unnamed';
$lang->pivot->filterName = 'Name';
$lang->pivot->showAs = 'Show as';
$lang->pivot->default = 'Default';
$lang->pivot->unlimited = 'Unlimited';
$lang->pivot->colon = 'To';
+1
View File
@@ -213,6 +213,7 @@ $lang->pivot->resultFilter = 'Result Filter';
$lang->pivot->queryFilter = 'Query Filter';
$lang->pivot->noName = 'Unnamed';
$lang->pivot->filterName = 'Name';
$lang->pivot->showAs = 'Show as';
$lang->pivot->default = 'Default';
$lang->pivot->unlimited = 'Unlimited';
$lang->pivot->colon = 'To';
+1
View File
@@ -225,6 +225,7 @@ $lang->pivot->resultFilter = '结果筛选器';
$lang->pivot->queryFilter = '查询筛选器';
$lang->pivot->noName = '未命名';
$lang->pivot->filterName = '名称';
$lang->pivot->showAs = '显示为';
$lang->pivot->default = '默认值';
$lang->pivot->unlimited = '不限';
$lang->pivot->colon = '至';
+36 -8
View File
@@ -2482,7 +2482,7 @@ class pivotModel extends model
* @access public
* @return array
*/
public function getSysOptions($type, $object = '', $field = '', $source = '')
public function getSysOptions($type, $object = '', $field = '', $source = '', $saveAs = '')
{
$options = array('' => '');
switch($type)
@@ -2524,7 +2524,10 @@ class pivotModel extends model
{
$options = array();
foreach($source as $row) $options[$row->id] = $row->$field;
}
elseif($saveAs)
{
$options = $this->getOptionsFromSql($source, $field, $saveAs);
}
else
{
@@ -2538,17 +2541,15 @@ class pivotModel extends model
}
break;
case 'string':
case 'number':
if($field)
{
$options = array();
if(is_string($source) and !empty($source))
{
$cols = $this->dbh->query($source)->fetchAll();
foreach($cols as $col)
{
$data = $col->$field;
$options[$data] = $data;
}
$keyField = $field;
$valueField = $saveAs ? $saveAs : $field;
$options = $this->getOptionsFromSql($source, $keyField, $valueField);
}
else if(is_array($source))
{
@@ -2560,6 +2561,33 @@ class pivotModel extends model
return $options;
}
/**
* Get pairs from column by keyField and valueField.
*
* @param string $sql
* @param string $keyField
* @param string $valueField
* @access public
* @return array
*/
public function getOptionsFromSql($sql, $keyField, $valueField)
{
$options = array();
$cols = $this->dbh->query($sql)->fetchAll();
$sample = current($cols);
if(!isset($sample->$keyField) or !isset($sample->$valueField)) return $options;
foreach($cols as $col)
{
$key = $col->$keyField;
$value = $col->$valueField;
$options[$key] = $value;
}
return $options;
}
/**
* Get tree of pivots and groups.
*