initial support for attribute groups

This commit is contained in:
Uwe Steinmann 2016-07-27 08:27:52 +02:00
parent f8d698bab5
commit 463123912d
2 changed files with 283 additions and 1 deletions

View File

@ -1027,4 +1027,236 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
function getValidationError() { return $this->_validation_error; }
} /* }}} */
/**
* Class to represent an attribute defintion group in the document management system
*
* @category DMS
* @package SeedDMS_Core
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2016 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Core_AttributeDefinitionGroup {
/**
* The id of the user group
*
* @var integer
*/
protected $_id;
/**
* The name of the user group
*
* @var string
*/
protected $_name;
/**
* The comment of the user group
*
* @var string
*/
protected $_comment;
/**
* Back reference to DMS this user group belongs to
*
* @var object
*/
protected $_dms;
function __construct($id, $name, $comment) { /* {{{ */
$this->_id = $id;
$this->_name = $name;
$this->_comment = $comment;
$this->_dms = null;
} /* }}} */
/**
* Create an instance of a group object
*
* @param string|integer $id Id, name of group, depending
* on the 3rd parameter.
* @param object $dms instance of dms
* @param string $by search by group name if set to 'name'.
* Search by Id of group if left empty.
* @return object instance of class SeedDMS_Core_Group
*/
public static function getInstance($id, $dms, $by='') { /* {{{ */
$db = $dms->getDB();
switch($by) {
case 'name':
$queryStr = "SELECT * FROM `tblAttributeDefinitionGroups` WHERE `name` = ".$db->qstr($id);
break;
default:
$queryStr = "SELECT * FROM `tblAttributeDefinitionGroups` WHERE id = " . (int) $id;
}
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false)
return false;
else if (count($resArr) != 1) //wenn, dann wohl eher 0 als > 1 ;-)
return false;
$resArr = $resArr[0];
$group = new self($resArr["id"], $resArr["name"], $resArr["comment"]);
$group->setDMS($dms);
return $group;
} /* }}} */
public static function getAllInstances($orderby, $dms) { /* {{{ */
$db = $dms->getDB();
switch($orderby) {
default:
$queryStr = "SELECT * FROM tblAttributeDefinitionGroups ORDER BY name";
}
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false)
return false;
$groups = array();
for ($i = 0; $i < count($resArr); $i++) {
$group = new self($resArr[$i]["id"], $resArr[$i]["name"], $resArr[$i]["comment"]);
$group->setDMS($dms);
$groups[$i] = $group;
}
return $groups;
} /* }}} */
function setDMS($dms) { /* {{{ */
$this->_dms = $dms;
} /* }}} */
function getID() { return $this->_id; }
function getName() { return $this->_name; }
function setName($newName) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblAttributeDefinitionGroups SET name = ".$db->qstr($newName)." WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$this->_name = $newName;
return true;
} /* }}} */
function getComment() { return $this->_comment; }
function setComment($newComment) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "UPDATE tblAttributeDefinitionGroups SET comment = ".$db->qstr($newComment)." WHERE id = " . $this->_id;
if (!$db->getResult($queryStr))
return false;
$this->_comment = $newComment;
return true;
} /* }}} */
function getAttributesDefinitions() { /* {{{ */
$db = $this->_dms->getDB();
if (!isset($this->_attrdefs)) {
$queryStr = "SELECT `tblAttributeDefinitions`.* FROM `tblAttributeDefinitions` ".
"LEFT JOIN `tblAttributeDefinitionGroupAttributeDefinition` ON `tblAttributeDefinitionGroupAttributeDefinition`.`userID`=`tblAttributeDefinitions`.`id` ".
"WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'";
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false)
return false;
$this->_attrdefs = array();
$classname = $this->_dms->getClassname('attributedefinition');
foreach ($resArr as $row) {
$user = new $classname($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $role, $row['hidden']);
$user->setDMS($this->_dms);
array_push($this->_attrdefs, $user);
}
}
return $this->_attrdefs;
} /* }}} */
function addAttributeDefinition($user,$show=false) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "INSERT INTO tblAttributeDefinitionGroupAttributeDefinition (attrgroupdef, attrdef, show) VALUES (".$this->_id.", ".$user->getID(). ", " . (int)$show ." )";
$res = $db->getResult($queryStr);
if (!$res) return false;
unset($this->_attrdefs);
return true;
} /* }}} */
function removeAttributeDefinition($attrdef) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "DELETE FROM tblAttributeDefinitionGroupAttributeDefinition WHERE attrgroupdef = ".$this->_id." AND attrdef = ".$attrdef->getID();
$res = $db->getResult($queryStr);
if (!$res) return false;
unset($this->_attrdefs);
return true;
} /* }}} */
// $asManager=false: verify if user is in group
// $asManager=true : verify if user is in group as manager
function isMember($attrdef) { /* {{{ */
$db = $this->_dms->getDB();
$queryStr = "SELECT * FROM tblAttributeDefinitionGroupAttributeDefinition WHERE attrgroupdef = " . $this->_id . " AND attrdef = " . $attrdef->getID();
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false) return false;
if (count($resArr) != 1) return false;
return true;
} /* }}} */
function toggleManager($user) { /* {{{ */
$db = $this->_dms->getDB();
if (!$this->isMember($user)) return false;
if ($this->isMember($user,true)) $queryStr = "UPDATE tblGroupMembers SET manager = 0 WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
else $queryStr = "UPDATE tblGroupMembers SET manager = 1 WHERE groupID = ".$this->_id." AND userID = ".$user->getID();
if (!$db->getResult($queryStr)) return false;
return true;
} /* }}} */
/**
* Delete user group
* This function deletes the user group and all it references, like access
* control lists, notifications, as a child of other groups, etc.
*
* @param object $user the user doing the removal (needed for entry in
* review log.
* @return boolean true on success or false in case of an error
*/
function remove($user) { /* {{{ */
$db = $this->_dms->getDB();
$db->startTransaction();
$queryStr = "DELETE FROM tblAttributeDefinitionGroups WHERE id = " . $this->_id;
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
$db->commitTransaction();
return true;
} /* }}} */
}
?>

View File

@ -2198,7 +2198,7 @@ class SeedDMS_Core_DMS {
/**
* Return a attribute definition by its id
*
* This function retrieves a attribute definitionr from the database by
* This function retrieves a attribute definition from the database by
* its id.
*
* @param integer $id internal id of attribute defintion
@ -2307,6 +2307,56 @@ class SeedDMS_Core_DMS {
return $this->getAttributeDefinition($this->db->getInsertID());
} /* }}} */
/**
* Return a attribute definition group by its id
*
* This function retrieves a attribute definition group from the database by
* its id.
*
* @param integer $id internal id of attribute defintion group
* @return object instance of {@link SeedDMS_Core_AttributeDefinitionGroup} or false
*/
function getAttributeDefinitionGroup($id) { /* {{{ */
if (!is_numeric($id))
return false;
$queryStr = "SELECT * FROM tblAttributeDefinitionGroups WHERE id = " . (int) $id;
$resArr = $this->db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false) return false;
if (count($resArr) != 1) return false;
$resArr = $resArr[0];
$attrdef = new SeedDMS_Core_AttributeDefinitionGroup($resArr["id"], $resArr["name"], $resArr["comment"]);
$attrdef->setDMS($this);
return $attrdef;
} /* }}} */
/**
* Return list of all attributes definition groups
*
* @return array of instances of {@link SeedDMS_Core_AttributeDefinitionGroup} or false
*/
function getAllAttributeDefinitionGroups() { /* {{{ */
$queryStr = "SELECT * FROM tblAttributeDefinitionGroups";
$queryStr .= ' ORDER BY name';
$resArr = $this->db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr == false)
return false;
$attrdefs = array();
for ($i = 0; $i < count($resArr); $i++) {
$attrdef = new SeedDMS_Core_AttributeDefinitionGroup($resArr[$i]["id"], $resArr[$i]["name"], $resArr[$i]["comment"]);
$attrdef->setDMS($this);
$attrdefs[$i] = $attrdef;
}
return $attrdefs;
} /* }}} */
/**
* Return list of all workflows
*