| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Formularium\Frontend\HTML\Renderable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Formularium\Datatype; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Formularium\Field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Formularium\Frontend\HTML\Framework; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Formularium\Frontend\HTML\Renderable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Formularium\HTMLElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class Renderable_bool extends Renderable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public const FORMAT_CHOOSER = 'format_chooser'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public const FORMAT_CHOOSER_SELECT = 'format_chooser_select'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public const FORMAT_CHOOSER_RADIO = 'format_chooser_radio'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     use \Formularium\Frontend\HTML\RenderableViewableTrait { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         viewable as _viewable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function viewable($value, Field $field, HTMLElement $previous): HTMLElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $formatted = $field->getDatatype()->format($value, $field); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return $this->_viewable($formatted, $field, $previous); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function editable($value, Field $field, HTMLElement $previous): HTMLElement | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         if (is_string($value)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             if ($value === 'true') { | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |                 $value = true; | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             } elseif ($value === 'false') { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |                 $value = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |                 $value = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $format = $field->getExtension(static::FORMAT_CHOOSER, static::FORMAT_CHOOSER_SELECT); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |          | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         if ($field->getValidators()[Datatype::REQUIRED] ?? false) { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             if ($format == static::FORMAT_CHOOSER_SELECT) { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                 $element = $this->editableSelect($value, $field, $previous); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                 $element = $this->editableRadio($value, $field, $previous); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             $element = $this->editableSelect($value, $field, $previous); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         return $this->container($element, $field); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param mixed $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @param Field $field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param HTMLElement $previous | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @return HTMLElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     protected function editableRadio($value, Field $field, HTMLElement $previous): HTMLElement | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         if (empty($value) && array_key_exists(static::DEFAULTVALUE, $field->getExtensions())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $value = $field->getExtensions()[static::DEFAULTVALUE]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $element = new HTMLElement('ul'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $idcounter = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         foreach ([true => 'True', false => 'False'] as $v => $label) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $input = new HTMLElement('input'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             // send ids to delete/edit data later correctly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             if ($value !== null && $v == $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 $input->addAttribute('checked', 'checked'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $elementname = $field->getName(); // 'loh:' . $this->name . '[' . $attrid . '][value]' . '[' . $attrid . ']'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             $id = $elementname . $idcounter++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $input->addAttributes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 'id' => $field->getName() . Framework::counter(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 'name' => $elementname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 'data-attribute' => $field->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 'data-datatype' => $field->getDatatype()->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 'data-basetype' => $field->getDatatype()->getBasetype(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 'value' => $value ? 'true' : 'false', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 'type' => 'radio', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 'title' => $field->getExtension(static::LABEL, '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             if ($field->getValidators()[Datatype::REQUIRED] ?? false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 $element->setAttribute('required', 'required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             foreach ([static::DISABLED, static::READONLY] as $p) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 if ($field->getExtension($p, false)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                     $input->setAttribute($p, $p); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $li = new HTMLElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 'li', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 [$input, new HTMLElement('label', ['for' => $id], [$label])] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             $element->addContent($li); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         return $element; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @param mixed $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @param Field $field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @param HTMLElement $previous | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @return HTMLElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     protected function editableSelect($value, Field $field, HTMLElement $previous): HTMLElement | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $element = new HTMLElement('select'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $element->setAttributes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             'id' => $field->getName() . Framework::counter(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             'name' => $field->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             'class' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             'data-attribute' => $field->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             'data-datatype' => $field->getDatatype()->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             'data-basetype' => $field->getDatatype()->getBasetype(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             'title' => $field->getExtension(static::LABEL, '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $optionEmpty = new HTMLElement('option', ['value' => ''], '', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $optionTrue = new HTMLElement('option', ['value' => 'true'], 'True', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $optionFalse = new HTMLElement('option', ['value' => 'false'], 'False', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         if ($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             $optionTrue->setAttribute('selected', 'selected'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         } elseif (!($value === null)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             $optionFalse->setAttribute('selected', 'selected'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         if ($field->getValidators()[Datatype::REQUIRED] ?? false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |             $element->addContent($optionEmpty); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $element->addContent($optionFalse); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $element->addContent($optionTrue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         foreach ([static::DISABLED, static::READONLY] as $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             if ($field->getExtension($v, false)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                 $element->setAttribute($v, $v); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         return $element; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 152 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 153 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.