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 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Base\Validators\CsvListValidator;
use OPNsense\Core\Config;
/**
......@@ -49,6 +50,11 @@ class CertificateField extends BaseField
*/
private $certificateType = "cert";
/**
* @var bool field may contain multiple certs at once
*/
private $internalMultiSelect = false;
/**
* @var string default validation message string
*/
......@@ -59,7 +65,6 @@ class CertificateField extends BaseField
*/
private static $internalOptionList = array();
/**
* set certificate type (cert/ca)
* @param $value certificate type
......@@ -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)
*/
......@@ -97,8 +115,10 @@ class CertificateField extends BaseField
if (!$this->internalIsRequired) {
$result[""] = array("value" => gettext("none"), "selected" => 0);
}
$certs = explode(',', $this->internalValue);
foreach (self::$internalOptionList as $optKey => $optValue) {
if ($optKey == $this->internalValue) {
if (in_array($optKey, $certs)) {
$selected = 1;
} else {
$selected = 0;
......@@ -117,9 +137,16 @@ class CertificateField extends BaseField
{
$validators = parent::getValidators();
if ($this->internalValue != null) {
if ($this->internalMultiSelect) {
// 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;
}
}
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