setCheckedValue($options['checkedValue']); unset($options['checkedValue']); } if (array_key_exists('uncheckedValue', $options)) { $this->setUncheckedValue($options['uncheckedValue']); unset($options['uncheckedValue']); } parent::setOptions($options); $curValue = $this->getValue(); $test = array($this->getCheckedValue(), $this->getUncheckedValue()); if (!in_array($curValue, $test)) { $this->setValue($curValue); } return $this; } /** * Set value * * If value matches checked value, sets to that value, and sets the checked * flag to true. * * Any other value causes the unchecked value to be set as the current * value, and the checked flag to be set as false. * * * @param mixed $value * @return Zend_Form_Element_Checkbox */ public function setValue($value) { if ($value == $this->getCheckedValue()) { parent::setValue($value); $this->checked = true; } else { parent::setValue($this->getUncheckedValue()); $this->checked = false; } return $this; } /** * Set checked value * * @param string $value * @return Zend_Form_Element_Checkbox */ public function setCheckedValue($value) { $this->_checkedValue = (string) $value; return $this; } /** * Get value when checked * * @return string */ public function getCheckedValue() { return $this->_checkedValue; } /** * Set unchecked value * * @param string $value * @return Zend_Form_Element_Checkbox */ public function setUncheckedValue($value) { $this->_uncheckedValue = (string) $value; return $this; } /** * Get value when not checked * * @return string */ public function getUncheckedValue() { return $this->_uncheckedValue; } /** * Set checked flag * * @param bool $flag * @return Zend_Form_Element_Checkbox */ public function setChecked($flag) { $this->checked = (bool) $flag; if ($this->checked) { $this->setValue($this->getCheckedValue()); } else { $this->setValue($this->getUncheckedValue()); } return $this; } /** * Get checked flag * * @return bool */ public function isChecked() { return $this->checked; } /** * Render * * Ensure that options property is set when rendering. * * @param Zend_View_Interface $view * @return string */ public function render(Zend_View_Interface $view = null) { $this->options = array( 'checked' => $this->getCheckedValue(), 'unChecked' => $this->getUncheckedValue(), ); return parent::render($view); } }