<?php 

class SelectRadio  {
  private $scope;
  private $elements;
  private $iterator;

  public function __construct($entry) {

    if (isset($entry)) {
      $this->scope  = $entry->scope;
      $this->iterator = $entry->iterator;
      $this->elements = explode (",", $entry->elements);
    }
  }
  

  public function outputLayout() {
  

  $layout = "
    <input type='hidden' id=hid$this->scope class=$this->iterator name='$this->scope'> 
  ";
  
    for ($i=0; $i<count($this->elements); $i++) {
      $value = $this->elements[$i];

      $layout .= "
      <input type='radio' class='rad$this->scope' id='rad$this->scope$value' value=$value> $value<br>
      ";
    }
  
 	return $layout;
  }	

  public function outputScript() {

    $script = "
 
$('.rad$this->scope').on('click', function() {
    $('.rad$this->scope').prop('checked', false);
    $(this).prop('checked', true);
  $('#hid$this->scope').val($(this).val());
});


$('#hid$this->scope').on('chg$this->iterator', function() {
  $('.rad$this->scope').prop('checked', false);
  var chkValue = $(this).val();
  $('#rad$this->scope'+chkValue).prop('checked', true);
});

      
    "; 
    
    return $script;
  }
}

?>