From b068c385e7f43ed7523cdb87e9752c660796da4a Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 7 Nov 2022 12:16:10 +0100 Subject: [PATCH] add new method __getAttributesData() --- restapi/index.php | 49 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/restapi/index.php b/restapi/index.php index 438761b7d..cb7ad9bbf 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -48,6 +48,22 @@ class RestapiController { /* {{{ */ $this->container = $container; } + protected function __getAttributesData($obj) { /* {{{ */ + $attributes = $obj->getAttributes(); + $attrvalues = array(); + if($attributes) { + foreach($attributes as $attrdefid=>$attribute) { + $attrdef = $attribute->getAttributeDefinition(); + $attrvalues[] = array( + 'id'=>$attrdef->getId(), + 'name'=>$attrdef->getName(), + 'value'=>$attribute->getValue() + ); + } + } + return $attrvalues; + } + protected function __getDocumentData($document) { /* {{{ */ $data = array( 'type'=>'document', @@ -87,19 +103,13 @@ class RestapiController { /* {{{ */ } $data['categories'] = $c; } - $attributes = $document->getAttributes(); + $attributes = $this->__getAttributesData($document); if($attributes) { - $attrvalues = array(); - foreach($attributes as $attrdefid=>$attribute) - $attrvalues[] = array('id'=>(int)$attrdefid, 'value'=>$attribute->getValue()); - $data['attributes'] = $attrvalues; + $data['attributes'] = $attributes; } - $attributes = $lc->getAttributes(); + $attributes = $this->__getAttributesData($lc); if($attributes) { - $attrvalues = array(); - foreach($attributes as $attrdefid=>$attribute) - $attrvalues[] = array('id'=>(int)$attrdefid, 'value'=>$attribute->getValue()); - $data['version-attributes'] = $attrvalues; + $data['version-attributes'] = $attributes; } return $data; } /* }}} */ @@ -146,12 +156,9 @@ class RestapiController { /* {{{ */ 'comment'=>$folder->getComment(), 'date'=>date('Y-m-d H:i:s', $folder->getDate()), ); - $attributes = $folder->getAttributes(); + $attributes = $this->__getAttributesData($folder); if($attributes) { - $attrvalues = array(); - foreach($attributes as $attrdefid=>$attribute) - $attrvalues[] = array('id'=>(int)$attrdefid, 'value'=>$attribute->getValue()); - $data['attributes'] = $attrvalues; + $data['attributes'] = $attributes; } return $data; } /* }}} */ @@ -421,16 +428,8 @@ class RestapiController { /* {{{ */ $folder = $dms->getFolder($args['id']); if($folder) { if ($folder->getAccessMode($userobj) >= M_READ) { - $recs = array(); - $attributes = $folder->getAttributes(); - foreach($attributes as $attribute) { - $recs[] = array( - 'id'=>(int)$attribute->getId(), - 'value'=>$attribute->getValue(), - 'name'=>$attribute->getAttributeDefinition()->getName(), - ); - } - return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$recs), 200); + $attributes = $this->__getAttributesData($folder); + return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$attributes), 200); } else { return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403); }