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.

CamerasBusiness.php 1.6KB

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