Item
[
class tree: Item
] [
index: Item
] [
all elements
]
README.txt
Todo List
Packages:
Formagic
Item
Renderer
Rule
Source for file Radio.php
Documentation is available at
Radio.php
<?php
/**
* Formagic
*
* LICENCE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at
* http://formagic.weasle.de/licence.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to licence@weasle.de so we can send you a copy immediately.
*
*
@category
Formagic
*
@package
Item
*
@author
Florian Sonnenburg
*
@copyright
Copyright (c) 2007 Florian Sonnenburg
*
@license
http://formagic.weasle.de/licence.txt New BSD License
*
@revision
$Revision: 11 $
*/
/**
* Input type radio for formagic formgenerator
*
*
@category
Formagic
*
@package
Item
*
@author
Florian Sonnenburg
*
@copyright
Copyright (c) 2007 Florian Sonnenburg
*
@version
$Id: Radio.php 11 2007-08-12 20:02:57Z meweasle $
*/
class
Formagic_Item_Radio
extends
Formagic_Item
{
/**
* Array containing select options
*
@var
array
*
@access
private
*/
private
$data
;
/**
* String to separate radio elements from each other
*
@var
string
*
@access
private
*/
private
$separator
=
"\n"
;
/**
* Tells if an empty radio element should be added to list of elements
*
@var
array
*
@access
private
*/
private
$emptyElement
=
null
;
/**
* Argument handler for arguments that are unknown to item parent class
*
*
@param
string
$key
Argument name
*
@param
mixed
$arg
Argument value
*
@return
boolean
*/
protected
function
_handleArg
(
$key
,
$arg
)
{
switch
(
$key
)
{
case
'separator'
:
$this
->
separator
=
$arg
;
break
;
case
'addEmptyFirst'
:
$this
->
addEmpty
(
$arg
,
'first'
)
;
break
;
case
'addEmpty'
:
case
'addEmptyLast'
:
$this
->
addEmpty
(
$arg
,
'last'
)
;
break
;
case
'data'
:
$this
->
setData
(
$arg
)
;
break
;
default
:
throw
new
Exception
(
"
Argument
type
'
$key
'
not
supported
"
)
;
}
// switch
return
true
;
}
/**
* Saves empty element
*
*
@param
mixed
$element
Label of empty element if string. If true, '---' is
* label of empty element.
*
@param
mixed
$pos
Where to add empty element. Allowed values:
* 'first' or 'last'
*
@return
boolean
*/
public
function
addEmpty
(
$element
,
$pos
)
{
if
(
!
$element
)
{
return
false
;
}
$element
=
is_bool
(
$element
)
?
'---'
:
$element
;
$this
->
emptyElement
=
array
(
$element
,
$pos
)
;
return
true
;
}
/**
* Adds empty element to data array after constructor is processed
*
*
@return
boolean
*/
protected
function
_onCreate
(
)
{
if
(
$this
->
emptyElement
)
{
$element
=
$this
->
emptyElement
[
0
]
;
$pos
=
$this
->
emptyElement
[
1
]
;
$this
->
data
=
$pos
==
'last'
?
$this
->
data
+
array
(
''
=>
$element
)
:
array
(
''
=>
$element
)
+
$this
->
data
;
}
return
true
;
}
/**
* Sets data for radio elements
*
*
@param
array
$arr
Associative array. Array-key will be value of radio
* elements, array-value will be label.
*
@return
boolean
*/
public
function
setData
(
$arr
)
{
$this
->
data
=
$arr
;
return
true
;
}
/**
* Sets separator string
*
*
@param
string
$separator
*
@return
string
*/
public
function
setSeparator
(
$separator
)
{
return
$this
->
separator
=
$separator
;
}
/**
* Returns string with HTML representation of radio elements
*
*
@return
string
*/
public
function
getHtml
(
)
{
// HTML blocked
$currVal
=
$this
->
getValue
(
)
;
if
(
$this
->
_isBlocked
)
{
$str
=
""
;
if
(
$this
->
isPostItem
)
{
$str
.=
'<input type="hidden" name="'
.
$this
->
name
.
'" value="'
.
$currVal
.
'" />'
;
}
foreach
(
$this
->
data
as
$key
=>
$value
)
{
$checkIndicator
=
$key
==
$currVal
?
"(o)"
:
"( )"
;
$str
.=
$checkIndicator
.
" "
.
$value
.
$this
->
separator
;
}
// HTML default
}
else
{
$str
=
""
;
$attrStr
=
$this
->
_getAttributeStr
(
)
;
foreach
(
$this
->
data
as
$key
=>
$value
)
{
$c
= (string)
$key
== (string)
$currVal
?
' checked="checked"'
:
''
;
$rName
=
$this
->
name
.
$key
;
$rId
=
$this
->
id
.
$key
;
// id=\"" . $this->name . "\"
$str
.=
"
<
input
type
=\"
radio
\"
id
=\"
$rId
\"
name
=\"{
$this
->
name
}
\"
"
.
"
value
=\"
$key
\"
{
$c
}
$attrStr
/><
label
for
=\"
$rId
\">
$value
"
.
"
</
label
>
{
$this
->
separator
}
"
;
}
}
$str
=
rtrim
(
$str
,
$this
->
separator
)
;
return
$str
;
}
Documentation generated on Thu, 23 Aug 2007 00:29:46 +0200 by
phpDocumentor 1.4.0