<?php
// DevicePaperTray.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use DI\DependencyException;use DI\NotFoundException;use Docuform\Api\Exception\ApiHttpInvalidParameter;use Docuform\Api\Exception\ApiHttpNotFoundException;use Docuform\Api\TableMapper;use Docuform\Database\DbPDO;use Docuform\Database\DbSQL;use Exception;#[\AllowDynamicProperties]class DevicePaperTray extends TableMapper{public $deviceId=0;private $mappings=[];public function getColumnMappings():array{if($this->mappings===[]){$this->mappings[]=['name'=>'DeviceId','type'=>DbSQL::cst_intornull,'alias'=>'deviceId'];$this->mappings=array_merge($this->mappings,self::getTrayMappings());}return $this->mappings;}public static function getTrayMappings(bool $noColumnNames=false):array{return[['name'=>$noColumnNames?'':'TrayIndex','type'=>DbSQL::cst_intornull,'alias'=>['paperTrays'=>'index']],['name'=>$noColumnNames?'':'Name','type'=>DbSQL::cst_text,'alias'=>['paperTrays'=>'name']],['name'=>$noColumnNames?'':'Description','type'=>DbSQL::cst_text,'alias'=>['paperTrays'=>'description']],['name'=>$noColumnNames?'':'FormatId','type'=>DbSQL::cst_intornull,'alias'=>['paperTrays'=>'formatId']],['name'=>$noColumnNames?'':'FormatName','type'=>DbSQL::cst_text,'alias'=>['paperTrays'=>'formatName']],['name'=>$noColumnNames?'':'MediaDimX','type'=>DbSQL::cst_intornull,'alias'=>['paperTrays'=>'mediaDimX']],['name'=>$noColumnNames?'':'MediaDimY','type'=>DbSQL::cst_intornull,'alias'=>['paperTrays'=>'mediaDimY']],['name'=>$noColumnNames?'':'MediaLevelPcnt','type'=>DbSQL::cst_intornull,'alias'=>['paperTrays'=>'mediaLevelPcnt']]];}public function getParameterConstraints(string $method):array{return[];}public function read(int $id):void{$serverApi=$this->getContainer()->get('RestApi');$request=$serverApi->getRequest();$this->checkGetParameters($request,$request->getQueryParams());$device=$serverApi->getDevice();if($device===null||$device->id!==$id){throw new ApiHttpNotFoundException($request,'Device not found');}$this->readData($device->id);}public function readData(int $id):void{$this->__set('DeviceId',$id);$database=$this->getContainer()->get('database');$params=array();$condition='';Device::addToWhereClause($this->getContainer(),$condition,$params,'AD',$id);$sql='SELECT '.$this->getColumnNamesAsString().' FROM'.' (SELECT IT.*,AF.Description as FormatName'.' FROM ((ACCINPUTTRAYS IT'.' INNER JOIN ACCDEVICES AD ON (AD.Id=IT.DeviceId))'.' LEFT OUTER JOIN ACCFORMATS AF ON (AF.WinFormatId=IT.FormatId))'.' WHERE '.$condition.') as IT2'.' ORDER BY DeviceId, TrayIndex ASC';$cursor=null;$row=$database->FetchFirst($cursor,$sql,$params);$this->paperTrays=[];while($row!==false){foreach($row as $name=>$value){$this->__set($name,$value);}$row=$database->FetchNext($cursor);}$database->FetchClose($cursor);}}