Merge branch ztflow-qixinzhi-feature/task-report#qixinzhi of zentao/zentaopms (#9498)

This commit is contained in:
刘刚
2025-06-13 14:55:54 +08:00
committed by Gitfox
3 changed files with 69 additions and 9 deletions
+11 -9
View File
@@ -350,17 +350,19 @@ class screenModel extends model
public function setValueByPath(object &$option, string $path, mixed $value): void
{
$keys = explode('.', $path);
$keyCount = count($keys);
$current = &$option;
foreach ($keys as $key) {
if(is_numeric($key))
{
if(!isset($current[$key])) $current[$key] = array();
}
else
{
if(!isset($current->$key)) $current->$key = new stdclass();
}
foreach ($keys as $index => $key)
{
$isEnd = ($index + 1) >= $keyCount;
$nextKey = $isEnd ? null : $keys[$index + 1];
$isArray = is_numeric($key);
$nextIsArray = is_numeric($nextKey);
if($isArray && !isset($current[$key])) $current[$key] = $nextIsArray ? array() : new stdclass();
if(!$isArray && !isset($current->$key)) $current->$key = $nextIsArray ? array() : new stdclass();
if (is_array($current)) {
$current = &$current[$key];
@@ -431,6 +431,20 @@ class screenTest
return $this->objectModel->filter;
}
/**
* Test set value by path.
*
* @param object $option
* @param string $path
* @param string $value
* @access public
* @return void
*/
public function setValueByPathTest(object &$option, string $path, mixed $value): void
{
$this->objectModel->setValueByPath($option, $path, $value);
}
/**
* 初始化过滤条件。
* Initialize filter conditions.
@@ -0,0 +1,44 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/screen.unittest.class.php';
/**
title=测试 screenModel->setValueByPath();
timeout=0
cid=1
- 测试title.show=true @1
- 测试series.0.color.0.colorStops.0.offset=1 @1
- 测试series.0.color.0.x=#fff @#fff
- 测试series.0.color.1.y=#000 @#000
- 测试series.0.0.name=data @data
*/
$screen = new screenTest();
$paths = array
(
'title.show',
'series.0.color.0.colorStops.0.offset',
'series.0.color.0.x',
'series.0.color.1.y',
'series.0.0.name',
);
$options = new stdclass();
$screen->setValueByPathTest($options, $paths[0], true);
$screen->setValueByPathTest($options, $paths[1], 1);
$screen->setValueByPathTest($options, $paths[2], '#fff');
$screen->setValueByPathTest($options, $paths[3], '#000');
r($options->title->show) && p('') && e("1"); //测试title.show=true
r($options->series[0]->color[0]->colorStops[0]->offset) && p('') && e("1"); //测试series.0.color.0.colorStops.0.offset=1
r($options->series[0]->color[0]->x) && p('') && e("#fff"); //测试series.0.color.0.x=#fff
r($options->series[0]->color[1]->y) && p('') && e("#000"); //测试series.0.color.1.y=#000
$options = new stdclass();
$screen->setValueByPathTest($options, $paths[4], 'data');
r($options->series[0][0]->name) && p('') && e("data"); //测试series.0.0.name=data