tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file form_field_radio_group_semidynamic_view.class.php

Documentation is available at form_field_radio_group_semidynamic_view.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. // $Id$
  4. //
  5.  
  6. /**
  7.  * Contains class Form_Field_Radio_Group_Semidynamic_View
  8.  *
  9.  * @package tangra_lib
  10.  * @subpackage form
  11.  */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once(TANGRA_MAIN_DIR.'form/fields/form_field_view.class.php');
  17.  
  18.  
  19. /**
  20.  * Semidynamic view class for Form_Field_Radio_Group
  21.  *
  22.  * @package tangra_lib
  23.  * @subpackage form
  24.  */
  25.     /**
  26.      * Labels map
  27.      *
  28.      * @var unknown_type 
  29.      * @internal
  30.      */
  31.     protected $radios_labels_map = array();
  32.  
  33.  
  34.     /**
  35.      * Sets labels map
  36.      *
  37.      * $rl_arr must be an array in form:
  38.      * $rl_arr[radio_value] = radio_label;
  39.      * Example: $rl_arr[1] = 'one';
  40.      *
  41.      * @param unknown_type $rl_arr 
  42.      * @throws Tangra_Exception
  43.      */
  44.     public function set_rl_map($rl_arr{
  45.         if (is_array($rl_arr)) {
  46.             $this->radios_labels_map = $rl_arr;
  47.         else {
  48.             throw new Tangra_Exception('$rl_arr is not an array');
  49.         }
  50.     }
  51.  
  52.  
  53.     /**
  54.      * Returns TPLE exports
  55.      *
  56.      * @return TPLE_Exports 
  57.      */
  58.     public function get_tple_exports({
  59.         $exports parent::get_tple_exports();
  60.  
  61.         $radios $this->field->get_radios();
  62.         $radios_exp array();
  63. //        print_r_pre($radios);
  64. //        print_r_pre($this->radios_labels_map);
  65.         foreach($radios as $radio{
  66.             $radio_label $this->get_radio_label($radio['value']);
  67.             $tmp_radio['html_value'$radio['html_value'];
  68.             $tmp_radio['label'$this->get_radio_label($radio['value']);
  69.             $tmp_radio['checked'$radio['checked'];
  70.             array_push($radios_exp$tmp_radio);
  71.         }
  72.  
  73.         $exports->add_pair($this->get_tpl_name().'_radios',$radios_exp);
  74.  
  75.         return $exports;
  76.     }
  77.  
  78.  
  79.     /**
  80.      * Returns radio's label
  81.      *
  82.      * @param integer $value 
  83.      * @return string 
  84.      */
  85.     private function get_radio_label($value{
  86.         $ret false;
  87.  
  88.         if (array_key_exists($value$this->radios_labels_map)) {
  89.             $ret $this->radios_labels_map[$value];
  90.         else {
  91.             throw new Tangra_Exception('radios_labels_map does not have key = '.$value);
  92.         }
  93.  
  94.         return $ret;
  95.     }
  96. }