mirror of
https://git.code.sf.net/p/seeddms/code
synced 2026-02-21 18:18:34 +00:00
144 lines
4.8 KiB
PHP
144 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* Some function for the rest api
|
|
*
|
|
* @category DMS
|
|
* @package SeedDMS
|
|
* @license GPL 2
|
|
* @version @version@
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
* @copyright Copyright (C) 2026 Uwe Steinmann
|
|
* @version Release: @package_version@
|
|
*/
|
|
|
|
|
|
trait SeedDMS_RestapiTrait { /* {{{ */
|
|
protected function __getAttributesData($obj) { /* {{{ */
|
|
$attributes = $obj->getAttributes();
|
|
$attrvalues = array();
|
|
if($attributes) {
|
|
foreach($attributes as $attrdefid=>$attribute) {
|
|
$attrdef = $attribute->getAttributeDefinition();
|
|
$attrvalues[] = array(
|
|
'id'=>(int) $attrdef->getId(),
|
|
'name'=>$attrdef->getName(),
|
|
'value'=>$attribute->getValue()
|
|
);
|
|
}
|
|
}
|
|
return $attrvalues;
|
|
} /* }}} */
|
|
|
|
protected function __getDocumentData($document) { /* {{{ */
|
|
$cats = $document->getCategories();
|
|
$tmp = [];
|
|
foreach($cats as $cat) {
|
|
$tmp[] = $this->__getCategoryData($cat);
|
|
}
|
|
$data = array(
|
|
'type'=>'document',
|
|
'id'=>(int)$document->getId(),
|
|
'date'=>date('Y-m-d H:i:s', $document->getDate()),
|
|
'name'=>$document->getName(),
|
|
'comment'=>$document->getComment(),
|
|
'keywords'=>$document->getKeywords(),
|
|
'categories'=>$tmp,
|
|
'owner'=>(int)$document->getOwner()->getId()
|
|
);
|
|
return $data;
|
|
} /* }}} */
|
|
|
|
protected function __getLatestVersionData($lc) { /* {{{ */
|
|
$document = $lc->getDocument();
|
|
$data = array(
|
|
'type'=>'document',
|
|
'id'=>(int)$document->getId(),
|
|
'date'=>date('Y-m-d H:i:s', $document->getDate()),
|
|
'name'=>$document->getName(),
|
|
'comment'=>$document->getComment(),
|
|
'keywords'=>$document->getKeywords(),
|
|
'ownerid'=>(int) $document->getOwner()->getID(),
|
|
'islocked'=>$document->isLocked(),
|
|
'sequence'=>$document->getSequence(),
|
|
'expires'=>$document->getExpires() ? date('Y-m-d H:i:s', $document->getExpires()) : "",
|
|
'mimetype'=>$lc->getMimeType(),
|
|
'filetype'=>$lc->getFileType(),
|
|
'origfilename'=>$lc->getOriginalFileName(),
|
|
'version'=>$lc->getVersion(),
|
|
'version_comment'=>$lc->getComment(),
|
|
'version_date'=>date('Y-m-d H:i:s', $lc->getDate()),
|
|
'size'=>(int) $lc->getFileSize(),
|
|
);
|
|
$cats = $document->getCategories();
|
|
if($cats) {
|
|
$c = array();
|
|
foreach($cats as $cat) {
|
|
$c[] = array('id'=>(int)$cat->getID(), 'name'=>$cat->getName());
|
|
}
|
|
$data['categories'] = $c;
|
|
}
|
|
$attributes = $this->__getAttributesData($document);
|
|
if($attributes) {
|
|
$data['attributes'] = $attributes;
|
|
}
|
|
$attributes = $this->__getAttributesData($lc);
|
|
if($attributes) {
|
|
$data['version_attributes'] = $attributes;
|
|
}
|
|
return $data;
|
|
} /* }}} */
|
|
|
|
protected function __getDocumentVersionData($lc) { /* {{{ */
|
|
$data = array(
|
|
'id'=>(int) $lc->getId(),
|
|
'version'=>$lc->getVersion(),
|
|
'date'=>date('Y-m-d H:i:s', $lc->getDate()),
|
|
'mimetype'=>$lc->getMimeType(),
|
|
'filetype'=>$lc->getFileType(),
|
|
'origfilename'=>$lc->getOriginalFileName(),
|
|
'size'=>(int) $lc->getFileSize(),
|
|
'comment'=>$lc->getComment(),
|
|
);
|
|
return $data;
|
|
} /* }}} */
|
|
|
|
protected function __getDocumentFileData($file) { /* {{{ */
|
|
$data = array(
|
|
'id'=>(int)$file->getId(),
|
|
'name'=>$file->getName(),
|
|
'date'=>$file->getDate(),
|
|
'mimetype'=>$file->getMimeType(),
|
|
'comment'=>$file->getComment(),
|
|
);
|
|
return $data;
|
|
} /* }}} */
|
|
|
|
protected function __getDocumentLinkData($link) { /* {{{ */
|
|
$data = array(
|
|
'id'=>(int)$link->getId(),
|
|
'target'=>$this->__getDocumentData($link->getTarget()),
|
|
'public'=>(boolean)$link->isPublic(),
|
|
);
|
|
return $data;
|
|
} /* }}} */
|
|
|
|
protected function __getFolderData($folder) { /* {{{ */
|
|
$data = array(
|
|
'type'=>'folder',
|
|
'id'=>(int)$folder->getID(),
|
|
'name'=>$folder->getName(),
|
|
'comment'=>$folder->getComment(),
|
|
'date'=>date('Y-m-d H:i:s', $folder->getDate()),
|
|
'owner'=>(int)$folder->getOwner()->getId()
|
|
);
|
|
$attributes = $this->__getAttributesData($folder);
|
|
if($attributes) {
|
|
$data['attributes'] = $attributes;
|
|
}
|
|
return $data;
|
|
} /* }}} */
|
|
|
|
} /* }}} */
|
|
|
|
|