123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
-
- namespace App\Http\Business;
-
- use Luticate\Utils\LuBusiness;
- use App\Http\DataAccess\HostsDataAccess;
- use App\Http\DBO\HostsDbo;
-
- class HostsBusiness extends LuBusiness {
- protected static function getDataAccess()
- {
- return new HostsDataAccess();
- }
-
- protected static function checkHost(HostsDbo $host, $host_id = null)
- {
- $existingHost = HostsDataAccess::getByName($host->getName());
- if (!is_null($existingHost) && $host_id != $existingHost->getId()) {
- self::badInput("Host name already exists");
- }
- if (is_null($host->getName()) || strlen($host->getName()) == 0) {
- self::badInput("Missing host name");
- }
- if (is_null($host->getUrl()) || strlen($host->getUrl()) == 0) {
- self::badInput("Missing host url");
- }
- if (is_null($host->getToken())) {
- $host->setToken("");
- }
- }
-
- public static function add(HostsDbo $host)
- {
- self::checkHost($host);
- return HostsDataAccess::addId($host);
- }
-
- public static function edit(HostsDbo $host, $host_id)
- {
- self::getById($host_id);
- self::checkHost($host, $host_id);
- $host->setId($host_id);
- return HostsDataAccess::editById($host_id, $host);
- }
- }
|