Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
afef1d9c
Commit
afef1d9c
authored
May 29, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mvc) add filters to model relations
parent
d5b9c78b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
20 deletions
+53
-20
ModelRelationField.php
...pp/models/OPNsense/Base/FieldTypes/ModelRelationField.php
+53
-20
No files found.
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
View file @
afef1d9c
...
@@ -45,7 +45,12 @@ class ModelRelationField extends BaseField
...
@@ -45,7 +45,12 @@ class ModelRelationField extends BaseField
/**
/**
* @var array collected options
* @var array collected options
*/
*/
private
static
$internalOptionList
=
null
;
private
static
$internalOptionList
=
array
();
/**
* @var string cache relations
*/
private
$internalCacheKey
=
""
;
/**
/**
* Set model as reference list, use uuid's as key
* Set model as reference list, use uuid's as key
...
@@ -53,24 +58,45 @@ class ModelRelationField extends BaseField
...
@@ -53,24 +58,45 @@ class ModelRelationField extends BaseField
*/
*/
public
function
setModel
(
$mdlStructure
)
public
function
setModel
(
$mdlStructure
)
{
{
if
(
!
is_array
(
self
::
$internalOptionList
))
{
// only handle array type input
self
::
$internalOptionList
=
array
();
if
(
!
is_array
(
$mdlStructure
))
{
if
(
is_array
(
$mdlStructure
))
{
return
;
foreach
(
$mdlStructure
as
$modelData
)
{
}
if
(
array_key_exists
(
"source"
,
$modelData
))
{
$className
=
str_replace
(
"."
,
"
\\
"
,
$modelData
[
'source'
]);
// set internal key for this node based on sources and filter criteria
$modelObj
=
new
$className
;
$this
->
internalCacheKey
=
md5
(
serialize
(
$mdlStructure
));
if
(
array_key_exists
(
"items"
,
$modelData
))
{
foreach
(
$modelObj
->
getNodeByReference
(
$modelData
[
'items'
])
->
__items
as
$node
)
{
// only collect options once per source/filter combination, we use a static to save our unique option
$displayKey
=
$modelData
[
'display'
];
// combinations over the running application.
if
(
array_key_exists
(
"uuid"
,
$node
->
getAttributes
())
&&
$node
->
$displayKey
!=
null
)
{
if
(
!
array_key_exists
(
$this
->
internalCacheKey
,
self
::
$internalOptionList
))
{
$uuid
=
$node
->
getAttributes
()[
'uuid'
];
self
::
$internalOptionList
[
$this
->
internalCacheKey
]
=
array
();
self
::
$internalOptionList
[
$uuid
]
=
$node
->
$displayKey
->
__toString
();
foreach
(
$mdlStructure
as
$modelData
)
{
// only handle valid model sources
if
(
array_key_exists
(
'source'
,
$modelData
)
&&
array_key_exists
(
'items'
,
$modelData
)
&&
array_key_exists
(
'display'
,
$modelData
))
{
$className
=
str_replace
(
"."
,
"
\\
"
,
$modelData
[
'source'
]);
$modelObj
=
new
$className
;
foreach
(
$modelObj
->
getNodeByReference
(
$modelData
[
'items'
])
->
__items
as
$node
)
{
$displayKey
=
$modelData
[
'display'
];
if
(
array_key_exists
(
"uuid"
,
$node
->
getAttributes
())
&&
$node
->
$displayKey
!=
null
)
{
// check for filters and apply if found
$isMatched
=
true
;
if
(
array_key_exists
(
"filters"
,
$modelData
))
{
foreach
(
$modelData
[
'filters'
]
as
$filterKey
=>
$filterValue
)
{
$fieldData
=
$node
->
$filterKey
;
if
(
!
preg_match
(
$filterValue
,
$fieldData
)
&&
$fieldData
!=
null
)
{
$isMatched
=
false
;
}
}
}
}
}
if
(
$isMatched
)
{
$uuid
=
$node
->
getAttributes
()[
'uuid'
];
self
::
$internalOptionList
[
$this
->
internalCacheKey
][
$uuid
]
=
$node
->
$displayKey
->
__toString
();
}
}
}
unset
(
$modelObj
);
}
}
unset
(
$modelObj
);
}
}
}
}
}
}
...
@@ -83,8 +109,9 @@ class ModelRelationField extends BaseField
...
@@ -83,8 +109,9 @@ class ModelRelationField extends BaseField
public
function
getNodeData
()
public
function
getNodeData
()
{
{
$result
=
array
();
$result
=
array
();
if
(
is_array
(
self
::
$internalOptionList
))
{
if
(
array_key_exists
(
$this
->
internalCacheKey
,
self
::
$internalOptionList
)
&&
foreach
(
self
::
$internalOptionList
as
$optKey
=>
$optValue
)
{
is_array
(
self
::
$internalOptionList
[
$this
->
internalCacheKey
]))
{
foreach
(
self
::
$internalOptionList
[
$this
->
internalCacheKey
]
as
$optKey
=>
$optValue
)
{
if
(
$optKey
==
$this
->
internalValue
&&
$this
->
internalValue
!=
null
)
{
if
(
$optKey
==
$this
->
internalValue
&&
$this
->
internalValue
!=
null
)
{
$selected
=
1
;
$selected
=
1
;
}
else
{
}
else
{
...
@@ -108,10 +135,16 @@ class ModelRelationField extends BaseField
...
@@ -108,10 +135,16 @@ class ModelRelationField extends BaseField
$msg
=
$this
->
internalValidationMessage
;
$msg
=
$this
->
internalValidationMessage
;
}
}
if
((
$this
->
internalIsRequired
==
true
||
$this
->
internalValue
!=
null
)
&&
if
((
$this
->
internalIsRequired
==
true
||
$this
->
internalValue
!=
null
)
count
(
self
::
$internalOptionList
)
>
0
)
{
)
{
return
array
(
new
InclusionIn
(
array
(
'message'
=>
$msg
,
'domain'
=>
array_keys
(
self
::
$internalOptionList
))));
if
(
array_key_exists
(
$this
->
internalCacheKey
,
self
::
$internalOptionList
)
&&
count
(
self
::
$internalOptionList
[
$this
->
internalCacheKey
])
>
0
)
{
return
array
(
new
InclusionIn
(
array
(
'message'
=>
$msg
,
'domain'
=>
array_keys
(
self
::
$internalOptionList
[
$this
->
internalCacheKey
]))));
}
else
{
return
array
(
new
InclusionIn
(
array
(
'message'
=>
$msg
,
'domain'
=>
array
())));
}
}
else
{
}
else
{
// empty field and not required, skip this validation.
// empty field and not required, skip this validation.
return
array
();
return
array
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment