123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
-
- namespace App\Http\Business;
-
- use Luticate\Utils\LuBusiness;
- use App\Http\DataAccess\CamerasDataAccess;
- use App\Http\DBO\CamerasDbo;
-
- 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);
- }
- }
|