<?php
// Dealer.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use DI\DependencyException;use DI\NotFoundException;use Docuform\Api\ApiUser;use Docuform\Database\DbException;use Docuform\Database\DbSQL;use Docuform\Lib\ApiUuid;use DI\Container;use Docuform\Lib\ValidateParam;use Docuform\Api\Exception\ApiHttpBadRequestException;class Dealer extends ApiUser{public $dealerId=0;public $uuid='';public $name='';public $cRights=0;public $restApiClientUuid='';public function getColumnMappings():array{$mappings=parent::getColumnMappings();self::clearMapping($mappings,['DeviceManagerId','sDeviceManagerUUID','ProductVersion','ReferenceNumber','Follow2PrintCtrl','DeployMcsCollectionUUID','DeployMcsPassword','DeployOAuthHost']);return $mappings;}private static function clearMapping(& $mappings,array $names):void{foreach($mappings as $key=>$row){if(!empty($row['name'])&&in_array($row['name'],$names,true)){unset($mappings[$key]);}}}public function getParameterConstraints(string $method):array{if($method==='GET'){return[['name'=>'name','maxLength'=>64,'allowEmpty'=>true],['name'=>'dealerUuid','type'=>ValidateParam::UUID,'allowEmpty'=>true]];}return[];}public function read(int $id):void{$object=self::readAll($this->getContainer(),$id);if(!empty($object)){foreach($object as $key=>$value){$this->__set($key,$value);}}}public static function readAll(Container $container,?int $id=null):Dealer|array{$request=$container->get('RestApi')->getRequest();$database=$container->get('database');if($id!==null&&$id<=0){throw new ApiHttpBadRequestException($request);}(new self($container))->checkGetParameters($request,$request->getQueryParams());$condition='DeviceManager<>?';$params=[0];if(!empty($request->getQueryParams()['name'])){DbSQL::addCondition($condition,'Name=?');$params[]=$request->getQueryParams()['name'];}if(!empty($request->getQueryParams()['dealerUuid'])){DbSQL::addCondition($condition,'sUUID=?');$params[]=ApiUuid::toHex($request->getQueryParams()['dealerUuid']);}ApiUser::addToWhereClause($container,$condition,$params,'AU',$id!==null?(int)$id:0,true);$sql='SELECT '.(new self($container))->getColumnNamesAsString().' FROM'.'(SELECT AU.*'.' FROM ACCUSERS AU WHERE '.$condition.') as AU3';return $database->FetchObjects(($id===null),$sql,$params,__CLASS__,[$container]);}}