Exemple #1
0
 /**
  * Returns the HTML rendered field as radio buttons group
  * @return string
  */
 public function getAsRadio()
 {
     $id = $this->getId();
     $properties = $this->composeStringProperties();
     $external_data = $this->data->getAll();
     $value_field = $this->getSourceValueField();
     $description_field = $this->getSourceDescriptionField();
     $new_value = $this->getNewValue();
     $sContent = "";
     $enabled = '';
     if (!$this->isEnabled()) {
         $enabled = 'disabled="disabled" ';
     }
     if ($this->isNullAllowed()) {
         if ($this->null_message === null) {
             $message = 'none_selected';
         } else {
             $message = $this->null_message;
         }
         array_unshift($external_data, array($value_field => '', $description_field => __($message)));
     }
     foreach ($external_data as $key => $current) {
         if ($current[$value_field] == $new_value) {
             $checked = "checked='checked'";
         } else {
             $checked = "";
         }
         $input = "<input {$enabled} name='{$id}' id='{$id}_{$key}input' type='radio' " . $this->composeStringActions() . " {$checked} value='" . htmlspecialchars($current[$value_field]) . "'/>";
         if ($this->isFormatted()) {
             $label = $this->format($current[$description_field], $this->data->fields->{$description_field}->getType(), $this->data->fields->{$description_field}->getNumOfDecimals());
         } else {
             $label = $current[$description_field];
         }
         $sContent .= P4A_Generate_Widget_Layout_Table($input, "<label for='{$id}_{$key}input'>{$label}</label>");
     }
     $this->label->unsetProperty('for');
     $return = $this->composeLabel() . "<div class='p4a_field_radio_values' {$properties}>{$sContent}</div>";
     $this->label->setProperty('for', "{$id}input");
     return $return;
 }