/** * Converts all the information that has been stored to this file object * into an observation instance. * * @param $warnings {Array} By reference. Optional. * A buffer into which generated warnings will be logged. If not * specified, warnings are logged to STDERR. * * @return {Observation} */ public function toObservation(&$warnings = null) { // Save last reading $this->_saveCurrentReading(); // This will be an ObservatoryDetail instance $observatory = $this->parser->_getObservatory($this->observatoryCode, $warnings); // While getting readings, begin/end time information (needed for subsequent // lookups) is calculated simultaneously. $beginEndStamps = array(); $readings = $this->_getReadings($beginEndStamps, $warnings); $begin = $beginEndStamps['begin']; $end = $beginEndStamps['end']; $pier = $this->parser->_getPier($observatory->code, $this->pierName, $this->pierCorrection, $warnings); $mark = $this->parser->_getMark($observatory->code, $pier->name, $pier->correction, $this->markName, $this->markAzimuth, $warnings); $electronics = $this->parser->_getInstrument($observatory->code, $this->electronicsSerial, 'electronics', $warnings); $theodolite = $this->parser->_getInstrument($observatory->code, $this->theodoliteSerial, 'theodolite', $warnings); $observer = null; $reviewer = null; if ($this->observer !== null) { $observer = $this->parser->_getUser($this->observer, $observatory->code); } if ($this->reviewer !== null) { $reviewer = $this->parser->_getUser($this->reviewer, $observatory->code); } $observation = array('id' => null, 'observatory_id' => $observatory !== null ? $observatory->id : null, 'begin' => $beginEndStamps['begin'], 'end' => $beginEndStamps['end'], 'reviewer_user_id' => $reviewer !== null ? $reviewer['id'] : null, 'observer_user_id' => $observer !== null ? $observer['id'] : null, 'mark_id' => $mark !== null ? $mark->id : null, 'electronics_id' => $electronics !== null ? $electronics->id : null, 'theodolite_id' => $theodolite !== null ? $theodolite->id : null, 'pier_temperature' => $this->metaInfo['pier_temperature'], 'elect_temperature' => $this->metaInfo['elect_temperature'], 'flux_temperature' => $this->metaInfo['flux_temperature'], 'proton_temperature' => $this->metaInfo['proton_temperature'], 'outside_temperature' => $this->metaInfo['outside_temperature'], 'reviewed' => 'N', 'annotation' => $this->metaInfo['annotation'], 'readings' => $readings); return ObservationDetail::fromArray($observation); }
// find matching observation $observation = $OBSERVATION_FACTORY->getObservation($id); if ($observation === null) { header('HTTP/1.1 400 Bad Request'); echo 'no matching observation found'; exit; } // delete $OBSERVATION_FACTORY->deleteObservation($observation); // notify it worked echo 'deleted'; } else { // read json from client $json = file_get_contents('php://input'); $json = json_decode($json, true); $observation = ObservationDetail::fromArray($json); if ($method === 'POST') { // create if ($observation->id !== null) { header('HTTP/1.1 400 Bad Request'); echo 'cannot create an observation that already has an id'; exit; } if ($observation->observatory_id === null) { header('HTTP/1.1 400 Bad Request'); echo 'cannot create an observation without an observatory'; exit; } // check user permissions if (!$isAdmin && $observation->observatory_id !== $defaultObservatoryId) { header('HTTP/1.1 403 Forbidden');