Commit 39ba8686 authored by Ad Schellevis's avatar Ad Schellevis

Merge pull request #876 from fraenki/multi_certs

support multiple values in CertificateField
parents 6c79ec95 f5cd82c6
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
namespace OPNsense\Base\FieldTypes; namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn; use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Base\Validators\CsvListValidator;
use OPNsense\Core\Config; use OPNsense\Core\Config;
/** /**
...@@ -49,6 +50,11 @@ class CertificateField extends BaseField ...@@ -49,6 +50,11 @@ class CertificateField extends BaseField
*/ */
private $certificateType = "cert"; private $certificateType = "cert";
/**
* @var bool field may contain multiple certs at once
*/
private $internalMultiSelect = false;
/** /**
* @var string default validation message string * @var string default validation message string
*/ */
...@@ -59,7 +65,6 @@ class CertificateField extends BaseField ...@@ -59,7 +65,6 @@ class CertificateField extends BaseField
*/ */
private static $internalOptionList = array(); private static $internalOptionList = array();
/** /**
* set certificate type (cert/ca) * set certificate type (cert/ca)
* @param $value certificate type * @param $value certificate type
...@@ -73,6 +78,19 @@ class CertificateField extends BaseField ...@@ -73,6 +78,19 @@ class CertificateField extends BaseField
} }
} }
/**
* select if multiple certs may be selected at once
* @param $value boolean value Y/N
*/
public function setMultiple($value)
{
if (trim(strtoupper($value)) == "Y") {
$this->internalMultiSelect = true;
} else {
$this->internalMultiSelect = false;
}
}
/** /**
* generate validation data (list of certificates) * generate validation data (list of certificates)
*/ */
...@@ -97,8 +115,10 @@ class CertificateField extends BaseField ...@@ -97,8 +115,10 @@ class CertificateField extends BaseField
if (!$this->internalIsRequired) { if (!$this->internalIsRequired) {
$result[""] = array("value" => gettext("none"), "selected" => 0); $result[""] = array("value" => gettext("none"), "selected" => 0);
} }
$certs = explode(',', $this->internalValue);
foreach (self::$internalOptionList as $optKey => $optValue) { foreach (self::$internalOptionList as $optKey => $optValue) {
if ($optKey == $this->internalValue) { if (in_array($optKey, $certs)) {
$selected = 1; $selected = 1;
} else { } else {
$selected = 0; $selected = 0;
...@@ -117,8 +137,15 @@ class CertificateField extends BaseField ...@@ -117,8 +137,15 @@ class CertificateField extends BaseField
{ {
$validators = parent::getValidators(); $validators = parent::getValidators();
if ($this->internalValue != null) { if ($this->internalValue != null) {
$validators[] = new InclusionIn(array('message' => $this->internalValidationMessage, if ($this->internalMultiSelect) {
'domain'=>array_keys(self::$internalOptionList))); // field may contain more than one country
$validators[] = new CsvListValidator(array('message' => $this->internalValidationMessage,
'domain'=>array_keys(self::$internalOptionList)));
} else {
// single country selection
$validators[] = new InclusionIn(array('message' => $this->internalValidationMessage,
'domain'=>array_keys(self::$internalOptionList)));
}
} }
return $validators; return $validators;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment