<?php
// Resource.php
// Copyright P.Kassel, M.Seliger, G.Trietsch, all Rights Reserved
namespace Docuform\Api\Server;use Docuform\Api\TableMapper;use Psr\Http\Message\ServerRequestInterface;use Docuform\Lib\ValidateParam;class Resource extends TableMapper{public array $resourceData;public function getColumnMappings():array{return[];}public function getParameterConstraints(string $method):array{if($method==='GET')return[['name'=>'group','maxLength'=>32,'type'=>ValidateParam::STRING_ASCII]];return[];}public function read(ServerRequestInterface $request):void{$serverApi=$this->getContainer()->get('RestApi');$type=$request->getAttribute('type');$this->checkGetParameters($request,$request->getQueryParams());$this->resourceData=[];$locale=!empty($request->getAttribute('locale'))?$request->getAttribute('locale'):'en';if($type==='system'){$group=!empty($request->getQueryParams()['group'])?$request->getQueryParams()['group']:'';$this->resourceData=$this->readSystemResources($locale,$group);}}private function readSystemResources(string $locale,string $group):array{$resources=[];$database=$this->getContainer()->get('database');$locale=substr(strtolower(explode('_',$locale)[0]),0,2);$sql="SELECT sGroup, sName, "."LANG_".strtoupper($locale)." as val,"." ULANG_".strtoupper($locale)." as uval"." FROM ACCSYSRSC WHERE sGroup<>'internal'".(!empty($group)?" AND sGroup=?":"")." ORDER BY sGroup, sName";$cursor=null;$row=$database->FetchFirst($cursor,$sql,!empty($group)?[$group]:[]);$groups=[];while($row!==false){$groups[$row['sGroup']][$row['sName']]=!empty($row['uval'])?$row['uval']:$row['val'];$row=$database->FetchNext($cursor);}$langResource[$locale]=$groups;$resources['resources']=$langResource;$database->FetchClose($cursor);return $resources;}}