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:
32: class RadioGroup extends FormComponent
33: {
34: public function getChoiceGroup()
35: {
36: $choice = null;
37: $callback = function(&$component) use (&$choice)
38: {
39: $choice = $component;
40: return Component::VISITOR_STOP_TRAVERSAL;
41: };
42: $this->visitParents(Identifier::forName('picon\ChoiceGroup'), $callback);
43: return $choice;
44: }
45:
46: public function getName()
47: {
48: $choice = $this->getChoiceGroup();
49: if($choice==null)
50: {
51: return parent::getName();
52: }
53: else
54: {
55: return str_replace('.', '_', $choice->getComponentPath());
56: }
57: }
58:
59: protected function convertInput()
60: {
61: $input = $this->getRawInput();
62: $value = null;
63: $callback = function(Radio &$radio) use(&$value, $input)
64: {
65: if($radio->getValue()==$input)
66: {
67: $value = $radio->getModelObject();
68: return Component::VISITOR_STOP_TRAVERSAL;
69: }
70: return Component::VISITOR_CONTINUE_TRAVERSAL;
71: };
72: $this->visitChildren(Radio::getIdentifier(), $callback);
73:
74: if($value!=null)
75: {
76: $this->setConvertedInput($value);
77: }
78: }
79:
80: public function isRequired()
81: {
82: $choice = $this->getChoiceGroup();
83: return $choice==null && parent::isRequired();
84: }
85:
86: protected function validateModel()
87: {
88:
89: }
90:
91: protected function onComponentTag(ComponentTag $tag)
92: {
93: parent::onComponentTag($tag);
94: $tag->remove('name');
95: }
96: }
97:
98: ?>
99: