* @author Gabriele Droege, Sybille Buers, Patricia Kelbert (BGBM, GGBN) * @version 1.0 * @package Package * @var $model SearchForm * @var $selectionLists - created in the controller * @var $form CActiveForm * @var $htmlOpts Design facts * @copyright Copyright (c) 2007-2020 Botanic Garden and Botanical Museum Berlin http://www.bgbm.org * @filesource * @license http://www.mozilla.org/MPL */ class CreateFormManager { // // create parameters for autosuggest widgets: public static function autosuggestOptions($model, $listTitle, $htmlOptions, $placeholder, $selectedValue) { if($placeholder != "") { $placeholder = $placeholder; } else { $placeholder = "Filter as you type..."; } if (isset ( $htmlOptions )) { if (isset ( $htmlOptions ['value'] )) //$model->$htmlOptions ['name'] = $htmlOptions ['value']; PHP5 $htmlOptions ['name'] = $htmlOptions ['name']; //PHP7 das eben eingegebene wird aber nicht mehr ausgegeben } $url = Yii::$app->getUrlManager ()->createUrl ( 'serverscripts/suggestion-list' ); if (! Yii::$app->params ['noBack']) { try { $template = ''; } catch ( Exception $e ) { try { $template = ''; } catch ( Exception $e ) { $template = ''; } } } else{ try { $template = ''; } catch ( Exception $e ) { try { $template = ''; } catch ( Exception $e ) { $template = ''; } } } // Yii::info("form template: ".$template); $formValues = [ ]; return [ 'options' => [ 'placeholder' => $placeholder, 'value' => $selectedValue ], 'pluginOptions' => [ 'highlight' => FALSE ], 'dataset' => [ [ 'remote' =>['url'=> $url . '?listTitle=' . $listTitle . '&term=%QUERY', 'wildcard' => '%QUERY',], 'display' => 'value', 'limit' => 50, 'templates' => [ 'empty' => '
Unable to find records for selected query.

You can continue with logical operators or wildcards.

Need help? Visit our How to page.
', 'suggestion' => new JsExpression ( "Handlebars.compile('{$template}')" ) ] ] ] ]; } public static function createField($controller, $model, $form, $key, $param, $selectionLists, $htmlOpts, $selectedValue, $label, $placeholder) { $currentType = "test"; foreach ( $param as $paramKey => $paramV ) if (strcmp ( $paramKey, "type" ) == 0) $currentType = $paramV; // Yii::info ( "currenttype : " . $currentType ); switch ($currentType) { case 'select' : if($label) { $label = $model->getAttributeLabel($key); } else { $label = ''; } // get the values either from the definition in the form model // or from the index if (isset ( $param ['valueList'] )) { $attributeList = $param ['valueList']; } else // get selection list from index { // actually the the field should never be not set! $attributeList = isset ( $selectionLists ) ? $selectionLists [$key] : array (); } $selectField = [ ]; foreach ( $attributeList as $kk => $vv ) { if ($key === "sampletype" && $vv != "---") { if (preg_match ( "/ \(\d* \/ \d*\)/", $vv )) $selectField [preg_replace ( "/ \(\d* \/ \d*\)/", "", $vv )] = "records with " . $vv; else $selectField [preg_replace ( "/ \(\d*\)/", "", $vv )] = "records with " . $vv; } else { if (preg_match ( "/ \(\d* \/ \d*\)/", $vv )) $selectField [preg_replace ( "/ \(\d* \/ \d*\)/", "", $vv )] = $vv; else $selectField [preg_replace ( "/ \(\d*\)/", "", $vv )] = $vv; } } // as the select tag we use here, uses the size attribute not for the length of the // field, we move the value to a style attribute if (isset ( $htmlOpts ['size'] )) { $size = $htmlOpts ['size']; unset ( $htmlOpts ['size'] ); } else { $size = $model->getFieldSize () * 8; } // Rukeia 16-03-2015: $onlyFieldName contains the $selectionLists values without record counts in brackets behind, e.g., "Algeria" instead of "Algeria (49)" $onlyFieldName = array (); foreach ( $selectionLists [$key] as $value ) { if (preg_match ( "/ \(\d* \/ \d*\)/", $value )) $value = preg_replace ( "/ \(\d* \/ \d*\)/", "", $value ); else $value = preg_replace ( "/ \(\d*\)/", "", $value ); array_push ( $onlyFieldName, $value ); } // Rukeia 16-03-2015: $listPos is the position of the selected value in $selectionLists $listPos = array_search ( $selectedValue, $onlyFieldName ); $model->$key = $selectedValue; echo $form->field ( $model, $key )->dropdownList ( $selectField, [ '$key' ])->label($label); break; case 'suggest' : if($label) { $label = $model->getAttributeLabel($key); } else { $label = ''; } if($placeholder) { $placeholder = $model->getAttributeLabel($key); } else { $placeholder = ''; } $options = self::autosuggestOptions ( $model, $key, $htmlOpts, $placeholder, $selectedValue ); echo $form->field ( $model, $key )->widget ( Typeahead::classname (), $options )->label ( $label ); break; case 'number' : if($label) { $label = $model->getAttributeLabel($key); } else { $label = ''; } echo $form->numberField ( $model, $key, $htmlOpts )->label ( $label ); break; // TODO do we need range bars? case 'range' : // foreach ( $htmlOpts as $ht => $hv ) // Yii::info ( $ht . " ==> " . $hv ); echo FieldRange::widget ( [ // 'form' => $form, // 'model' => $model, 'label' => $key, // 'attribute1' => $htmlOpts["attribute1"], // 'attribute2' => $htmlOpts["attribute2"], 'name1' => $htmlOpts ["attribute1"], 'options1' => [ "placeholder" => $htmlOpts ["attribute1value"] ], 'name2' => $htmlOpts ["attribute2"], 'type' => $htmlOpts ["type"], 'label' => $htmlOpts ["name"], 'options2' => [ "placeholder" => $htmlOpts ["attribute2value"] ] ] ); if (isset ( $htmlOpts ["attribute3"] )) { echo FieldRange::widget ( [ // 'form' => $form, // 'model' => $model, // 'attribute1' => $htmlOpts["attribute1"], // 'attribute2' => $htmlOpts["attribute2"], 'name1' => $htmlOpts ["attribute3"], 'options1' => [ "placeholder" => $htmlOpts ["attribute3value"] ], 'name2' => $htmlOpts ["attribute4"], 'options2' => [ "placeholder" => $htmlOpts ["attribute4value"] ], 'type' => $htmlOpts ["type"] ] ); } break; case 'checkbox' : $model->$key=$selectedValue; echo $form->field($model, $key)->widget(CheckboxX::classname(), [ 'autoLabel'=>true, 'name'=>$htmlOpts ["name"],'pluginOptions'=>['threeState'=>false], 'labelSettings' => ['options'=>['class'=>'custom-control-label']] ])->label(false); // echo $form->field($model, $key)->checkbox (); break; case 'radio' : $model->$key=$selectedValue; if($key==='cites') echo $form->field ( $model, $key )->radioList ( [ 'exclude' => 'Exclude listed species', 'include' => 'Include listed species', 'citesOnly' => 'Only listed species' ] ); if($key==='sampleavailability') echo $form->field ( $model, $key )->radioList ( [ 'only' => 'only available samples', 'all' => 'all samples' ] ); if($key==='accessionStatus') if(!isset($model->$key)) { $model->$key = 'onlyLiving'; } echo $form->field ( $model, $key )->radioList ( [ 'onlyLiving' => 'only living accessions', 'onlyDead' => 'only dead accessions', 'all' => 'all accessions' ] ); echo "
"; break; case 'text' : if($label) { $label = $model->getAttributeLabel($key); } else { $label = ''; } echo $form->field ( $model, $key )->textInput ( $htmlOpts )->label ( $label ); break; case 'hidden' : echo $form->field ( $model, $key )->hiddenInput ()->label ( '' ); break; default : if($label) { $label = $model->getAttributeLabel($key); } else { $label = ''; } // echo $form->textField ( $model, $key, $htmlOpts ); echo $form->field ( $model, $key )->textInput ( $htmlOpts )->label ( $label ); break; } //End switch } public static function prepareFormFields ($model, $form, $selectionLists, $primaryObject, $cssClassSearchFields, $label, $placeholder) { $elements = $model->getParameters (); echo $form->errorSummary ( $model ); echo ""; foreach ( $elements as $key => $param ) { $tohandle = false; foreach ( $param as $k => $toto ) { try { if (isset ( $param ['type'] )) { if (isset ( $param ['hidden'] )) $tohandle = false; else $tohandle = TRUE; $type = $param ['type']; } } catch ( Exception $e ) { } } if ($tohandle) { // 1. preparation for the field generation $htmlOpts = isset ( $param ['config'] ) ? $param ['config'] : array (); if($placeholder) { $htmlOpts += array ( 'placeholder' => $model->getAttributeLabel($key)); } // if the field is hideable // it's set not displayed in the first place // and it gets a button to hide it again: if (isset ( $param ['hideable'] ) && $param ['hideable'] == 'true') { $hide_option = "style=\"display:none;\""; $hide_button = "request->baseUrl . "/images/close.png \" parent_name=\"" . $key . "\" class=\"hide_button\" alt=\"close\"/>"; } else { $hide_option = ""; $hide_button = ""; } // use default size if no size is given if (! isset ( $param ['config'] ['size'] )) { $param ['config'] ['size'] = $model->getFieldSize (); } // surround label and fields with div echo "
"; // echo "
"; // 2. label - could be common text label or drop down choice // choose whether the label is a dropdown choice: if (isset ( $param ['alt'] ) && is_array ( $param ['alt'] ) && sizeof ( $param ['alt'] > 0 )) { $altList = array ( $key ) + $param ['alt']; // Yii::info ( "altList : " . implode ( $altList, "\n" ) ); // echo "
"; echo Html::dropDownList ( $key, $key, $altList, $htmlOptions = array ( 'class' => "dropDownLabel", 'id2' => $key ) ); $htmlOpts += array ( "class" => "hasSelectableLabel_" . $key, "id2" => $key ); $alt = true; } else { $altList = null; $form->field ( $model, $key )->label ( $key ); $alt = false; } // 3. field itself (different types -depending on $type self::createField ( $primaryObject, $model, $form, $key, $param, $selectionLists, $htmlOpts, $selectedValue = NULL, $label, $placeholder); // if there are alternate fields create them and hide them: if ($alt) { if (isset ( $htmlOpts ['style'] )) { $htmlOpts ['style'] += " display:none;"; } else { $htmlOpts ['style'] = "display:none;"; } foreach ( $altList as $altField ) { unset ( $param ['valueList'] ); self::createField ( $primaryObject, $model, $form, $altField, $param, $selectionLists, $htmlOpts, $selectedValue = NULL, $label, $placeholder); } } echo "
"; } } } public static function prepareUpdateFormFields ($form, $model, $elements, $this, $filters, $cssClassSearchFields, $selectionLists, $label, $placeholder) { echo $form->errorSummary ( $model ); echo ""; $suggestFields = [ 'fullScientificName' , 'sequenceaccessionIdentifier', 'country', 'continent', 'ocean', 'sea', 'geneticlocus', 'genusName', 'speciesName' ]; $defaultFields = [ 'familyName', 'phylumName', 'className', 'orderName', 'unitID', 'ipen', 'locality', 'collectors', 'collectornumber' , 'unitaccessionnumber', 'geneticlocus', 'preparationtype' ]; $selectFields = [ 'kingdom', 'institution', 'voucherCol', 'sampletype', 'indexHerbarorium' ]; $buttonFields=['hasTypestatus', 'hasImage','sampleavailability', 'cites']; $radioB=[]; foreach ( $elements as $key => $param ) { if (isset ( $param ['type'] )) { // echo "param config :".$param ['config'] ['name']."
"; // 1. preparation for the field generation $type = $param ['type']; $selectedValue = ''; foreach ( $suggestFields as $tf ) if ($param ['config'] ['name'] == $tf && isset ( $filters [$tf] )) { $param ['config'] ['value'] = $filters [$tf]; $selectedValue = $filters [$tf]; $param ['type'] = 'suggest'; } foreach ( $defaultFields as $tf ) if ($param ['config'] ['name'] == $tf && isset ( $filters [$tf] )) { $param ['config'] ['value'] = $filters [$tf]; $selectedValue = $filters [$tf]; $param ['type'] = 'default'; } foreach ( $buttonFields as $tf ) if ($param ['config'] ['name'] == $tf && isset ( $filters [$tf] )) { $param ['config'] ['value'] = $filters [$tf]; $selectedValue = $filters [$tf]; $radioB[$tf] = $filters [$tf]; } if ($param ['config'] ['name'] == 'Multimedia' && isset ( $filters ['hasImage'] )) { $param ['config'] ['value'] = $filters ['hasImage']; $selectedValue = $filters ['accessionStatus']; $param ['type'] = 'checkbox'; } if ($param ['config'] ['name'] == 'Type status' && isset ( $filters ['hasTypestatus'] )) { $param ['config'] ['value'] = $filters ['hasTypestatus']; $selectedValue = $filters ['hasTypestatus']; $param ['type'] = 'checkbox'; } if ($param ['config'] ['name'] == 'Has reviewed identification' && isset ( $filters ['identifiedby'] )) { $param ['config'] ['value'] = $filters ['identifiedby']; $selectedValue = $filters ['identifiedby']; $param ['type'] = 'checkbox'; } if ($param ['config'] ['name'] == 'accStatus' && isset ( $filters ['accessionStatus'] )) { $param ['config'] ['value'] = $filters ['accessionStatus']; $selectedValue = $filters ['accessionStatus']; $param ['type'] = 'radio'; } if ($param ['config'] ['name'] == 'cites' && isset ( $filters ['cites'] )) { $param ['config'] ['value'] = $filters ['cites']; $selectedValue = $filters ['accessionStatus']; $param ['type'] = 'radio'; } if ($param ['config'] ['name'] == 'Coordinates' && (isset ( $filters ['latitudeFrom'] ) || isset ( $filters ['latitudeTo'] ) || isset ( $filters ['longitudeTo'] ) || isset ( $filters ['longitudeFrom'] ))) { handleCoordinates ( $filters,$key,$param, $selectionLists, $this, $model, $form, $selectedValue); } if ($param ['config'] ['name'] == 'Collection Year' && (isset ( $filters ['collectionYearFrom'] ) || isset ( $filters ['collectionYearTo'] ))) { handleGatheringyear ( $filters,$key,$param, $selectionLists, $this, $model, $form, $selectedValue ); } foreach ( $selectFields as $tf ) if ($param ['config'] ['name'] == $tf && isset ( $filters [$tf] )) { $selectedValue = $filters [$tf]; $param ['type'] = 'select'; $param ['config'] ['value'] = $filters [$tf]; } $htmlOpts = isset ( $param ['config'] ) ? $param ['config'] : []; // Rukeia 30-03-2015: If the field was not used for the search, it's set not to be displayed in the // first place and it gets a button to hide it again: if (! isset ( $param ['config'] ['value'] ) && $selectedValue == '') { // Rukeia 30-03-2015: added $hide_option = "style=\"display:none;\""; $hide_button = "request->baseUrl . "/images/close.png \" parent_name=\"" . $key . "\" class=\"hide_button\" alt=\"close\"/>"; } else { $hide_option = ""; $hide_button = "request->baseUrl . "/images/close.png \" parent_name=\"" . $key . "\" class=\"hide_button\" alt=\"close\"/>"; } // use default size if no size is given if (! isset ( $param ['config'] ['size'] )) { $param ['config'] ['size'] = $model->getFieldSize (); } // surround label and fields with div echo "
"; // 2. label - could be common text label or drop down choice // choose whether the label is a dropdown choice: if (isset ( $param ['alt'] ) && is_array ( $param ['alt'] ) && sizeof ( $param ['alt'] > 0 )) { $altList = array ( $key ) + $param ['alt']; echo Html::dropDownList ( $key, $key, $altList, $htmlOptions = array ( 'class' => "dropDownLabel", 'id2' => $key ) ); $htmlOpts += array ( "class" => "hasSelectableLabel_" . $key, "id2" => $key ); $alt = true; } else { $altList = null; // echo $form->labelEx ( $model, $key ); $form->field ( $model, $key )->label ( $key ); $alt = false; } echo $hide_button; // 3. field itself (different types -depending on $type self::createField ( $this, $model, $form, $key, $param, $selectionLists, $htmlOpts, $selectedValue, $label, $placeholder); // if there are alternate fields create them and hide them: if ($alt) { if (isset ( $htmlOpts ['style'] )) { $htmlOpts ['style'] += " display:none;"; } else { $htmlOpts ['style'] = "display:none;"; } foreach ( $altList as $altField ) { unset ( $param ['valueList'] ); self::createField ( $this, $model, $form, $altField, $param, $selectionLists, $htmlOpts, $selectedValue, $label, $placeholder ); } } echo "
"; } } } public static function AddAccordion ($headerTitle, $headerClass, $itemContent) { echo Accordion::widget ( [ 'items' => [ [ 'header' => $headerTitle, 'content' => $itemContent ] ], 'options' => [ 'tag' => 'div', 'autoHeight' => false, 'active' => false, 'delay' => '100' ], 'itemOptions' => [ 'tag' => 'div', 'class' => 'balmusette_search' ], 'headerOptions' => [ 'tag' => 'button', 'class' => $headerClass ], 'clientOptions' => [ 'collapsible' => true, 'active' => false ] ] ); } } ?>