add support for custom attributes of categories

This commit is contained in:
Uwe Steinmann 2021-07-12 18:21:41 +02:00
parent b47c01fdd8
commit 2061cde061
10 changed files with 119 additions and 17 deletions

View File

@ -251,6 +251,12 @@ class SeedDMS_Core_Attribute { /* {{{ */
else
$queryStr = "UPDATE `tblFolderAttributes` SET `value` = ".$db->qstr($value)." WHERE `folder` = " . $this->_obj->getID() . " AND `attrdef` = " . $this->_attrdef->getId();
break;
case $this->_dms->getClassname('user'):
if(trim($value) === '')
$queryStr = "DELETE FROM `tblUserAttributes WHERE` `userID` = " . $this->_obj->getID() . " AND `attrdef` = " . $this->_attrdef->getId();
else
$queryStr = "UPDATE `tblUserAttributes` SET `value` = ".$db->qstr($value)." WHERE `userID` = " . $this->_obj->getID() . " AND `attrdef` = " . $this->_attrdef->getId();
break;
default:
return false;
}
@ -440,6 +446,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
const objtype_folder = '1';
const objtype_document = '2';
const objtype_documentcontent = '3';
const objtype_user = '4';
/**
* Constructor
@ -517,7 +524,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
* Get object type of attribute definition
*
* This can be one of objtype_all,
* objtype_folder, objtype_document, or objtype_documentcontent.
* objtype_folder, objtype_document, objtype_documentcontent, or objtype_user.
*
* @return integer type
*/
@ -527,7 +534,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
* Set object type of attribute definition
*
* This can be one of objtype_all,
* objtype_folder, objtype_document, or objtype_documentcontent.
* objtype_folder, objtype_document, objtype_documentcontent, or objtype_user.
*
* @param integer $objtype type
* @return bool
@ -1064,6 +1071,27 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
}
}
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all ||
$this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_user) {
$queryStr = "SELECT * FROM `tblUserAttributes` WHERE `attrdef`=".$this->_id." AND ";
if($this->getMultipleValues()) {
$sep = $this->getValueSetSeparator();
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
} else {
$queryStr .= "`value`=".$db->qstr($attrvalue);
}
if($limit)
$queryStr .= " limit ".(int) $limit;
$resArr = $db->getResultArray($queryStr);
if($resArr) {
foreach($resArr as $rec) {
if($user = $this->_dms->getUser($rec['userID'])) {
$result['users'][] = $user;
}
}
}
}
return $result;
} /* }}} */

View File

@ -100,6 +100,9 @@ class SeedDMS_Core_Object { /* {{{ */
case $this->_dms->getClassname('folder'):
$queryStr = "SELECT a.* FROM `tblFolderAttributes` a LEFT JOIN `tblAttributeDefinitions` b ON a.`attrdef`=b.`id` WHERE a.`folder` = " . $this->_id." ORDER BY b.`name`";
break;
case $this->_dms->getClassname('user'):
$queryStr = "SELECT a.* FROM `tblUserAttributes` a LEFT JOIN `tblAttributeDefinitions` b ON a.`attrdef`=b.`id` WHERE a.`userID` = " . $this->_id." ORDER BY b.`name`";
break;
default:
return false;
}
@ -259,6 +262,10 @@ class SeedDMS_Core_Object { /* {{{ */
$tablename = 'tblFolderAttributes';
$queryStr = "INSERT INTO `tblFolderAttributes` (`folder`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
break;
case $this->_dms->getClassname('user'):
$tablename = 'tblUserAttributes';
$queryStr = "INSERT INTO `tblUserAttributes` (`userID`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
break;
default:
return false;
}
@ -299,6 +306,9 @@ class SeedDMS_Core_Object { /* {{{ */
case $this->_dms->getClassname('folder'):
$queryStr = "DELETE FROM `tblFolderAttributes` WHERE `folder`=".$this->_id." AND `attrdef`=".$attrdef->getId();
break;
case $this->_dms->getClassname('user'):
$queryStr = "DELETE FROM `tblUserAttributes` WHERE `userID`=".$this->_id." AND `attrdef`=".$attrdef->getId();
break;
default:
return false;
}

View File

@ -430,14 +430,7 @@ class SeedDMS_Core_ApiKey { /* {{{ */
* 2010 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Core_User { /* {{{ */
/**
* @var integer id of user
*
* @access protected
*/
var $_id;
class SeedDMS_Core_User extends SeedDMS_Core_Object { /* {{{ */
/**
* @var string login name of user
*
@ -559,13 +552,6 @@ class SeedDMS_Core_User { /* {{{ */
*/
var $_rev_substitutes;
/**
* @var SeedDMS_Core_DMS reference to the dms instance this user belongs to
*
* @access protected
*/
var $_dms;
/**
* @var int
*/

View File

@ -26,6 +26,7 @@
<notes>
add class SeedDMS_Core_ApiKey
add property color to SeedDMS_Document_Category
support custom attributes for users
</notes>
<contents>
<dir baseinstalldir="SeedDMS" name="/">

View File

@ -44,6 +44,14 @@ CREATE TABLE "tblFolderAttributeDefinitionGroup" (
UNIQUE ("folder", "attrgrp")
);
CREATE TABLE "tblUserAttributes" (
"id" SERIAL UNIQUE,
"userID" INTEGER default NULL REFERENCES "tblUsers" ("id") ON DELETE CASCADE,
"attrdef" INTEGER default NULL REFERENCES "tblAttributeDefinitions" ("id"),
"value" text default NULL,
UNIQUE (userID, attrdef)
) ;
UPDATE "tblVersion" set "major"=6, "minor"=1, "subminor"=0, "module"='core';
COMMIT;

View File

@ -90,6 +90,14 @@ CREATE TABLE `tblFolderAttributeDefinitionGroup` (
UNIQUE(`folder`, `attrgrp`)
);
CREATE TABLE `tblUserAttributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`userID` INTEGER default NULL REFERENCES `tblUsers` (`id`) ON DELETE CASCADE,
`attrdef` INTEGER default NULL REFERENCES `tblAttributeDefinitions` (`id`),
`value` text default NULL,
UNIQUE (`userID`, `attrdef`)
);
UPDATE `tblVersion` set `major`=6, `minor`=1, `subminor`=0, `module`='core';
COMMIT;

View File

@ -49,6 +49,18 @@ CREATE TABLE `tblFolderAttributeDefinitionGroup` (
CONSTRAINT `tblFolderAttributeDefinitionGroup_attrgrp` FOREIGN KEY (`attrgrp`) REFERENCES `tblAttributeDefinitionGroups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tblUserAttributes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userID` int(11) DEFAULT NULL,
`attrdef` int(11) DEFAULT NULL,
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY `userID` (`userID`,`attrdef`),
KEY `tblUserAttributes_attrdef` (`attrdef`),
CONSTRAINT `tblUserAttributes_attrdef` FOREIGN KEY (`attrdef`) REFERENCES `tblAttributeDefinitions` (`id`),
CONSTRAINT `tblUserAttributes_userid` FOREIGN KEY (`userID`) REFERENCES `tblUsers` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
UPDATE `tblVersion` set `major`=6, `minor`=1, `subminor`=0, `module`='core';
COMMIT;

View File

@ -379,6 +379,39 @@ else if ($action == "edituser") {
$homefolder = (isset($_POST["homefolder"]) ? $_POST["homefolder"] : 0);
$quota = (isset($_POST["quota"]) ? (int) $_POST["quota"] : 0);
if(isset($_POST["attributes"]))
$attributes = $_POST["attributes"];
else
$attributes = array();
$oldattributes = $user->getAttributes();
if($attributes) {
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
if(!$attrdef->validate($attribute, $editedUser, true)) {
UI::exitError(getMLText("error_occured"), getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute));
}
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
if(!$editedUser->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
UI::exitError(getMLText("error_occured"), getMLText("error_occured"));
}
} elseif($attrdef->getMinValues() > 0) {
$this->errormsg = getMLText("attr_min_values", array("attrname"=>$attrdef->getName()));
} elseif(isset($oldattributes[$attrdefid])) {
if(!$editedUser->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("error_occured"), getMLText("error_occured"));
}
}
}
foreach($oldattributes as $attrdefid=>$oldattribute) {
if(!isset($attributes[$attrdefid])) {
if(!$editedUser->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("error_occured"), getMLText("error_occured"));
}
}
if (isset($pwd) && ($pwd != "")) {
if($settings->_passwordStrength) {
$ps = new Password_Strength();

View File

@ -218,6 +218,7 @@ $(document).ready( function() {
$options[] = array(SeedDMS_Core_AttributeDefinition::objtype_folder, getMLText('folder'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_folder);
$options[] = array(SeedDMS_Core_AttributeDefinition::objtype_document, getMLText('document'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_document);
$options[] = array(SeedDMS_Core_AttributeDefinition::objtype_documentcontent, getMLText('documentcontent'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_documentcontent);
$options[] = array(SeedDMS_Core_AttributeDefinition::objtype_user, getMLText('user'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_user);
$this->formField(
getMLText("attrdef_objtype"),
array(

View File

@ -399,6 +399,21 @@ $(document).ready( function() {
'value'=>($currUser ? htmlspecialchars($currUser->getComment()) : '')
)
);
$attrdefs = $dms->getAllAttributeDefinitions(array(SeedDMS_Core_AttributeDefinition::objtype_user));
if($attrdefs) {
foreach($attrdefs as $attrdef) {
$arr = $this->callHook('editUserAttribute', $currUser, $attrdef);
if(is_array($arr)) {
if($arr) {
$this->formField($arr[0], $arr[1], isset($arr[2]) ? $arr[2] : null);
}
} elseif(is_string($arr)) {
echo $arr;
} else {
$this->formField(htmlspecialchars($attrdef->getName()), $this->getAttributeEditField($attrdef, $currUser->getAttribute($attrdef)));
}
}
}
$options = array();
foreach($roles as $role) {
$options[] = array($role->getID(), $role->getName(), ($currUser && $currUser->getRole()->getID() == $role->getID()));