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.

HostsBusiness.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Business;
  3. use Luticate\Utils\LuBusiness;
  4. use App\Http\DataAccess\HostsDataAccess;
  5. use App\Http\DBO\HostsDbo;
  6. class HostsBusiness extends LuBusiness {
  7. protected static function getDataAccess()
  8. {
  9. return new HostsDataAccess();
  10. }
  11. protected static function checkHost(HostsDbo $host, $host_id = null)
  12. {
  13. $existingHost = HostsDataAccess::getByName($host->getName());
  14. if (!is_null($existingHost) && $host_id != $existingHost->getId()) {
  15. self::badInput("Host name already exists");
  16. }
  17. if (is_null($host->getName()) || strlen($host->getName()) == 0) {
  18. self::badInput("Missing host name");
  19. }
  20. if (is_null($host->getUrl()) || strlen($host->getUrl()) == 0) {
  21. self::badInput("Missing host url");
  22. }
  23. if (is_null($host->getToken())) {
  24. $host->setToken("");
  25. }
  26. }
  27. public static function add(HostsDbo $host)
  28. {
  29. self::checkHost($host);
  30. return HostsDataAccess::addId($host);
  31. }
  32. public static function edit(HostsDbo $host, $host_id)
  33. {
  34. self::getById($host_id);
  35. self::checkHost($host, $host_id);
  36. $host->setId($host_id);
  37. return HostsDataAccess::editById($host_id, $host);
  38. }
  39. public static function del($host_id)
  40. {
  41. self::getById($host_id);
  42. return HostsDataAccess::deleteById($host_id);
  43. }
  44. }