Source for file TCheckGroup.php
Documentation is available at TCheckGroup.php
namespace
Adianti \
Widget \
Form ;
use
Adianti \
Widget \
Form \
TForm ;
use
Adianti \
Widget \
Form \
TLabel ;
use
Adianti \
Widget \
Form \
TField ;
* A group of CheckButton's
* @author Pablo Dall'Oglio
* @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
* @license http://www.adianti.com.br/framework-license
private $layout =
'vertical' ;
private $allItemsChecked ;
* @param $name name of the field
$oldbuttons =
$this -> buttons ;
$this -> buttons =
array ( ) ;
foreach ( $this -> items as $key =>
$value )
$button -> setProperty ( 'checkgroup' , $this -> name ) ;
$button -> setIndexValue ( $key ) ;
$button -> setProperty ( 'onchange' , $oldbuttons [ $key ] -> getProperty ( 'onchange' )) ;
$obj =
new TLabel ( $value ) ;
$this -> buttons [ $key ] =
$button ;
$this -> labels [ $key ] =
$obj ;
public function checkAll ( )
$this -> allItemsChecked = TRUE ;
* Define the direction of the options
* @param $direction String (vertical, horizontal)
public function setLayout ( $dir )
* Get the direction (vertical or horizontal)
public function getLayout ( )
* Define after how much items, it will break
public function setBreakItems ( $breakItems )
$this -> breakItems = $breakItems ;
public function setUseButton ( )
public function setUseSwitch ( $useSwitch = TRUE , $labelClass = 'blue' )
$this -> labelClass = 'tswitch ' . $labelClass . ' ' ;
* Add items to the check group
* @param $items An indexed array containing the options
$this -> buttons = array ( ) ;
foreach ( $items as $key => $value )
$button = new <a href="widget/form/TCheckButton.html">TCheckButton</a> ( " {$this -> name } []
" ) ;
$button -> setProperty ( 'checkgroup' , $this -> name ) ;
$button -> setIndexValue ( $key ) ;
$obj =
new TLabel ( $value ) ;
$this -> buttons [ $key ] =
$button ;
$this -> labels [ $key ] =
$obj ;
public function getItems ( )
* Return the option buttons
public function getButtons ( )
* Return the option labels
public function getLabels ( )
* Define the field's separator
* @param $sep A string containing the field's separator
public function setValueSeparator ( $sep )
* Define the field's value
* @param $value A string containing the field's value
public function setValue ( $value )
public function getPostData ( )
if ( isset( $_POST [ $this -> name ] ))
return $_POST [ $this -> name ] ;
* Define the action to be executed when the user changes the combo
* @param $action TAction object
public function setChangeAction ( TAction $action )
$this -> changeAction = $action ;
$string_action = $action -> toString ( ) ;
throw new Exception ( AdiantiCoreTranslator :: translate ( 'Action (^1) must be static to be used in ^2' , $string_action , __METHOD__)) ;
* Reload checkbox items after it is already shown
* @param $formname form name (used in gtk version)
* @param $name field name
* @param $items array with items
* @param $options array of options [layout, size, breakItems, useButton, valueSeparator, value, changeAction, changeFunction, checkAll]
public static function reload ( $formname , $name , $items , $options )
$field = new self ( $name ) ;
$field -> addItems ( $items ) ;
if ( ! empty ( $options [ 'layout' ] ))
$field -> setLayout ( $options [ 'layout' ] ) ;
if ( ! empty ( $options [ 'size' ] ))
$field -> setSize ( $options [ 'size' ] ) ;
if ( ! empty ( $options [ 'breakItems' ] ))
$field -> setBreakItems ( $options [ 'breakItems' ] ) ;
if ( ! empty ( $options [ 'useButton' ] ))
$field -> setUseButton ( $options [ 'useButton' ] ) ;
if ( ! empty ( $options [ 'valueSeparator' ] ))
$field -> setValueSeparator ( $options [ 'valueSeparator' ] ) ;
if ( ! empty ( $options [ 'value' ] ))
$field -> setValue ( $options [ 'value' ] ) ;
if ( ! empty ( $options [ 'changeAction' ] ))
$field -> setChangeAction ( $options [ 'changeAction' ] ) ;
if ( ! empty ( $options [ 'changeFunction' ] ))
$field -> setChangeFunction ( $options [ 'changeFunction' ] ) ;
if ( ! empty ( $options [ 'checkAll' ] ))
$field -> checkAll ( $options [ 'checkAll' ] ) ;
$content = $field -> getContents ( ) ;
<a href="widget/base/TScript.html">TScript</a> :: create ( " tcheckgroup_reload('{
$formname } ', '{
$name } ', `{
$content } `);
" ) ;
* @param $form_name Form name
* @param $field Field name
public static function enableField ( $form_name , $field )
TScript :: create ( " tcheckgroup_enable_field('{
$form_name } ', '{
$field } ');
" ) ;
* @param $form_name Form name
* @param $field Field name
public static function disableField ( $form_name , $field )
TScript :: create ( " tcheckgroup_disable_field('{
$form_name } ', '{
$field } ');
" ) ;
* @param $form_name Form name
* @param $field Field name
public static function clearField ( $form_name , $field )
TScript :: create ( " tcheckgroup_clear_field('{
$form_name } ', '{
$field } ');
" ) ;
* Shows the widget at the screen
$editable_class = ( ! parent :: getEditable ( )) ? 'tfield_block_events' : '' ;
echo " <div class=\"toggle-wrapper {
$editable_class } \"
" .$this -> getPropertiesAsString ( 'aria' ) .' data-toggle="buttons">' ;
echo '<div class="btn-group" style="clear:both;float:left;display:table">' ;
echo " <div class=\"toggle-wrapper {
$editable_class } \"
" .$this -> getPropertiesAsString ( 'aria' ) .' role="group">' ;
// iterate the checkgroup options
foreach ( $this -> items as $index => $label )
$button = $this -> buttons [ $index ] ;
$button -> setName ( $this -> name .'[]' ) ;
// verify if the checkbutton is checked
$button -> setValue ( $index ) ; // value=indexvalue (checked)
// create the label for the button
$obj = $this -> labels [ $index ] ;
$obj -> { 'class' } = $this -> labelClass . ( $active ?'active' :'' ) ;
$obj -> setTip ( $this -> tag -> title ) ;
if ( $this -> getSize ( ) AND ! $obj -> getSize ( ))
// check whether the widget is non-editable
if ( isset( $this -> changeAction ))
if ( ! <a href="widget/form/TForm.html">TForm</a> :: getFormByName ( $this -> formName ) instanceof <a href="widget/form/TForm.html">TForm</a> )
throw new Exception ( <a href="core/AdiantiCoreTranslator.html">AdiantiCoreTranslator</a> :: translate ( 'You must pass the ^1 (^2) as a parameter to ^3' , __CLASS__, $this -> name , 'TForm::setFields()' ) ) ;
$string_action = $this -> changeAction -> serialize ( FALSE ) ;
$button -> setProperty ( 'changeaction' , " __adianti_post_lookup('{
$this -> formName } ', '{
$string_action } ', '{
$id } ', 'callback')
" ) ;
$button -> setProperty ( 'onChange' , $button -> getProperty ( 'changeaction' ) , FALSE ) ;
$button -> setEditable ( FALSE ) ;
//$obj->setFontColor('gray');
$classButton = 'filled-in' ;
$classButton .= ' btn-tswitch' ;
$button -> setProperty ( 'class' , $classButton ) ;
$obj -> { 'for' } = $button -> getId ( ) ;
$wrapper = new <a href="widget/base/TElement.html">TElement</a> ( 'div' ) ;
$wrapper -> { 'style' } = 'display:inline-flex;align-items:center;' ;
if ( $this -> layout == 'vertical' OR ( $this -> breakItems == $i ))
echo '<div class="btn-group" style="clear:both;float:left;display:table">' ;
$br = new <a href="widget/base/TElement.html">TElement</a> ( 'br' ) ;
if ( ! empty ( $this -> getAfterElement ( )))
$this -> getAfterElement ( ) -> show ( ) ;