<?php

/**
 * This is the model class for table "rawoccurrence".
 *
 * The followings are the available columns in table 'rawoccurrence':
 * @property integer $occurrenceid
 * @property string $created_when
 * @property string $gatheringdate
 * @property string $gatheringdatebegin
 * @property string $gatheringdateend
 * @property string $country
 * @property string $isocountrycode
 * @property string $locality
 * @property integer $fk_recordbasisid
 * @property integer $fk_kindofunitid
 * @property string $collectornumber
 * @property string $fieldnumber
 * @property string $guid
 * @property string $accessionnumber
 * @property integer $fk_datasourceid
 * @property string $minDepth
 * @property string $maxDepth
 * @property string $minAltitude
 * @property string $maxAltitude
 * @property integer $fk_sha1sumid
 * @property integer $fk_tripleidstoreid
 * @property string $gatheringareas
 * @property string $establishmentMeans
 * @property string $recordURI
 *
 * The followings are the available model relations:
 * @property Collectors[] $collectors
 * @property Identification[] $identifications
 * @property Measurementorfacts[] $measurementorfacts
 * @property Rawcoordinates[] $rawcoordinates
 * @property Rawidentification[] $rawidentifications
 * @property Tripleidstore $fkTripleidstore
 * @property Sha1responses $fkSha1sum
 * @property Recordbasis $fkRecordbasis
 * @property BioDatasource $fkDatasource
 * @property Unitkind $fkKindofunit
 * @property Rawstratigraphy[] $rawstratigraphies
 * @property Typedesignation[] $typedesignations
 * @property Unitaccessionnumber[] $unitaccessionnumbers
 */
class Rawoccurrence extends CActiveRecord {
	/**
	 *
	 * @return string the associated database table name
	 */
	public function tableName() {
		return 'rawoccurrence';
	}
	
	/**
	 *
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array (
				array (
						'fk_recordbasisid, fk_kindofunitid, fk_datasourceid, fk_sha1sumid, fk_tripleidstoreid',
						'numerical',
						'integerOnly' => true 
				),
				array (
						'gatheringdate, gatheringdatebegin, gatheringdateend, country, minDepth, maxDepth, minAltitude, maxAltitude',
						'length',
						'max' => 45 
				),
				array (
						'isocountrycode',
						'length',
						'max' => 10 
				),
				array (
						'collectornumber, fieldnumber, guid, accessionnumber, establishmentMeans',
						'length',
						'max' => 255 
				),
				array (
						'recordURI',
						'length',
						'max' => 455 
				),
				array (
						'created_when, locality, gatheringareas',
						'safe' 
				),
				// The following rule is used by search().
				// @todo Please remove those attributes that should not be searched.
				array (
						'occurrenceid, created_when, gatheringdate, gatheringdatebegin, gatheringdateend, country, isocountrycode, locality, fk_recordbasisid, fk_kindofunitid, collectornumber, fieldnumber, guid, accessionnumber, fk_datasourceid, minDepth, maxDepth, minAltitude, maxAltitude, fk_sha1sumid, fk_tripleidstoreid, gatheringareas, establishmentMeans, recordURI',
						'safe',
						'on' => 'search' 
				) 
		);
	}
	
	/**
	 *
	 * @return array relational rules.
	 */
	public function relations() {
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array (
				'collectors' => array (
						self::HAS_MANY,
						'Collectors',
						'fk_occurrenceid' 
				),
				'identifications' => array (
						self::HAS_MANY,
						'Identification',
						'fk_occurrenceid' 
				),
				'measurementorfacts' => array (
						self::HAS_MANY,
						'Measurementorfacts',
						'fk_occurrenceid' 
				),
				'rawcoordinates' => array (
						self::HAS_MANY,
						'Rawcoordinates',
						'fk_occurrenceid' 
				),
				'rawidentifications' => array (
						self::HAS_MANY,
						'Rawidentification',
						'fk_occurrenceid' 
				),
				'fkTripleidstore' => array (
						self::BELONGS_TO,
						'Tripleidstore',
						'fk_tripleidstoreid' 
				),
				'fkSha1sum' => array (
						self::BELONGS_TO,
						'Sha1responses',
						'fk_sha1sumid' 
				),
				'fkRecordbasis' => array (
						self::BELONGS_TO,
						'Recordbasis',
						'fk_recordbasisid' 
				),
				'fkDatasource' => array (
						self::BELONGS_TO,
						'BioDatasource',
						'fk_datasourceid' 
				),
				'fkKindofunit' => array (
						self::BELONGS_TO,
						'Unitkind',
						'fk_kindofunitid' 
				),
				'rawstratigraphies' => array (
						self::HAS_MANY,
						'Rawstratigraphy',
						'fk_occurrenceid' 
				),
				'typedesignations' => array (
						self::HAS_MANY,
						'Typedesignation',
						'fk_occurrenceid' 
				),
				'unitaccessionnumbers' => array (
						self::HAS_MANY,
						'Unitaccessionnumber',
						'fk_occurrenceid' 
				) 
		);
	}
	
	/**
	 *
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array (
				'occurrenceid' => 'Occurrenceid',
				'created_when' => 'Created When',
				'gatheringdate' => 'Gatheringdate',
				'gatheringdatebegin' => 'Gatheringdatebegin',
				'gatheringdateend' => 'Gatheringdateend',
				'country' => 'Country',
				'isocountrycode' => 'Isocountrycode',
				'locality' => 'Locality',
				'fk_recordbasisid' => 'Fk Recordbasisid',
				'fk_kindofunitid' => 'Fk Kindofunitid',
				'collectornumber' => 'Collectornumber',
				'fieldnumber' => 'Fieldnumber',
				'guid' => 'Guid',
				'accessionnumber' => 'Accessionnumber',
				'fk_datasourceid' => 'Fk Datasourceid',
				'minDepth' => 'Min Depth',
				'maxDepth' => 'Max Depth',
				'minAltitude' => 'Min Altitude',
				'maxAltitude' => 'Max Altitude',
				'fk_sha1sumid' => 'Fk Sha1sumid',
				'fk_tripleidstoreid' => 'Fk Tripleidstoreid',
				'gatheringareas' => 'Gatheringareas',
				'establishmentMeans' => 'Establishment Means',
				'recordURI' => 'Record Uri' 
		);
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 *         based on the search/filter conditions.
	 */
	public function search() {
		// @todo Please modify the following code to remove attributes that should not be searched.
		$criteria = new CDbCriteria ();
		
		$criteria->compare ( 'occurrenceid', $this->occurrenceid );
		$criteria->compare ( 'created_when', $this->created_when, true );
		$criteria->compare ( 'gatheringdate', $this->gatheringdate, true );
		$criteria->compare ( 'gatheringdatebegin', $this->gatheringdatebegin, true );
		$criteria->compare ( 'gatheringdateend', $this->gatheringdateend, true );
		$criteria->compare ( 'country', $this->country, true );
		$criteria->compare ( 'isocountrycode', $this->isocountrycode, true );
		$criteria->compare ( 'locality', $this->locality, true );
		$criteria->compare ( 'fk_recordbasisid', $this->fk_recordbasisid );
		$criteria->compare ( 'fk_kindofunitid', $this->fk_kindofunitid );
		$criteria->compare ( 'collectornumber', $this->collectornumber, true );
		$criteria->compare ( 'fieldnumber', $this->fieldnumber, true );
		$criteria->compare ( 'guid', $this->guid, true );
		$criteria->compare ( 'accessionnumber', $this->accessionnumber, true );
		$criteria->compare ( 'fk_datasourceid', $this->fk_datasourceid );
		$criteria->compare ( 'minDepth', $this->minDepth, true );
		$criteria->compare ( 'maxDepth', $this->maxDepth, true );
		$criteria->compare ( 'minAltitude', $this->minAltitude, true );
		$criteria->compare ( 'maxAltitude', $this->maxAltitude, true );
		$criteria->compare ( 'fk_sha1sumid', $this->fk_sha1sumid );
		$criteria->compare ( 'fk_tripleidstoreid', $this->fk_tripleidstoreid );
		$criteria->compare ( 'gatheringareas', $this->gatheringareas, true );
		$criteria->compare ( 'establishmentMeans', $this->establishmentMeans, true );
		$criteria->compare ( 'recordURI', $this->recordURI, true );
		
		return new CActiveDataProvider ( $this, array (
				'criteria' => $criteria 
		) );
	}
	
	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * 
	 * @param string $className
	 *        	active record class name.
	 * @return Rawoccurrence the static model class
	 */
	public static function model($className = __CLASS__) {
		return parent::model ( $className );
	}
}