<?php

namespace app\models;

use Yii;
use yii\base\Model;
use common\models\CommonSearchForm;

/**
 * instructions
 * this model provides a structure for the form.
 * here you can modify all the parameter for the content of the form:
 * mainly fields and their types
 * and also some othr parameter such as which string is shown
 * in a selection list as default
 *
 * how to define fields:
 * you have to add each field to the
 * field definitions section ,
 * field declarationss section and
 * the rules() function
 * (see below at the corresponding section for further infos)
 *
 * you also have to define what queries are generated from the user
 * input of each field. do this in the QueryFactory.
 * make sure you use the same name in all 4 places!
 * and is the same name as in the correspondint solr index field!
 *
 * you also can add a label for the field in the attributeLabels() function
 * by default the label is generatet automatically
 * by changing camelcase to single words
 * and start each word upper case
 * e.g. familyName will get the label: Family Name
 *
 * you also can define more form parameters in the other settings section
 * (see below)
 *
 * this form is used by the SearchController
 * that runs the search view (views.search.search.php) customized for this model.
 *
 * @author s.buers
 *        
 */
class SearchForm extends CommonSearchForm {
	
	// ------------- field definitions -----------------------------
	// here you define all parameters/fields for the form
	// in an array of key=>value:
	// key: name of the field
	// value is an array of parameters to define the field:
	// type: is required! and must be one of the following:
	// text: usual text field
	// checkbox: shows checkbox returns value
	// select: creates a selection list (drop down)
	// if a the parameter 'valueList' is set (to an array of strings)
	// it will be shown.
	// if it is not set, the list will be generated from the index
	// therefore the field name must match an index field
	// (if not an error will appear)
	// suggest: a field that provides suggestion on the input the user makes
	// number: creates a number field, where the user can choose integers.
	// it is recommended to define 'min' and 'max' in the 'config' array
	// deactivated: the field will not be writable
	// hideable: set to 'true' if the field can be added by the user on demand
	// config: is an array of attributes for the <input> elements
	// e.g. 'size' or 'maxlength'
	// e.g. 'familyName' =>['type'=>'text', 'config'=>[size'=>45,'maxlength'=>45))
	// (this will end up in a field like this:
	// <input size="45" maxlength="45" name="SearchForm[familyName]" id="SearchForm_familyName" type="text" />)
	// alt: if you have a group of fields, that have to be chosen one of them exclusively.
	// create a field in the field declaration section for each but only one in the
	// field definition section with the default selection and put the names of the
	// others in the 'alt' parameter see: familyName
	// TODO do we need or want this static???
	
	public $knownLParams = [
			'country',
			'geneticlocus',
			'continent',
			'sea',
			'ocean',
			'sampletype',
			'collectioncode',
			'institutioncode',
			'indexHerbarorium'
	];
	public $knownParams = [
			'fullScientificName',
			'genusName',
			'speciesName',
			'kingdom',
			'sequenceaccessionIdentifier',
			'unitID',
			'locality',
			'collectors',
			'collectornumber',
			'institution',
			'voucherCol',
			'collectionYearFrom',
			'collectionYearTo',
			'latitudeTo',
			'latitudeFrom',
			'longitudeTo',
			'longitudeFrom',
			'cites',
			'hasImage',
			'hasTypestatus',
			'sampleavailability',
			'institutioncode',
			'collectioncode',
			'preparationtype',
			'ipen',
			'unitaccessionnumber',
			'accessionStatus',
			'identifiedBy'
	];
	
	public $_parameters = [
			'fullScientificName' => [ 
					'type' => 'suggest',
					'config' => [ 
							'size' => 45,
							'maxlength' => 150,
							'name' => 'fullScientificName' 
					],
					'class' => 'test',
					'name' => 'Scientific name' 
			],
			
			'country' => [ 
					'type' => 'suggest',
					'config' => [ 
							'size' => 285,
							'maxlength' => 150,
							'name' => 'country' 
					],
					'name' => 'Country' 
			],
			'locality' => [
					'type' => 'text',
					'name' => 'Locality',
					'config' => [
							'size' => 45,
							'maxlength' => 150,
							'name' => 'locality'
					],
					// 					'hideable' => 'true'
			],
			
			'collectors' => [
					'type' => 'text',
					'name' => 'Collector(s)',
					'config' => [
							'size' => 45,
							'maxlength' => 150,
							'name' => 'collectors'
					]
			]
			// 'hideable' => 'true'
			,
			'collectornumber' => [
					'type' => 'text',
					'name' => "Field or collector number",
					'config' => [
							'size' => 45,
							'maxlength' => 150,
							'name' => 'collectornumber'
					],
					'hideable' => 'true',
			]
			 
			,
			'unitID' => [ 
					'config' => [ 
							'size' => 45,
							'maxlength' => 150,
							'name' => 'unitID' 
					],
					'type' => 'text', // freigeschaltet von Gabi
					'name' => 'Observation ID',
					'hideable' => 'true',
			],
			'collectionYear' => [ 
					'type' => 'range',
					'config' => [ 
							'size' => 40,
							'width' => '150px',
							'name' => 'Collection Year',
							'attribute1' => 'collectionYearFrom',
							'attribute2' => 'collectionYearTo',
							'attribute1value' => 'collectionYearFrom',
							'attribute2value' => 'collectionYearTo',
							'type' => \kartik\field\FieldRange::INPUT_TEXT 
					],
					'hideable' => 'true',
					'name' => 'Collection Year' 
			],
			
			
			'continent' => [ 
					'type' => 'suggest',
					'name' => 'Continent',
					'config' => [ 
							'size' => 285,
							'maxlength' => 150,
							'name' => 'continent' 
					],
					'hideable' => 'true' 
			],
			'coordinates' => [ 
					'type' => 'range',
					'config' => [ 
							'size' => 40,
							'width' => '150px',
							'name' => 'Coordinates',
							'label' => 'Latitude',
							'attribute1' => 'latitudeFrom',
							'attribute2' => 'latitudeTo',
							'attribute1value' => 'latitudeFrom',
							'attribute2value' => 'latitudeTo',
							'label2' => 'Longitude',
							'attribute3' => 'longitudeFrom',
							'attribute4' => 'longitudeTo',
							'attribute3value' => 'longitudeFrom',
							'attribute4value' => 'longitudeTo',
							'type' => \kartik\field\FieldRange::INPUT_TEXT 
					],
					'hideable' => 'true',
					'name' => 'Coordinates' 
			],
			
			'ocean' => [ 
					'type' => 'suggest',
					'name' => 'Ocean',
					'config' => [ 
							'size' => 285,
							'maxlength' => 150,
							'name' => 'ocean' 
					],
					'hideable' => 'true' 
			], 
			'sea' => [ 
					'type' => 'suggest',
					'name' => 'Sea',
					'config' => [ 
							'size' => 285,
							'maxlength' => 150,
							'name' => 'sea' 
					],
					'hideable' => 'true' 
			],

						
	];
	

	/*
	 * ----------------- other settings ----------------------------
	 *
	 *These settings will overwrite the default setting in common/models/CommonSearchForm
	 */
	// title of the form:
	
// 	private $_extendedSearchFormTitle = 'SEARCH';
// 	private $_previewTitle = 'RESULTS OVERVIEW';
// 	private $_detailsTitle = 'DETAILS';
	
// 	search button text:
// 	private $_extendedSearchButtonLabel = 'Search'; // Rukeia 16-02-2015: Das ist das Search-Button-Label.
 	private $_refineSearchButtonLabel = 'Search';
// 	private $_newSearchButtonLabel = 'New search';
// 	private $_saveSearchButtonLabel = 'Save Search'; // Hartebrodt 22-07-15
// 	private $_searchName; // Hartebrodt 23-07-15: name a search to store it in the database
	                      
// 	what string represents if nothing is chosen in the drop down lists
// 	                      // (technically it leads to everything (*))
// 	private $_selectionListNonChosen = "---";
	
// 	string that is presented in a suggestion list if
// 	the input does not match to any item
// 	private $_sugesstionListNoMatch = "-- no match --";
	
// 	default size of fields
// 	- if you don't give a size in the definition area this value will be used
// 	private $_fieldSize = 50;
	
	                                    
	// ------------- getters--------------------------------------
	public function getParameters() {
		return $this->_parameters;
	}
// 	public function getExtendedSearchFormTitle() {
// 		return $this->_extendedSearchFormTitle;
// 	}
// 	public function getPreviewTitle() {
// 		return $this->_previewTitle;
// 	}
// 	public function getDetailsTitle() {
// 		return $this->_detailsTitle;
// 	}
// 	public function getExtendedSearchButtonLabel() {
// 		return $this->_extendedSearchButtonLabel;
// 	}
// 	public function getNewSearchButtonLabel() {
// 		return $this->_newSearchButtonLabel;
// 	}
	public function getRefineSearchButtonLabel() {
		return $this->_refineSearchButtonLabel;
	}
// 	public function getFieldsPerRow() {
// 		return $this->_fieldsPerRow;
// 	}
// 	public function getSelectionListNonChosen() {
// 		return $this->_selectionListNonChosen;
// 	}
// 	public function getSugesstionListNoMatch() {
// 		return $this->_sugesstionListNoMatch;
// 	}
// 	public function getHideableList() {
// 		return $this->_hideableList;
// 	}
// 	public function getHideableListFields() {
// 		return $this->_hideableListFields;
// 	}
// 	public function getCompleteList() { // Rukeia 30-03-2015: added
// 		return $this->_completeList;
// 	}
// 	public function getCompleteListFields() { // Rukeia 30-03-2015: added
// 		return $this->_completeListFields;
// 	}
// 	public function getFieldSize() {
// 		return $this->_fieldSize;
// 	}
	
	// @override
	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels() {
		return [ 
				'taxonomyId' => 'Taxonomy ID (NCBI)',
				'fullScientificName' => 'Scientific name',
				'sequenceaccessionIdentifier' => 'Genetic Accession Number',
				'geneticlocus' => 'Genetic Locus',
				'kingdom' => 'Kingdom',
				'hasImage' => 'Image available',
				'sampletype' => 'Sample Type',
                'preparationType' => 'Preparation Type',
				'hasTypestatus' => 'Type Specimen/Strain',
				'unitID' => 'Observation ID',
				'phylumName' => 'Phylum/Division Name',
				'continent' => 'Continent',
				'sea' => 'Sea',
				'locality' => 'Locality',
				'collectors' => 'Observed By',
				'collectornumber' => "Collector's number",
				'institution' => 'Repository',
				'voucherCol' => 'Voucher collection',
				'genBankRecordAvailable' => 'with Genetic Accession Number',
				'collectionYear' => 'Collection year',
				'coordinates' => 'Coordinates',
				'cites' => 'CITES list',
				'collectioncode' => 'Collection or subcollection',
				'institutioncode' => 'Institution code',
				'indexHerbarorium'=>'Index Herbariorum code'
		];
	}

	
}