Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CamerasBusiness.php 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Http\Business;
  3. use App\Http\DBO\CameraTypesDbo;
  4. use App\Http\DBO\HostsDbo;
  5. use Luticate\Auth\Business\LuticatePermissionsBusiness;
  6. use Luticate\Utils\LuBusiness;
  7. use App\Http\DataAccess\CamerasDataAccess;
  8. use App\Http\DBO\CamerasDbo;
  9. use Luticate\Utils\LuRequest;
  10. class CamerasBusiness extends LuBusiness {
  11. protected static function getDataAccess()
  12. {
  13. return new CamerasDataAccess();
  14. }
  15. protected static function checkCamera(CamerasDbo $camera, $camera_id = null)
  16. {
  17. $existingCamera = CamerasDataAccess::getByName($camera->getName());
  18. if (!is_null($existingCamera) && $camera_id != $existingCamera->getId()) {
  19. self::badInput("Camera name already exists");
  20. }
  21. if (is_null($camera->getName()) || strlen($camera->getName()) == 0) {
  22. self::badInput("Missing camera name");
  23. }
  24. HostsBusiness::getById($camera->getHostId());
  25. CameraTypesBusiness::getById($camera->getCameraTypeId());
  26. if (is_null($camera->getDescription())) {
  27. $camera->setDescription("");
  28. }
  29. if (is_null($camera->getData()) || strlen($camera->getData()) == 0) {
  30. $camera->setData("{}");
  31. }
  32. $json = json_decode($camera->getData());
  33. if (is_null($json)) {
  34. self::badInput("Camera data could not be converted to json");
  35. }
  36. }
  37. public static function getAllLight($_user, $page = 0, $perPage = PHP_INT_MAX, $query = "")
  38. {
  39. $values = self::getAll($page, $perPage, $query);
  40. if (LuticatePermissionsBusiness::getEffectivePermission($_user->getId(), "CAMOTION_CAMERA_EDIT")->getValue()) {
  41. return $values;
  42. }
  43. return $values->map(function($camera)
  44. {
  45. $camera->setData(null);
  46. return $camera;
  47. });
  48. }
  49. public static function getLight($_user, $camera_id)
  50. {
  51. $camera = self::getById($camera_id);
  52. if (LuticatePermissionsBusiness::getEffectivePermission($_user->getId(), "CAMOTION_CAMERA_EDIT")->getValue()) {
  53. return $camera;
  54. }
  55. $camera->setData(null);
  56. return $camera;
  57. }
  58. public static function add(CamerasDbo $camera)
  59. {
  60. self::checkCamera($camera);
  61. return CamerasDataAccess::addId($camera);
  62. }
  63. public static function edit(CamerasDbo $camera, $camera_id)
  64. {
  65. self::getById($camera_id);
  66. self::checkCamera($camera, $camera_id);
  67. $camera->setId($camera_id);
  68. return CamerasDataAccess::editById($camera_id, $camera);
  69. }
  70. public static function getImage($camera_id)
  71. {
  72. /**
  73. * @var $camera CamerasDbo
  74. * @var $host HostsDbo
  75. * @var $type CameraTypesDbo
  76. */
  77. $camera = self::getById($camera_id);
  78. $host = HostsBusiness::getById($camera->getHostId());
  79. $type = CameraTypesBusiness::getById($camera->getCameraTypeId());
  80. return LuRequest::proxy('POST', $host->getUrl() . "/cameras/image", [],
  81. ["camera" => $camera->__toString(), "type" => $type->__toString()], ["X-Token" => $host->getToken()]);
  82. }
  83. }