<?php
// DeviceFeatureList.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use DI\Container;use DI\DependencyException;use DI\NotFoundException;use Docuform\Api\TableMapper;use Docuform\Api\Exception\ApiHttpBadRequestException;use Docuform\Database\DbException;use Docuform\Database\DbPDO;use Docuform\Database\DbSQL;use Exception;#[\AllowDynamicProperties]class DeviceFeatureList extends TableMapper{public $deviceId=0;private $mappings=[];public function getColumnMappings():array{if($this->mappings===[]){$this->mappings[]=['name'=>'DeviceId','type'=>DbSQL::cst_intornull,'alias'=>'deviceId'];$propCount=0;$features=self::getFeatureMappings($this->getContainer(),$propCount);$this->mappings=array_merge($this->mappings,$features);$this->mappings[]=['name'=>'follow2print','type'=>DbSQL::cst_text,'alias'=>['properties'=>$propCount++]];$this->mappings[]=['name'=>'securePrint','type'=>DbSQL::cst_text,'alias'=>['properties'=>$propCount]];}return $this->mappings;}public static function getFeatureMappings(Container $container,&$propCount,bool $outputDimensions=true,bool $technicalSpecs=true):array{$result=[];if($container->has('device_feature_list_mappings')){$result=$container->get('device_feature_list_mappings');}else{$database=$container->get('database');$cursor=null;$sql='SELECT ValIndex,Type,JsonName FROM ACCMIBPROPERTYDEF WHERE JsonName IS NOT NULL ORDER BY JsonName';$row=$database->FetchFirst($cursor,$sql);while($row!==false){$alias=$row['JsonName'];$m=['column'=>'C'.$row['ValIndex'],'name'=>$alias,'type'=>DbSQL::cst_auto];if($row['Type']==='boolean'){$m['alias']=['properties'=>$propCount++];}elseif($row['Type']==='hidden'){if(in_array($alias,['gpiV4Driver','gpcCanFold','truetypeAsBitmap'],false)){$m['alias']=['properties'=>$propCount++];}elseif(in_array($alias,['maxMediaFeedDimension','maxMediaXFeedDimension','northMargin'],false)){if($outputDimensions){$m['alias']=['outputDimensions'=>$alias];}}elseif($technicalSpecs){$m['alias']=['technicalSpecs'=>$alias];}}else if($technicalSpecs){$m['alias']=$alias;}if(!empty($m['alias'])){$result[]=$m;}$row=$database->FetchNext($cursor);}$database->FetchClose($cursor);if($technicalSpecs){$result[]=['name'=>'InputTrayFormats','type'=>DbSQL::cst_auto,'alias'=>['technicalSpecs'=>'paperTrayFormatIds']];}}return $result;}public static function getOutDimMappings(Container $container,bool $noColumnNames=false):array{$result=[];$propCount=0;$features=self::getFeatureMappings($container,$propCount);foreach($features as $m){if(is_array($m['alias'])&&array_keys($m['alias'])[0]==='outputDimensions'){if($noColumnNames){$m['column']='';$m['name']='';}$result[]=$m;}}return $result;}public static function getTecSpecMappings(Container $container,bool $noColumnNames=false):array{$result=[];$propCount=0;$features=self::getFeatureMappings($container,$propCount);foreach($features as $m){if(!is_array($m['alias'])||array_keys($m['alias'])[0]==='technicalSpecs'){if($noColumnNames){$m['column']='';$m['name']='';}$result[]=$m;}}return $result;}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 ApiHttpBadRequestException($request);}if($device->isLicensed===false){throw new ApiHttpBadRequestException($request,'Device not licensed');}$this->readData($device->id);}public function readData(int $id):void{$this->__set('DeviceId',$id);$database=$this->getContainer()->get('database');$cursor=null;$sql='SELECT * FROM ACCMIBPROPERTYVALUES WHERE DeviceId=?';$row=$database->FetchFirst($cursor,$sql,[$id]);if($row!==false){foreach($this->mappings as $colDef){if(isset($colDef['column'],$row[$colDef['column']])){if(is_array($colDef['alias'])){if(is_int(current($colDef['alias']))){if(empty($row[$colDef['column']])){continue;}$name=$colDef['name'];$value=$colDef['name'];}else{$name=current($colDef['alias']);$value=$row[$colDef['column']];}}else{$name=$colDef['name'];$value=$row[$colDef['column']];}$this->__set($name,$value);}}}$database->FetchClose($cursor);$cursor=null;$sql='SELECT follow2print,securePrint FROM ACCDEVICES WHERE Id=?';$row=$database->FetchFirst($cursor,$sql,[$id]);foreach($row as $name=>$value){if(isset($value)&&$value==='Y'){$this->__set($name,$name);}}$database->FetchClose($cursor);$cursor=null;$sql='SELECT DISTINCT FormatId FROM ACCINPUTTRAYS WHERE DeviceId=? AND FormatId IS NOT NULL ORDER BY FormatId';$row=$database->FetchFirst($cursor,$sql,[$id]);$formatIds='';while($row!==false){foreach($row as $name=>$value){if(!empty($value)){$formatIds.=($formatIds!==''?',':'').$value;}}$row=$database->FetchNext($cursor);}$this->__set('InputTrayFormats',$formatIds);$database->FetchClose($cursor);}}