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"; }
public function actionIndex() { $observation = new \NDFF\Observation(); $observation->setLifestage('http://ndff-ecogrid.nl/codes/domainvalues/observation/lifestages/unknown'); $observation->setLocation(0, '', 'http://ndff-ecogrid.nl/codes/locationtypes/point'); $observation->setOriginalabundance(0); $observation->setPeriodstart(date('o-m-d\\TH:i:s')); $observation->setScaleidentity('http://ndff-ecogrid.nl/codes/scales/exact_count'); $observation->setSex('http://ndff-ecogrid.nl/codes/domainvalues/observation/sexes/undefined'); $observation->setSubjecttypeidentity('http://ndff-ecogrid.nl/codes/subjecttypes/live/individual'); d(json_decode($bats)); die; }