1: <?php
2:
3: /**
4: * Picon Framework
5: * http://code.google.com/p/picon-framework/
6: *
7: * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
8:
9: * Picon Framework is free software: you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation, either version 3 of the License, or
12: * (at your option) any later version.
13:
14: * Picon Framework is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * General Public License for more details.
18:
19: * You should have received a copy of the GNU General Public License
20: * along with Picon Framework. If not, see <http://www.gnu.org/licenses/>.
21: * */
22:
23: namespace picon;
24:
25: /**
26: * An automatically populated list of check boxes to choose from. The options
27: * are defined as an array.
28: *
29: * @author Martin Cassidy
30: * @package web/markup/html/form
31: */
32: class CheckChoice extends AbstractMultipleChoice implements ChoiceGroup
33: {
34: private $group;
35: private $selection;
36:
37: /**
38: *
39: * @param string $id
40: * @param array $choices The available choices
41: * @param Model $model
42: */
43: public function __construct($id, $choices, Model $model = null)
44: {
45: parent::__construct($id, $choices, $model);
46: }
47:
48: protected function onInitialize()
49: {
50: parent::onInitialize();
51: $this->selection = $this->getModelObject();
52: $this->group = new CheckBoxGroup('choice', $this->getModel());
53: $this->add($this->group);
54:
55: //@todo add the type hint back into the closure when the serializer can handle them
56: $this->group->add(new ListView('choices', function(&$item)
57: {
58: $check = new \picon\Check('checkbox', $item->getModel());
59: $item->add($check);
60: $item->add(new \picon\FormComponentLabel('label', $check));
61: }, new ArrayModel($this->getChoices())));
62: }
63:
64: protected function newMarkupSource()
65: {
66: return new PanelMarkupSource();
67: }
68:
69: public function __get($name)
70: {
71: return $this->$name;
72: }
73:
74: public function __set($name, $value)
75: {
76: $this->$name = $value;
77: }
78:
79: protected function convertInput()
80: {
81: $this->group->processInput();
82: $this->setConvertedInput($this->group->getConvertedInput());
83: }
84: }
85:
86: ?>
87: