public function search($params, $personal = false) { $query = Species::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); return $dataProvider; }
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()]); }
public function actionIndex() { return $this->render('index', ['species' => Species::find()->all()]); }