<?php
// Model.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Client;use Docuform\Api\TableMapper;use Docuform\Database\DbSQL;use Docuform\Api\Exception\ApiHttpServerErrorException;use DI\Container;use Docuform\Lib\XmlReturn;class Model extends TableMapper{public function getColumnMappings():array{return[['name'=>'Model','type'=>DbSQL::cst_text,'alias'=>'name'],['name'=>'SerialNoOid','type'=>DbSQL::cst_text,'alias'=>'serialNumberOid'],['name'=>'VendorId','type'=>DbSQL::cst_intornull,'alias'=>'vendorId']];}public function getParameterConstraints(string $method):array{if($method==='GET')return[['name'=>'modelName','maxLength'=>255,'required'=>true],];return[];}public static function readAll(Container $container):array|Model{$request=$container->get('RestApi')->getRequest();$xmlrpc=$container->get('XmlrpcClient');(new self($container))->checkGetParameters($request,$request->getQueryParams());$xmlparams=['token'=>$container->get('RestApi')->getToken()];$xmlparams['modelname']=$request->getQueryParams()['modelName'];$xmlresult=$xmlrpc->call('fsm.client.devicemodels.read',$xmlparams);if(!isset($xmlresult['code'])||$xmlresult['code']!==XmlReturn::XMLRET_OK){throw new ApiHttpServerErrorException($request,null,'Client result: '.$xmlresult['result']);}$result=[];if(($xmlresult['apiresult']===200)&&!empty($xmlresult['values'])){foreach($xmlresult['values']as $value){$model=new self($container);$model->__set('name',$value['modelname']);$model->__set('serialNumberOid',$value['serialnooid']);$model->__set('vendorId',$value['vendorid']);$result[]=$model;}$result=$result[0];}return $result;}public function __set(string $name,mixed $value){if($name==='serialNumberOid'||$name==='vendorId'){$this->$name=empty($value)?null:$value;}else parent::__set($name,$value);}}