1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: namespace picon;
24:
25: 26: 27: 28: 29: 30:
31: class CheckBox extends FormComponent
32: {
33: protected function validateModel()
34: {
35: if($this->getModel()!=null && !($this->getModel() instanceof BooleanModel) && $this->getModelObject()!=null && !is_bool($this->getModelObject()))
36: {
37: throw new \IllegalStateException(sprintf("A check box must have a boolean model, actual %s", gettype($this->getModelObject())));
38: }
39: }
40:
41: public function getValue()
42: {
43: return $this->getComponentPath();
44: }
45:
46: protected function isSelected($value)
47: {
48: if($this->isEmptyInput())
49: {
50: return false;
51: }
52: else
53: {
54: if($this->getRawInput()==null)
55: {
56: return $this->getModelObject();
57: }
58: else
59: {
60: return $value==$this->getRawInput();
61: }
62: }
63: }
64:
65: protected function onComponentTag(ComponentTag $tag)
66: {
67: parent::onComponentTag($tag);
68: $this->checkComponentTag($tag, 'input');
69: $this->checkComponentTagAttribute($tag, 'type', 'checkbox');
70: $tag->put('value', $this->getValue());
71:
72: if($this->isSelected($this->getValue()))
73: {
74: $tag->put('checked', 'checked');
75: }
76: }
77:
78: protected function convertInput()
79: {
80: $value = ($this->getRawInput()==$this->getValue())==true;
81: $this->setConvertedInput($value);
82: }
83: }
84:
85: ?>
86: