private function newMeasurement() { $measurement = null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $measurement = new Measurement($_POST); } $_SESSION['measurement'] = $measurement; if (is_null($measurement) || $measurement->getErrorCount() != 0) { MeasurementView::showNew(); } else { $newMeasurement = MeasurementsDB::addMeasurement($measurement); if ($newMeasurement->getErrorCount() == 0) { $_SESSION['measurement'] = $newMeasurement; } SensorView::show(); header('Location: /' . $_SESSION['base'] . '/sensor/show/' . $_SESSION['sensor']->getSensorId()); } }
private function updateSensor() { $sensor = $_SESSION['sensor']; if (empty($sensor)) { HomeView::show(); header('Location: /' . $_SESSION['base']); } elseif ($_SERVER['REQUEST_METHOD'] == 'GET') { SensorView::showUpdate(); } else { $params = $sensor->getParameters(); $params['sensor_name'] = array_key_exists('sensor_name', $_POST) ? $_POST['sensor_name'] : ''; $params['description'] = array_key_exists('description', $_POST) ? $_POST['description'] : ''; $updatedSensor = new Sensor($params); $updatedSensor->setSensorId($sensor->getSensorId()); $returnedSensor = SensorsDB::updateSensor($updatedSensor); if ($returnedSensor->getErrorCount() == 0) { // Show the Sensor View which should display the updated params SensorView::show(); header('Location: /' . $_SESSION['base'] . '/sensor/show/' . $sensor->getSensorId()); } else { // Carry over the measurements, if any $updatedSensor->setMeasurements($sensor->getMeasurements()); $_SESSION['sensor'] = $updatedSensor; SensorView::showUpdate(); } } }