Exemplo n.º 1
0
 public function search($params, array $options = NULL)
 {
     /* User identifier */
     $userIdentifier = \Yii::$app->user->getId() ? \Yii::$app->user->getId() : 0;
     /* Base query */
     $query = Visits::find();
     /* Joins */
     $query->join('LEFT JOIN', 'projects', 'visits.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]);
     /* Clauses */
     if (isset($options['project_id']) && $options['project_id']) {
         $query->where(['project_id' => $options['project_id']]);
     }
     $query->where(['and', ['visits.deleted' => false], ['projects.deleted' => false]]);
     $query->andWhere(['or', ['"projects"."owner_id"' => $userIdentifier], ['"projects"."main_observer_id"' => $userIdentifier], ['and', ['or', ['is', '"projects"."embargo"', NULL], ['<=', '"projects"."embargo"', 'NOW()']], ['or', ['is', '"visits"."embargo"', NULL], ['<=', '"visits"."embargo"', 'NOW()']]], ['is not', '"project_counters"."user_id"', NULL]]);
     if (isset($options['personal']) && $options['personal']) {
         $query->personal();
     }
     if (isset($options['project_id'])) {
         $query->andWhere(['visits.project_id' => $options['project_id']]);
     }
     $query->andWhere(['and', ['"projects"."deleted"' => false], ['"visits"."deleted"' => false]]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionDelete($id)
 {
     $model = Visits::findOne($id);
     if ($model) {
         $model->deleted = true;
         $model->save(false);
     }
     foreach ($model->observations as $observation) {
         $observation->deleted = true;
         $observation->save(false);
     }
     return $this->redirect(Url::toRoute('visits/personal'));
 }
 public function actionForm($id = NULL)
 {
     $model = $id ? Observations::findOne($id) : new Observations();
     if (Yii::$app->getRequest()->getQueryParam('visit_id') && is_null($id)) {
         $model->visit_id = Yii::$app->getRequest()->getQueryParam('visit_id');
     }
     if ($model->load(Yii::$app->request->post())) {
         /* Load picture file */
         $model->pictureFile = UploadedFile::getInstance($model, 'pictureFile');
         /* Validate model */
         if ($model->validate()) {
             /* Upload picture */
             if ($model->pictureFile) {
                 $model->upload();
             }
             /* Delete picture if selected */
             if ($model->deleteImage && !$model->pictureFile) {
                 $model->picture = NULL;
             }
             /* Check for auto-validation on observqation */
             if (Yii::$app->user->getIdentity()->hasRole(['validator', 'administrator'])) {
                 $model->markAsValidated();
             }
             /* When the observation type equals a null-observation, clear all other fields */
             if ($model->observation_type == Observations::OBSERVATION_TYPE_NULL) {
                 foreach ($model->attributes as $attribute => $value) {
                     if (!in_array($attribute, ['id', 'visit_id', 'observation_type', 'validated_by_id', 'validated_date', 'box_id', 'date_created', 'date_updated', 'deleted'])) {
                         $model->{$attribute} = NULL;
                     }
                 }
             }
             $model->save(false);
             if ($model->observation_type != Observations::OBSERVATION_TYPE_NULL && Observations::find()->where(['and', ['deleted' => false], ['box_id' => $model->box_id], ['observation_type' => Observations::OBSERVATION_TYPE_NULL]])->exists()) {
                 foreach (Observations::find()->where(['and', ['deleted' => false], ['observation_type' => Observations::OBSERVATION_TYPE_NULL], ['box_id' => $model->box_id]])->all() as $nullObservation) {
                     $nullObservation->delete();
                 }
             }
             return $this->redirect(Url::toRoute(['visits/detail/' . $model->visit_id]));
         }
     }
     return $this->render('form', ['model' => $model, 'boxes' => Boxes::find()->where(['project_id' => Visits::findOne($model->visit_id)->project_id])->all(), 'species' => Species::find()->asArray()->all(), 'parasites' => Species::find()->where(['taxon' => Species::TAXONOMY_ARTHROPOD])->all()]);
 }
Exemplo n.º 4
0
					<div class="boxList"></div>
					<?php 
        if ($model->hasErrors('checked_boxes')) {
            ?>
<div class="help-block"><?php 
            echo $model->getErrors('checked_boxes')[0];
            ?>
</div><?php 
        }
        ?>
				</div>
			<?php 
    }
    ?>
			<?php 
    echo $form->field($model, 'count_completeness')->dropdownList(Visits::getCountCompletenessOptions());
    ?>
			<?php 
    echo $form->field($model, 'blur')->dropDownList(Projects::getBlurOptions());
    ?>
			<?php 
    echo $form->field($model, 'embargo')->widget(DatePicker::className(), ['type' => 1, 'options' => ['placeholder' => Yii::t('app', 'Selecteer datum')], 'pluginOptions' => ['format' => 'dd-mm-yyyy', 'todayHighlight' => true, 'autoclose' => true, 'weekStart' => 1]]);
    ?>
	    	<?php 
    echo $form->field($model, 'remarks')->widget(\yii\redactor\widgets\Redactor::className(), ['clientOptions' => ['buttons' => ['formatting', 'bold', 'italic', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'link', 'alignment', 'horizontalrule']]]);
    ?>
	    	<div class="form-group">
	            <?php 
    echo Html::submitButton(Yii::t('app', 'Opslaan'), ['class' => 'btn btn-primary pull-right']);
    ?>
	        </div>
Exemplo n.º 5
0
<?php

use app\models\Observations;
use app\models\Species;
use app\models\Visits;
use app\components\View;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\bootstrap\Html;
$observationModel = new Observations();
$visitModel = new Visits();
/* @var $model \app\models\Observations */
?>
<h1><?php 
echo Yii::t('app', 'Waarneming toevoegen');
?>
</h1>

<div class="observation-form">
	<table class="table table-striped">
		<tr>
			<td width="50%"><?php 
echo $visitModel->getAttributeLabel('project');
?>
</td>
			<td><?php 
echo Html::encode($model->visit->project->name);
?>
</td>
		</tr>
		<tr>
Exemplo n.º 6
0
<?php

use app\models\Visits;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\HtmlPurifier;
use app\models\search\ObservationsSearch;
$visitModel = new Visits();
?>

<h1><?php 
echo Yii::t('app', 'Bezoek details van');
?>
 <?php 
echo Html::encode($visit->date);
?>
 - <?php 
echo Html::encode($visit->project->name);
?>
</h1>

<?php 
if (Yii::$app->user->can('updateVisit', ['visit' => $visit])) {
    ?>
	<a href="<?php 
    echo Url::toRoute('visits/form/' . $visit->id);
    ?>
" class="btn btn-info"><?php 
    echo Yii::t('app', 'Bewerken');
    ?>
</a>
Exemplo n.º 7
0
 public function getLastEntry()
 {
     return Visits::find()->select('date')->where(['project_id' => $this->id])->orderBy('date DESC')->limit(1)->one();
 }
Exemplo n.º 8
0
 public function getVisit()
 {
     return $this->hasOne(Visits::className(), ['id' => 'visit_id']);
 }
Exemplo n.º 9
0
 public function byPersonal()
 {
     return $this->andWhere(['in', 'visit_id', (new Query())->select('id')->from(Visits::tableName())->where(['observer_id' => Yii::$app->user->getId()])]);
 }
Exemplo n.º 10
0
<?php

use app\models\Visits;
use yii\helpers\Url;
use yii\bootstrap\Html;
use app\models\Observations;
use app\components\View;
use app\models\Projects;
use app\components\WGS84;
use yii\helpers\HtmlPurifier;
$visitModel = new Visits();
?>
<div class="observation-detail">

	<h1><?php 
echo Yii::t('app', 'Waarneming');
?>
 #<?php 
echo $observation->number;
?>
</h1>
	<?php 
if ($observation->validated_by_id) {
    ?>
		<p class="bg-success text-success">
			<?php 
    echo Yii::t('app', 'Gevalideerd door ');
    ?>
			<?php 
    echo Html::a($observation->validator->username, "#");
    ?>
Exemplo n.º 11
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>