<?php
// Vendor.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\TableMapper;use Docuform\Database\DbSQL;use DI\Container;class Vendor extends TableMapper{public function getColumnMappings():array{return[['name'=>'VendorId','type'=>DbSQL::cst_intornull,'alias'=>'id'],['name'=>'SnmpId','type'=>DbSQL::cst_intornull,'alias'=>'smiPEN'],['name'=>'Vendor','type'=>DbSQL::cst_text,'alias'=>'name'],];}public function getParameterConstraints(string $method):array{if($method==='GET')return[['name'=>'id','min'=>1,'max'=>PHP_INT_MAX],['name'=>'smiPEN','min'=>1,'max'=>PHP_INT_MAX],['name'=>'name','maxLength'=>128]];return[];}public static function readAll(Container $container,?int $id=null):array{$serverApi=$container->get('RestApi');$request=$serverApi->getRequest();(new self($container))->checkGetParameters($request,$request->getQueryParams());$database=$container->get('database');$condition='SV.VendorId>0';$params=[];if(!empty($request->getQueryParams()['vendorId'])){DbSQL::addCondition($condition,'SV.VendorId=?');$params[]=(int)$request->getQueryParams()['vendorId'];}if(!empty($request->getQueryParams()['smiPEN'])){DbSQL::addCondition($condition,'SV.SnmpId=?');$params[]=(int)$request->getQueryParams()['smiPEN'];}if(!empty($request->getQueryParams()['name'])){DbSQL::addCondition($condition,'DV.Vendor LIKE ?');$params[]='%'.$request->getQueryParams()['name'].'%';}$sql='SELECT DISTINCT '.(new self($container))->getColumnNamesAsString().' FROM (ACCSNMPVENDORS SV'.' INNER JOIN ACCDEVICEVENDORS DV on (SV.VendorId=DV.Id))'.' WHERE '.$condition;return $database->FetchObjects(true,$sql,$params,__CLASS__,[$container]);}}