<?php
 namespace Engine\Form\Input; class Checkboxes extends \Engine\Form\Input\ElementAbstract { protected $class = "checkboxes"; protected $possibleValues = []; protected array $partialDisabled = []; public function __construct($label=null, $name=null, $value=null, $possibleValues=null) { if($possibleValues){ $this->possibleValues = $possibleValues; } parent::__construct($label, $name, $value); $this->setStyle('renderMode', 'inline'); } public function setValue($value) { $this->value = (Array)$value; return $this; } protected function getTemplateParams($templateClass = null, $parentElement = null) { $params = parent::getTemplateParams($templateClass, $parentElement ); $params['possibleValues'] = $this->getPossibleValues(); $params['partialDisabled'] = $this->partialDisabled; return $params; } public function getPossibleValues() { if (!$this->possibleValues) { $this->possibleValues = $this->determinePossibleValues(); } return $this->possibleValues; } public function setPossibleValues($possibleValues) { $this->possibleValues = $possibleValues; return $this; } protected function determinePossibleValues() { return []; } public function getDefaultValue() { return array_flip($this->defaultValue); } public function renderFilterOverview() { $pvalues = $this->getPossibleValues(); $values = $this->getValue(); $ret = []; foreach ($values as $v) { $ret[] = $pvalues[$v]; } if ($ret) { return sprintf("%s", implode(", ", $ret)); } else { return sprintf("(none)"); } } public function shouldRenderOverview() { if ($this->getDefaultValue()===null) { throw new \Exception("You did not set any default value for this input"); } $cv = array_values($this->getvalue()); sort($cv); $dv = array_keys($this->getDefaultValue()); sort($dv); return $cv != $dv; } public function setPartialDisabled(array $disabledElements): void { $this->partialDisabled = $disabledElements; } } 