You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CamerasBusiness.php 2.3KB

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