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
ac75ef6f
Commit
ac75ef6f
authored
Jun 26, 2017
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mvc, add setMultiple() to OptionField, closes
https://github.com/opnsense/core/issues/1693
parent
0502860e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
+33
-4
OptionField.php
...e/mvc/app/models/OPNsense/Base/FieldTypes/OptionField.php
+33
-4
No files found.
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/OptionField.php
View file @
ac75ef6f
...
...
@@ -30,6 +30,7 @@
namespace
OPNsense\Base\FieldTypes
;
use
Phalcon\Validation\Validator\InclusionIn
;
use
OPNsense\Base\Validators\CsvListValidator
;
/**
* Class OptionField
...
...
@@ -58,6 +59,11 @@ class OptionField extends BaseField
*/
private
$internalOptionList
=
array
();
/**
* @var bool field may contain multiple interfaces at once
*/
private
$internalMultiSelect
=
false
;
/**
* set descriptive text for empty value
* @param $value description
...
...
@@ -88,6 +94,19 @@ class OptionField extends BaseField
}
}
/**
* select if multiple interfaces may be selected at once
* @param $value boolean value 0/1
*/
public
function
setMultiple
(
$value
)
{
if
(
trim
(
strtoupper
(
$value
))
==
"Y"
)
{
$this
->
internalMultiSelect
=
true
;
}
else
{
$this
->
internalMultiSelect
=
false
;
}
}
/**
* get valid options, descriptions and selected value
* @return array
...
...
@@ -96,11 +115,14 @@ class OptionField extends BaseField
{
$result
=
array
();
// if relation is not required, add empty option
if
(
!
$this
->
internalIsRequired
)
{
if
(
!
$this
->
internalIsRequired
&&
!
$this
->
internalMultiSelect
)
{
$result
[
""
]
=
array
(
"value"
=>
$this
->
internalEmptyDescription
,
"selected"
=>
0
);
}
// explode options
$options
=
explode
(
','
,
$this
->
internalValue
);
foreach
(
$this
->
internalOptionList
as
$optKey
=>
$optValue
)
{
if
(
$optKey
==
$this
->
internalValue
)
{
if
(
in_array
(
$optKey
,
$options
)
)
{
$selected
=
1
;
}
else
{
$selected
=
0
;
...
...
@@ -120,8 +142,15 @@ class OptionField extends BaseField
{
$validators
=
parent
::
getValidators
();
if
(
$this
->
internalValue
!=
null
)
{
$validators
[]
=
new
InclusionIn
(
array
(
'message'
=>
$this
->
internalValidationMessage
,
'domain'
=>
array_keys
(
$this
->
internalOptionList
)));
if
(
$this
->
internalMultiSelect
)
{
// field may contain more than one option
$validators
[]
=
new
CsvListValidator
(
array
(
'message'
=>
$this
->
internalValidationMessage
,
'domain'
=>
array_keys
(
$this
->
internalOptionList
)));
}
else
{
// single option selection
$validators
[]
=
new
InclusionIn
(
array
(
'message'
=>
$this
->
internalValidationMessage
,
'domain'
=>
array_keys
(
$this
->
internalOptionList
)));
}
}
return
$validators
;
}
...
...
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