1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
-
- namespace App\Http\Business;
-
- use App\Http\DBO\CameraTypesDbo;
- use App\Http\DBO\HostsDbo;
- use Luticate\Utils\LuBusiness;
- use App\Http\DataAccess\CamerasDataAccess;
- use App\Http\DBO\CamerasDbo;
- use Luticate\Utils\LuRequest;
-
- class CamerasBusiness extends LuBusiness {
- protected static function getDataAccess()
- {
- return new CamerasDataAccess();
- }
-
- protected static function checkCamera(CamerasDbo $camera, $camera_id = null)
- {
- $existingCamera = CamerasDataAccess::getByName($camera->getName());
- if (!is_null($existingCamera) && $camera_id != $existingCamera->getId()) {
- self::badInput("Camera name already exists");
- }
- if (is_null($camera->getName()) || strlen($camera->getName()) == 0) {
- self::badInput("Missing camera name");
- }
- HostsBusiness::getById($camera->getHostId());
- CameraTypesBusiness::getById($camera->getCameraTypeId());
- if (is_null($camera->getDescription())) {
- $camera->setDescription("");
- }
- if (is_null($camera->getData()) || strlen($camera->getData()) == 0) {
- $camera->setData("{}");
- }
- $json = json_decode($camera->getData());
- if (is_null($json)) {
- self::badInput("Camera data could not be converted to json");
- }
- }
-
- public static function add(CamerasDbo $camera)
- {
- self::checkCamera($camera);
- return CamerasDataAccess::addId($camera);
- }
-
- public static function edit(CamerasDbo $camera, $camera_id)
- {
- self::getById($camera_id);
- self::checkCamera($camera, $camera_id);
- $camera->setId($camera_id);
- return CamerasDataAccess::editById($camera_id, $camera);
- }
-
- public static function getImage($camera_id)
- {
- /**
- * @var $camera CamerasDbo
- * @var $host HostsDbo
- * @var $type CameraTypesDbo
- */
- $camera = self::getById($camera_id);
- $host = HostsBusiness::getById($camera->getHostId());
- $type = CameraTypesBusiness::getById($camera->getCameraTypeId());
- return LuRequest::proxy('POST', $host->getUrl() . "/cameras/image", [],
- ["camera" => $camera->__toString(), "type" => $type->__toString()], ["X-Token" => $host->getToken()]);
- }
- }
|