Nooku Framework is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

nooku-framework

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
 * @version        $Id$
 * @category    Koowa
 * @package        Koowa_Form
 * @subpackage     Element
 * @copyright    Copyright (C) 2007 - 2010 Johan Janssens. All rights reserved.
 * @license        GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link         http://www.nooku.org
 */

/**
 * Abstract Option Element
 *
 * @author        Mathias Verraes <mathias@joomlatools.org>
 * @category    Koowa
 * @package     Koowa_Form
 * @subpackage     Element
 */
class KFormElementSelectRadio extends KFormElementAbstract
{
    /**
     * Is the option checked
     *
     * @var bool
     */
    protected $_checked = false;

    /**
     * Valid attributes for the element
     *
     * @var array    Array of strings
     */
    protected $_validAttribs = array('disabled', 'checked', 'value', 'accesskey', 'class', 'dir', 'id', 'lang', 'style', 'tabindex', 'title', 'xml:lang');


    /**
     * Import an XML element definition
     *
     * @param     SimpleXMLElement SimpleXMLElement object
     * @return     KFormElementSelectRadio
     */
    public function importXml(SimpleXMLElement $xml)
    {
        parent::importXml($xml);

        $this->setValue((string) $this->_xml['value']);
        $this->setLabel((string) $this->_xml);
        return $this;
    }

    /**
     * Select or unselet the option
     *
     * @param     bool
     * @return     KFormElementSelectRadio
     */
    public function setChecked($bool)
    {
        $this->_checked = (bool) $bool;
        return $this;
    }

    /**
     * Is the option checked?
     *
     * @return     bool
     */
    public function isChecked()
    {
        return $this->_checked;
    }

    public function renderDomElement(DOMDocument $dom)
    {
        $elem = $dom->createElement('input');
        $elem->setAttribute('type', 'radio');
        $elem->setAttribute('name', $this->getName());
        $elem->setAttribute('id', $this->getName() . '_' . $this->getValue());
        $elem->setAttribute('value', $this->getValue());
        $label = $this->_xml;
        //$elem->appendChild( $dom->createTextNode((string)$label));

        if($this->isChecked()) {
            $elem->setAttribute('checked', 'checked');
        }

        foreach($this->getAttributes() as $key => $val) {
            $elem->setAttribute($key, $val);
        }

        return $elem;
    }

    public function renderDomLabel(DOMDocument $dom)
    {
        $data         = $this->getLabel();

        $elem = $dom->createElement('label', JText::_($data['label']));
        $elem->setAttribute('title', JText::_($data['description']));
        $elem->setAttribute('for', $this->getName().'_'.$this->getValue());

        return $elem;
    }
}
Ajax-loader Loading, please wait...