Example #1
0
 public function actionNdff()
 {
     echo "=== Starting export sequence at " . date("d-m-Y h:i") . " ===\r\n";
     echo "Fetching all records from the 'observations' table where ndff_id is empty or ndiff_failed is filled\r\n";
     $observations = Observations::find()->where(['or', ['is', 'ndff_id', NULL], ['not', ['ndff_failed' => NULL]]]);
     echo "Found " . $observations->count() . " records, continuing\r\n";
     echo "Looping trough all the results\r\n";
     foreach ($observations->all() as $observation) {
         if ($observation->observation_method == Observations::OBSERVATION_TYPE_NULL) {
             continue;
         }
         $ndffObservation = new \NDFF\Observation();
         $ndffObservation->setLifestage('http://ndff-ecogrid.nl/codes/domainvalues/observation/lifestages/unknown');
         $ndffObservation->setLocation(0, '', 'http://ndff-ecogrid.nl/codes/locationtypes/point');
         $ndffObservation->setPeriodstart(date('o-m-d\\TH:i:s', strtotime($observation->visit->date)));
         $ndffObservation->setScaleidentity('http://ndff-ecogrid.nl/codes/scales/exact_count');
         if ($observation->catch_sex != Observations::CATCH_SEX_UNKNOWN) {
             $sexUrlParameter = $observation->catch_sex == Observations::CATCH_SEX_MALE ? 'male' : 'female';
             $ndffObservation->setSex('http://ndff-ecogrid.nl/codes/domainvalues/observation/sexes/' . $sexUrlParameter);
         }
         $ndffObservation->setSubjecttypeidentity('http://ndff-ecogrid.nl/codes/subjecttypes/live/individual');
         echo "Attempting to write observation " . $observation->id . " to NDFF database\r\n";
         $ndffRequest = new \NDFF\ApiRequest('telmee', 'onsjos', '********');
         $ndffRequest->set_request_data($ndffObservation);
         $ndffRequest->resource_post('observation');
     }
     echo "All done!\r\n";
 }
Example #2
0
 public function actionForm($id = NULL)
 {
     $model = $id ? Visits::findOne($id) : new Visits();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         /* Check if it is a new record before we save it  */
         $newRecord = $model->isNewRecord;
         /* Attempt to save model */
         if ($model->save(false)) {
             /* Only when the record is new */
             if ($newRecord) {
                 /* Register null-observations for un-checked boxes if available */
                 if (!$model->checked_all) {
                     foreach ($model->project->boxes as $box) {
                         if (in_array($box->id, $model->checked_boxes)) {
                             Observations::createNullObservation($model->id, $box->id);
                         }
                     }
                 }
                 /* Register checked boxes */
                 if ($model->checked_boxes) {
                     $model->unlinkAll('visitBox', true);
                     foreach ($model->checked_boxes as $checkedBox) {
                         $visitBoxModel = new VisitBoxes();
                         $visitBoxModel->box_id = $checkedBox;
                         $visitBoxModel->link('visit', $model);
                         $visitBoxModel->save();
                     }
                 }
                 /* Register null-observations for all boxes in project when "checked-all" is selected */
                 if ($model->checked_all) {
                     foreach ($model->project->boxes as $box) {
                         Observations::createNullObservation($model->id, $box->id);
                     }
                 }
             }
             /* Register observers by this visit */
             if ($model->observers) {
                 $model->unlinkAll('observers', true);
                 foreach ($model->observers as $observer) {
                     $visitObservers = new VisitObservers();
                     $visitObservers->observer_id = $observer;
                     $visitObservers->link('visit', $model);
                     $visitObservers->save();
                 }
             }
             /* Redirect on success */
             return $this->redirect(Url::toRoute('visits/detail/' . $model->id));
         }
     }
     return $this->render('form', ['model' => $model, 'projects' => Projects::find()->hasRights()->hasBoxes()->all()]);
 }
Example #3
0
 public function search($params, $personal = false)
 {
     /* User identifier */
     $userIdentifier = \Yii::$app->user->getId() ? \Yii::$app->user->getId() : 0;
     /* Base query */
     $query = Observations::find();
     /* Joins */
     $query->join('LEFT JOIN', 'boxes', '"observations"."box_id" = "boxes"."id" AND "boxes"."deleted" = FALSE');
     $query->join('LEFT JOIN', 'visits', '"observations"."visit_id" = "visits"."id" AND "visits"."deleted" = FALSE');
     $query->join('LEFT JOIN', 'projects', '"boxes"."project_id" = "projects"."id" AND "projects"."deleted" = FALSE');
     $query->join('LEFT JOIN', 'project_counters', '"projects"."id" = "project_counters"."project_id" AND "project_counters"."user_id" = :user_id', ['user_id' => $userIdentifier]);
     /* Conditions */
     $query->where(['and', ['observations.deleted' => false], ['not', ['visits.id' => NULL]], ['not', ['boxes.id' => NULL]], ['not', ['projects.id' => NULL]], ['or', ['is', '"visits"."embargo"', NULL], ['<=', '"visits"."embargo"', 'NOW()'], ['in', 'visit_id', (new Query())->select('id')->from(VisitObservers::tableName())->where(['observer_id' => $userIdentifier])]], ['<>', 'observations.observation_type', Observations::OBSERVATION_TYPE_NULL]]);
     if (!is_object(Yii::$app->user->getIdentity()) || is_object(Yii::$app->user->getIdentity()) && !Yii::$app->user->getIdentity()->hasRole(['validator', 'administrator'])) {
         $query->andWhere(['or', ['"projects"."owner_id"' => $userIdentifier], ['"projects"."main_observer_id"' => $userIdentifier], ['or', ['is', '"projects"."embargo"', NULL], ['<=', '"projects"."embargo"', 'NOW()']], ['is not', '"project_counters"."user_id"', NULL]]);
     }
     $query->andWhere(['and', ['"projects"."deleted"' => false], ['"boxes"."deleted"' => false], ['"visits"."deleted"' => false], ['"observations"."deleted"' => false]]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     return $dataProvider;
 }
Example #4
0
<?php 
View::beginJs();
?>
	<script>
		/* Variables */
		var species 					= <?php 
echo json_encode($species);
?>
;
		var sexualStatusOptionsMale 	= <?php 
echo json_encode(Observations::getCatchSexualStatusOptions(Observations::CATCH_SEX_MALE));
?>
;
		var sexualStatusOptionsFemale 	= <?php 
echo json_encode(Observations::getCatchSexualStatusOptions(Observations::CATCH_SEX_FEMALE));
?>
;
		
		/* Species */
		$(document).on('change', '[data-taxon-identifier]', speciesSelector);
		speciesSelector();

		function speciesSelector() {
			HoldOn.open();
			$('[data-species-identifier]').empty();
			jQuery.each(species, function(index, value) {
				if(value.taxon == $('[data-taxon-identifier]').val()) {
					var selected = (<?php 
echo $model->species_id ? $model->species_id : "0";
?>
Example #5
0
 public function getObservations()
 {
     return $this->hasMany(Observations::className(), ['visit_id' => 'id']);
 }
Example #6
0
 public static function createNullObservation($visit_id, $box_id)
 {
     $observationModel = new Observations();
     $observationModel->visit_id = $visit_id;
     $observationModel->box_id = $box_id;
     $observationModel->observation_type = self::OBSERVATION_TYPE_NULL;
     if ($observationModel->isNewRecord) {
         $observationModel->number = $observationModel->visit->observation_counter + 1;
     }
     $observationModel->save(false);
     $observationModel->visit->observation_counter++;
     $observationModel->visit->save();
 }
Example #7
0
 public function getObservations()
 {
     return $this->hasmany(Observations::className(), ['species_id' => 'id']);
 }
 public function actionValidate($id)
 {
     if (!($observation = Observations::findOne($id)) == false) {
         $observation->markAsValidated();
     }
     return $this->redirect(Url::toRoute('observations/detail/' . $id));
 }
Example #9
0
<?php

use fedemotta\datatables\DataTables;
use yii\helpers\Url;
use yii\helpers\Html;
use app\models\Visits;
use app\models\Observations;
use app\models\Boxtypes;
use app\models\ProjectClusters;
?>
<div class="table-responsive">
	<?php 
echo DataTables::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'code', 'format' => 'html', 'value' => function ($model, $key, $index, $column) {
    return Html::a($model['code'], Url::toRoute('boxes/detail/' . $model['id']));
}], ['attribute' => 'boxtype_id', 'format' => 'html', 'label' => 'Boxtype', 'value' => function ($model, $key, $index, $column) {
    $boxType = $model['boxtype_id'] ? Boxtypes::findOne($model['boxtype_id']) : NULL;
    return $boxType ? Html::a($boxType->model, Url::toRoute('boxtypes/detail/' . $boxType->id)) : "-";
}], ['attribute' => 'cluster_id', 'format' => 'html', 'label' => 'Cluster', 'value' => function ($model, $key, $index, $column) {
    $cluster = $model['cluster_id'] ? ProjectClusters::findOne($model['cluster_id']) : NULL;
    return $cluster ? $cluster->cluster : '-';
}], ['attribute' => 'placement_date', 'label' => Yii::t('app', 'Plaatsingsdatum')], ['label' => Yii::t('app', 'Laatste waarneming'), 'value' => function ($model, $key, $index, $column) {
    if (($observationModel = Observations::find()->byBox($model['id'])->one()) !== NULL) {
        return Visits::findOne($observationModel->visit_id)->date;
    } else {
        return "-";
    }
}]], 'clientOptions' => ['info' => false, 'responsive' => true, 'dom' => 'lfTrtip', 'tableTools' => ['aButtons' => [['sExtends' => 'copy', 'sButtonText' => Yii::t('app', 'Copy to clipboard')], ['sExtends' => 'csv', 'sButtonText' => Yii::t('app', 'Save to CSV')], ['sExtends' => 'pdf', 'sButtonText' => Yii::t('app', 'Save to PDF')], ['sExtends' => 'print', 'sButtonText' => Yii::t('app', 'Print')]]]]]);
?>
</div>