radioField.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\forms;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Select Form Field
  6. *
  7. * @author Michal Czech <michael@modulesgarden.com>
  8. */
  9. class radioField extends abstractField{
  10. public $translateOptions = true;
  11. public $addValueIfNotExits = false;
  12. public $options;
  13. public $type = 'radio';
  14. function prepare() {
  15. if(array_keys($this->options) == range(0, count($this->options) - 1))
  16. {
  17. $options = array();
  18. foreach($this->options as $value)
  19. {
  20. $options[$value] = $value;
  21. }
  22. $this->options = $options;
  23. }
  24. else
  25. {
  26. $this->translateOptions = false;
  27. }
  28. if($this->addValueIfNotExits)
  29. {
  30. if($this->value && !isset($this->options[$this->value]))
  31. {
  32. $this->options[$this->value] = $this->value;
  33. }
  34. }
  35. if($this->translateOptions)
  36. {
  37. $options = array();
  38. foreach($this->options as $value)
  39. {
  40. $options[$value] = main\mgLibs\lang::T($this->formName,$this->name,'options',$value);
  41. }
  42. $this->options = $options;
  43. }
  44. if(empty($this->value))
  45. {
  46. foreach($this->options as $value => $lbl)break;
  47. $this->value = $value;
  48. }
  49. }
  50. }