getName()); if (!is_null($existingSensor) && $sensor_id != $existingSensor->getId()) { self::badInput("Sensor name already exists"); } if (is_null($sensor->getName()) || strlen($sensor->getName()) == 0) { self::badInput("Missing sensor name"); } HostsBusiness::getById($sensor->getHostId()); SensorTypesBusiness::getById($sensor->getSensorTypeId()); if (is_null($sensor->getDescription())) { $sensor->setDescription(""); } if (is_null($sensor->getData()) || strlen($sensor->getData()) == 0) { $sensor->setData("{}"); } $json = json_decode($sensor->getData()); if (is_null($json)) { self::badInput("Sensor data could not be converted to json"); } } public static function add(SensorsDbo $sensor) { self::checkSensor($sensor); return SensorsDataAccess::addId($sensor); } public static function edit(SensorsDbo $sensor, $sensor_id) { self::getById($sensor_id); self::checkSensor($sensor, $sensor_id); $sensor->setId($sensor_id); return SensorsDataAccess::editById($sensor_id, $sensor); } public static function getValue($sensor_id) { self::getById($sensor_id); return rand(0, 42) * ($sensor_id % 2 == 0 ? 1 : -1); } }