seeddms-code/inc/inc.TraitRestapi.php
2026-01-31 16:11:17 +01:00

215 lines
7.2 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;
} /* }}} */
protected function __getGroupData($u) { /* {{{ */
$data = array(
'type'=>'group',
'id'=>(int)$u->getID(),
'name'=>$u->getName(),
'comment'=>$u->getComment(),
);
return $data;
} /* }}} */
protected function __getUserData($u) { /* {{{ */
$data = array(
'type'=>'user',
'id'=>(int)$u->getID(),
'name'=>$u->getFullName(),
'comment'=>$u->getComment(),
'login'=>$u->getLogin(),
'email'=>$u->getEmail(),
'language' => $u->getLanguage(),
'quota' => $u->getQuota(),
'homefolder' => $u->getHomeFolder(),
'theme' => $u->getTheme(),
'role' => $this->__getRoleData($u->getRole()), //array('id'=>(int)$u->getRole()->getId(), 'name'=>$u->getRole()->getName()),
'hidden'=>$u->isHidden() ? true : false,
'disabled'=>$u->isDisabled() ? true : false,
'isguest' => $u->isGuest() ? true : false,
'isadmin' => $u->isAdmin() ? true : false,
);
if($u->getHomeFolder())
$data['homefolder'] = (int)$u->getHomeFolder();
$groups = $u->getGroups();
if($groups) {
$tmp = [];
foreach($groups as $group)
$tmp[] = $this->__getGroupData($group);
$data['groups'] = $tmp;
}
return $data;
} /* }}} */
protected function __getRoleData($r) { /* {{{ */
$data = array(
'type'=>'role',
'id'=>(int)$r->getID(),
'name'=>$r->getName(),
'role'=>$r->getRole()
);
return $data;
} /* }}} */
protected function __getAttributeDefinitionData($attrdef) { /* {{{ */
$data = [
'id' => (int)$attrdef->getId(),
'name' => $attrdef->getName(),
'type'=>(int)$attrdef->getType(),
'objtype'=>(int)$attrdef->getObjType(),
'min'=>(int)$attrdef->getMinValues(),
'max'=>(int)$attrdef->getMaxValues(),
'multiple'=>$attrdef->getMultipleValues()?true:false,
'valueset'=>$attrdef->getValueSetAsArray(),
'regex'=>$attrdef->getRegex()
];
return $data;
} /* }}} */
protected function __getCategoryData($category) { /* {{{ */
$data = [
'id'=>(int)$category->getId(),
'name'=>$category->getName()
];
return $data;
} /* }}} */
} /* }}} */