public function search($params, $personal = false) { $query = Species::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); return $dataProvider; }
public function actionDelete($id) { $model = Species::findOne($id); if ($model && !$model->observations) { $model->deleted = true; $model->save(false); } return $this->redirect(Url::toRoute('species/index')); }
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()]); }
use yii\bootstrap\ActiveForm; use app\models\Species; ?> <h1><?php echo Yii::t('app', 'Soort'); ?> <?php echo $model->isNewRecord ? Yii::t('app', 'toevoegen') : Yii::t('app', 'bewerken'); ?> </h1> <div class="species-form"> <?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?> <?php echo $form->field($model, 'taxon')->dropDownList(Species::getTaxonomies()); ?> <?php echo $form->field($model, 'genus'); ?> <?php echo $form->field($model, 'speceus'); ?> <?php echo $form->field($model, 'dutch'); ?> <?php echo $form->field($model, 'url'); ?> <div class="form-group text-right"> <input type="submit" class="btn btn-success" value="<?php
<?php } ?> </table> <?php $form = ActiveForm::begin(['enableClientValidation' => false, 'options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'box_id')->dropDownList(Arrayhelper::map($boxes, 'id', 'code')); ?> <?php echo $form->field($model, 'observation_type')->dropDownList(Observations::getObservationTypes(), ['data-observation-type' => 1]); ?> <div class="observation-form-details"> <?php echo $form->field($model, 'taxon_id')->dropDownList(Species::getTaxonomies(true), ['data-taxon-identifier' => 1]); ?> <?php echo $form->field($model, 'species_id')->dropDownList(ArrayHelper::map($species, 'id', 'dutch'), ['data-species-identifier' => 1]); ?> <div class="sight-container hidden-js"> <?php echo $form->field($model, 'age')->dropDownList(Observations::getAgeOptions()); ?> <?php echo $form->field($model, 'sight_quantity'); ?> </div> <div class="manure-container hidden-js"> <?php echo $form->field($model, 'manure_collected')->checkbox(['data-manure-collected' => 1]);
public function store() { $csvPath = Input::file('file')->getRealPath(); $collectionName = Input::file('file')->getClientOriginalName(); $collectionName = substr($collectionName, 0, strlen($collectionName) - 4); $csv = new parseCSV(); $csv->auto($csvPath); $data = $csv->data; // If collection exists, drop it if (Schema::hasCollection($collectionName)) { Schema::drop($collectionName); } switch ($collectionName) { case 'Species': Schema::create('Species', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newSpecies = new Species(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newSpecies[$key] = $row[$key]; } $newSpecies->save(); } break; case 'Interactions': Schema::create('Interactions', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newInteraction = new Interaction(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newInteraction[$key] = $row[$key]; } $newInteraction->save(); } break; case 'TaxaGroups': Schema::create('TaxaGroups', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newTaxaGroup = new TaxaGroup(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newTaxaGroup[$key] = $row[$key]; } $newTaxaGroup->save(); } break; case 'LitSources': Schema::create('LitSources', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newLitSource = new LitSource(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newLitSource[$key] = $row[$key]; } $newLitSource->save(); } break; case 'Images': Schema::create('Images', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newImage = new Image(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newImage[$key] = $row[$key]; } $newImage->save(); } break; case 'Synonyms': Schema::create('Synonyms', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newSynonym = new Synonym(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newSynonym[$key] = $row[$key]; } $newSynonym->save(); } break; case 'BioNotes': Schema::create('BioNotes', function ($collection) { // $collection->unique('spID'); }); foreach ($data as $row) { $keys = array_keys($row); // $newBioNote = new BioNote(); // foreach ($keys as $key) { if (is_numeric($row[$key])) { $row[$key] = (int) $row[$key]; } $newBioNote[$key] = $row[$key]; } $newBioNote->save(); } break; default: return "Nothing is done"; } //$csv->data[4]['spID']; return 'success!'; }
<?php } } ?> <br><br> <div class="table-responsive"> <table class="table"> <tr> <td><?php echo $specie->getAttributeLabel('taxon'); ?> </td> <td><?php echo Species::getTaxonomy($specie->taxon); ?> </td> </tr> <tr> <td><?php echo $specie->getAttributeLabel('genus'); ?> </td> <td><?php echo Html::encode($specie->genus); ?> </td> </tr> <tr> <td><?php
public function getSpeciesByID(Request $request) { $spID = $request->input('spID'); $speciesObject = Species::where('spID', '=', $spID)->where('uploadToWeb', '=', 1)->get(); $speciesObject[0]->images->toArray(); $speciesObject[0]->bioNotes->toArray(); $speciesObject[0]->synonyms->toArray(); $speciesObject[0]->litSources->toArray(); $speciesObject[0]->interactions->toArray(); $hierachy = []; $parentTaxaGroupID = $speciesObject[0]->taxaGroupID; while (TaxaGroup::find($parentTaxaGroupID)->tier > 1) { $taxaGroupName = TaxaGroup::find($parentTaxaGroupID)->TaxaGroupName; array_unshift($hierachy, ['taxaGroupID' => $parentTaxaGroupID, 'TaxaGroupName' => $taxaGroupName]); $parentTaxaGroupID = TaxaGroup::find($parentTaxaGroupID)->parentTaxaGroupID; } return response()->json(['speciesObject' => $speciesObject, 'hierachy' => $hierachy]); }
public function getParasite() { return $this->hasOne(Species::className(), ['id' => 'catch_parasite_id']); }