Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
lightCMS
提交
ff475e4e
L
lightCMS
项目概览
OpenDocCN
/
lightCMS
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
lightCMS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ff475e4e
编写于
3月 11, 2020
作者:
E
eddy8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add: 多选表单类型(selectMulti)选择 unsignedInteger 数据类型时多个选择值求和保存
上级
39131c7d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
11 deletion
+35
-11
app/Http/Controllers/Admin/ContentController.php
app/Http/Controllers/Admin/ContentController.php
+2
-2
app/Repository/Admin/ContentRepository.php
app/Repository/Admin/ContentRepository.php
+18
-7
app/functions.php
app/functions.php
+5
-0
resources/views/admin/content/add.blade.php
resources/views/admin/content/add.blade.php
+10
-2
未找到文件。
app/Http/Controllers/Admin/ContentController.php
浏览文件 @
ff475e4e
...
...
@@ -125,7 +125,7 @@ class ContentController extends Controller
$content
=
ContentRepository
::
add
(
$request
->
only
(
EntityFieldRepository
::
getSaveFields
(
$entity
)
));
)
,
$this
->
entity
);
// 标签类型字段另外处理 多对多关联
$inputTagsField
=
EntityFieldRepository
::
getInputTagsField
(
$entity
);
...
...
@@ -203,7 +203,7 @@ class ContentController extends Controller
try
{
DB
::
beginTransaction
();
ContentRepository
::
update
(
$id
,
$data
);
ContentRepository
::
update
(
$id
,
$data
,
$this
->
entity
);
// 标签类型字段另外处理 多对多关联
$inputTagsField
=
EntityFieldRepository
::
getInputTagsField
(
$entity
);
$tags
=
null
;
...
...
app/Repository/Admin/ContentRepository.php
浏览文件 @
ff475e4e
...
...
@@ -7,6 +7,8 @@ namespace App\Repository\Admin;
use
App\Model\Admin\Content
;
use
App\Model\Admin\ContentTag
;
use
App\Model\Admin\Entity
;
use
App\Model\Admin\EntityField
;
use
App\Repository\Searchable
;
/**
...
...
@@ -46,15 +48,15 @@ class ContentRepository
];
}
public
static
function
add
(
$data
)
public
static
function
add
(
$data
,
Entity
$entity
)
{
self
::
$model
->
setRawAttributes
(
self
::
processParams
(
$data
))
->
save
();
self
::
$model
->
setRawAttributes
(
self
::
processParams
(
$data
,
$entity
))
->
save
();
return
self
::
$model
;
}
public
static
function
update
(
$id
,
$data
)
public
static
function
update
(
$id
,
$data
,
Entity
$entity
)
{
return
self
::
$model
->
newQuery
()
->
where
(
'id'
,
$id
)
->
update
(
self
::
processParams
(
$data
));
return
self
::
$model
->
newQuery
()
->
where
(
'id'
,
$id
)
->
update
(
self
::
processParams
(
$data
,
$entity
));
}
public
static
function
find
(
$id
)
...
...
@@ -83,15 +85,24 @@ class ContentRepository
return
self
::
$model
;
}
protected
static
function
processParams
(
$data
)
protected
static
function
processParams
(
$data
,
Entity
$entity
)
{
return
array_map
(
function
(
$item
)
{
return
collect
(
$data
)
->
map
(
function
(
$item
,
$key
)
use
(
$entity
)
{
if
(
is_array
(
$item
))
{
return
implode
(
','
,
$item
);
}
elseif
(
preg_match
(
'/^\d+(,\d+)*/'
,
$item
))
{
// select多选类型表单,数据类型为 unsignedInteger 的求和保存,查询时可以利用 AND 运算查找对应值
$fieldType
=
EntityField
::
where
(
'entity_id'
,
$entity
->
id
)
->
where
(
'form_type'
,
'selectMulti'
)
->
where
(
'name'
,
$key
)
->
value
(
'type'
);
if
(
$fieldType
==
'unsignedInteger'
)
{
return
array_sum
(
explode
(
','
,
$item
));
}
return
$item
;
}
else
{
return
$item
;
}
}
,
$data
);
}
)
->
toArray
(
);
}
public
static
function
adjacent
(
$id
)
...
...
app/functions.php
浏览文件 @
ff475e4e
...
...
@@ -36,6 +36,11 @@ function isChecked($value, $options)
return
in_array
(
$value
,
explode
(
','
,
$options
),
true
);
}
function
isCheckedByAnd
(
$value
,
$options
)
{
return
(
$options
&
$value
)
==
$value
;
}
function
xssFilter
(
$data
)
{
if
(
is_string
(
$data
))
{
...
...
resources/views/admin/content/add.blade.php
浏览文件 @
ff475e4e
...
...
@@ -99,7 +99,11 @@
<
div
class
=
"layui-input-inline"
style
=
"width: 380px;z-index: {{99999 - (
$field->order
+
$field->id
)}}"
>
<
select
xm
-
select
-
search
xm
-
select
=
"select-{{
$inlineField->name
}}"
name
=
"{{
$inlineField->name
}}"
@
if
(
$inlineField
->
is_required
==
\
App\Model\Admin\EntityField
::
REQUIRED_ENABLE
)
required
lay
-
verify
=
"required"
@
endif
@
if
(
isset
(
$model
)
&&
$inlineField
->
is_edit
==
\
App\Model\Admin\EntityField
::
EDIT_DISABLE
)
disabled
@
endif
>
@
foreach
(
parseEntityFieldParams
(
$inlineField
->
form_params
)
as
$v
)
<
option
value
=
"{{
$v[0]
}}"
@
if
((
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$model
->
{
$inlineField
->
name
}))
||
(
!
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$inlineField
->
form_default_value
)))
selected
@
endif
>
{{
$v
[
1
]
}}
</
option
>
@
if
(
$inlineField
->
type
==
'unsignedInteger'
)
<
option
value
=
"{{
$v[0]
}}"
@
if
((
isset
(
$model
)
&&
isCheckedByAnd
(
$v
[
0
],
$model
->
{
$inlineField
->
name
}))
||
(
!
isset
(
$model
)
&&
isCheckedByAnd
(
$v
[
0
],
$inlineField
->
form_default_value
)))
selected
@
endif
>
{{
$v
[
1
]
}}
</
option
>
@
else
<
option
value
=
"{{
$v[0]
}}"
@
if
((
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$model
->
{
$inlineField
->
name
}))
||
(
!
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$inlineField
->
form_default_value
)))
selected
@
endif
>
{{
$v
[
1
]
}}
</
option
>
@
endif
@
endforeach
</
select
>
</
div
>
...
...
@@ -427,7 +431,11 @@
<
div
class
=
"layui-input-block"
style
=
"width: 600px;z-index: {{99999 - (
$field->order
+
$field->id
)}}"
>
<
select
xm
-
select
-
search
xm
-
select
=
"select-{{
$field->name
}}"
name
=
"{{
$field->name
}}"
@
if
(
$field
->
is_required
==
\
App\Model\Admin\EntityField
::
REQUIRED_ENABLE
)
required
lay
-
verify
=
"required"
@
endif
@
if
(
isset
(
$model
)
&&
$field
->
is_edit
==
\
App\Model\Admin\EntityField
::
EDIT_DISABLE
)
disabled
@
endif
>
@
foreach
(
parseEntityFieldParams
(
$field
->
form_params
)
as
$v
)
<
option
value
=
"{{
$v[0]
}}"
@
if
((
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$model
->
{
$field
->
name
}))
||
(
!
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$field
->
form_default_value
)))
selected
@
endif
>
{{
$v
[
1
]
}}
</
option
>
@
if
(
$field
->
type
==
'unsignedInteger'
)
<
option
value
=
"{{
$v[0]
}}"
@
if
((
isset
(
$model
)
&&
isCheckedByAnd
(
$v
[
0
],
$model
->
{
$field
->
name
}))
||
(
!
isset
(
$model
)
&&
isCheckedByAnd
(
$v
[
0
],
$field
->
form_default_value
)))
selected
@
endif
>
{{
$v
[
1
]
}}
</
option
>
@
else
<
option
value
=
"{{
$v[0]
}}"
@
if
((
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$model
->
{
$field
->
name
}))
||
(
!
isset
(
$model
)
&&
isChecked
(
$v
[
0
],
$field
->
form_default_value
)))
selected
@
endif
>
{{
$v
[
1
]
}}
</
option
>
@
endif
@
endforeach
</
select
>
</
div
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录