Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SensorsBusiness.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Business;
  3. use Luticate\Utils\LuBusiness;
  4. use App\Http\DataAccess\SensorsDataAccess;
  5. use App\Http\DBO\SensorsDbo;
  6. class SensorsBusiness extends LuBusiness {
  7. protected static function getDataAccess()
  8. {
  9. return new SensorsDataAccess();
  10. }
  11. protected static function checkSensor(SensorsDbo $sensor, $sensor_id = null)
  12. {
  13. $existingSensor = SensorsDataAccess::getByName($sensor->getName());
  14. if (!is_null($existingSensor) && $sensor_id != $existingSensor->getId()) {
  15. self::badInput("Sensor name already exists");
  16. }
  17. if (is_null($sensor->getName()) || strlen($sensor->getName()) == 0) {
  18. self::badInput("Missing sensor name");
  19. }
  20. HostsBusiness::getById($sensor->getHostId());
  21. SensorTypesBusiness::getById($sensor->getSensorTypeId());
  22. if (is_null($sensor->getDescription())) {
  23. $sensor->setDescription("");
  24. }
  25. if (is_null($sensor->getData()) || strlen($sensor->getData()) == 0) {
  26. $sensor->setData("{}");
  27. }
  28. $json = json_decode($sensor->getData());
  29. if (is_null($json)) {
  30. self::badInput("Sensor data could not be converted to json");
  31. }
  32. }
  33. public static function add(SensorsDbo $sensor)
  34. {
  35. self::checkSensor($sensor);
  36. return SensorsDataAccess::addId($sensor);
  37. }
  38. public static function edit(SensorsDbo $sensor, $sensor_id)
  39. {
  40. self::getById($sensor_id);
  41. self::checkSensor($sensor, $sensor_id);
  42. $sensor->setId($sensor_id);
  43. return SensorsDataAccess::editById($sensor_id, $sensor);
  44. }
  45. }