From 216eee25b1e6d4e9e5be996c3e1a5ce09364168c Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 28 May 2013 09:01:04 +0200 Subject: [PATCH] add regex for checking attribute values --- SeedDMS_Core/Core/inc.ClassAttribute.php | 39 +++++++++++++++++++++++- SeedDMS_Core/Core/inc.ClassDMS.php | 10 +++--- SeedDMS_Core/Core/inc.ClassObject.php | 32 +++++++++++++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassAttribute.php b/SeedDMS_Core/Core/inc.ClassAttribute.php index 74dd721cc..5557376a6 100644 --- a/SeedDMS_Core/Core/inc.ClassAttribute.php +++ b/SeedDMS_Core/Core/inc.ClassAttribute.php @@ -221,6 +221,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ */ protected $_valueset; + /** + * @var string regular expression the value must match + * + * @access protected + */ + protected $_regex; + /** * @var object SeedDMS_Core_DMS reference to the dms instance this attribute definition belongs to * @@ -258,7 +265,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ * @param string $valueset separated list of allowed values, the first char * is taken as the separator */ - function SeedDMS_Core_AttributeDefinition($id, $name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset) { /* {{{ */ + function SeedDMS_Core_AttributeDefinition($id, $name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset, $regex) { /* {{{ */ $this->_id = $id; $this->_name = $name; $this->_type = $type; @@ -268,6 +275,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ $this->_maxvalues = $maxvalues; $this->_valueset = $valueset; $this->_separator = ''; + $this->_regex = $regex; $this->_dms = null; } /* }}} */ @@ -438,6 +446,35 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ return true; } /* }}} */ + /** + * Get the regular expression as saved in the database + * + * @return string regular expression + */ + function getRegex() { /* {{{ */ + return $this->_regex; + } /* }}} */ + + /** + * Set the regular expression + * + * A value of the attribute must match this regular expression. + * + * @param string $regex + * @return boolean true if regex could be set, otherwise false + */ + function setRegex($regex) { /* {{{ */ + $db = $this->_dms->getDB(); + + $queryStr = "UPDATE tblAttributeDefinitions SET regex =".$db->qstr($regex)." WHERE id = " . $this->_id; + $res = $db->getResult($queryStr); + if (!$res) + return false; + + $this->_regex = $regex; + return true; + } /* }}} */ + /** * Check if the attribute definition is used * diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 4d62581f8..221ef7436 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -1453,7 +1453,7 @@ class SeedDMS_Core_DMS { $resArr = $resArr[0]; - $attrdef = new SeedDMS_Core_AttributeDefinition($resArr["id"], $resArr["name"], $resArr["objtype"], $resArr["type"], $resArr["multiple"], $resArr["minvalues"], $resArr["maxvalues"], $resArr["valueset"]); + $attrdef = new SeedDMS_Core_AttributeDefinition($resArr["id"], $resArr["name"], $resArr["objtype"], $resArr["type"], $resArr["multiple"], $resArr["minvalues"], $resArr["maxvalues"], $resArr["valueset"], $resArr["regex"]); $attrdef->setDMS($this); return $attrdef; } /* }}} */ @@ -1477,7 +1477,7 @@ class SeedDMS_Core_DMS { $resArr = $resArr[0]; - $attrdef = new SeedDMS_Core_AttributeDefinition($resArr["id"], $resArr["name"], $resArr["objtype"], $resArr["type"], $resArr["multiple"], $resArr["minvalues"], $resArr["maxvalues"], $resArr["valueset"]); + $attrdef = new SeedDMS_Core_AttributeDefinition($resArr["id"], $resArr["name"], $resArr["objtype"], $resArr["type"], $resArr["multiple"], $resArr["minvalues"], $resArr["maxvalues"], $resArr["valueset"], $resArr["regex"]); $attrdef->setDMS($this); return $attrdef; } /* }}} */ @@ -1505,7 +1505,7 @@ class SeedDMS_Core_DMS { $attrdefs = array(); for ($i = 0; $i < count($resArr); $i++) { - $attrdef = new SeedDMS_Core_AttributeDefinition($resArr[$i]["id"], $resArr[$i]["name"], $resArr[$i]["objtype"], $resArr[$i]["type"], $resArr[$i]["multiple"], $resArr[$i]["minvalues"], $resArr[$i]["maxvalues"], $resArr[$i]["valueset"]); + $attrdef = new SeedDMS_Core_AttributeDefinition($resArr[$i]["id"], $resArr[$i]["name"], $resArr[$i]["objtype"], $resArr[$i]["type"], $resArr[$i]["multiple"], $resArr[$i]["minvalues"], $resArr[$i]["maxvalues"], $resArr[$i]["valueset"], $resArr[$i]["regex"]); $attrdef->setDMS($this); $attrdefs[$i] = $attrdef; } @@ -1524,13 +1524,13 @@ class SeedDMS_Core_DMS { * @param string $valueset list of allowed values (csv format) * @return object of {@link SeedDMS_Core_User} */ - function addAttributeDefinition($name, $objtype, $type, $multiple=0, $minvalues=0, $maxvalues=1, $valueset='') { /* {{{ */ + function addAttributeDefinition($name, $objtype, $type, $multiple=0, $minvalues=0, $maxvalues=1, $valueset='', $regex='') { /* {{{ */ if (is_object($this->getAttributeDefinitionByName($name))) { return false; } if(!$type) return false; - $queryStr = "INSERT INTO tblAttributeDefinitions (name, objtype, type, multiple, minvalues, maxvalues, valueset) VALUES (".$this->db->qstr($name).", ".intval($objtype).", ".intval($type).", ".intval($multiple).", ".intval($minvalues).", ".intval($maxvalues).", ".$this->db->qstr($valueset).")"; + $queryStr = "INSERT INTO tblAttributeDefinitions (name, objtype, type, multiple, minvalues, maxvalues, valueset, regex) VALUES (".$this->db->qstr($name).", ".intval($objtype).", ".intval($type).", ".intval($multiple).", ".intval($minvalues).", ".intval($maxvalues).", ".$this->db->qstr($valueset).", ".$this->db->qstr($regex).")"; $res = $this->db->getResult($queryStr); if (!$res) return false; diff --git a/SeedDMS_Core/Core/inc.ClassObject.php b/SeedDMS_Core/Core/inc.ClassObject.php index 0669810dc..9e464264e 100644 --- a/SeedDMS_Core/Core/inc.ClassObject.php +++ b/SeedDMS_Core/Core/inc.ClassObject.php @@ -158,5 +158,37 @@ class SeedDMS_Core_Object { /* {{{ */ return true; } /* }}} */ + /** + * Remove an attribute of the object for the given attribute definition + * + * @return boolean true if operation was successful, otherwise false + */ + function removeAttribute($attrdef) { /* {{{ */ + $db = $this->_dms->getDB(); + if (!$this->_attributes) { + $this->getAttributes(); + } + if(isset($this->_attributes[$attrdef->getId()])) { + switch(get_class($this)) { + case "SeedDMS_Core_Document": + $queryStr = "DELETE FROM tblDocumentAttributes WHERE document=".$this->_id." AND attrdef=".$attrdef->getId(); + break; + case "SeedDMS_Core_DocumentContent": + $queryStr = "DELETE FROM tblDocumentContentAttributes WHERE content=".$this->_id." AND attrdef=".$attrdef->getId(); + break; + case "SeedDMS_Core_Folder": + $queryStr = "DELETE FROM tblFolderAttributes WHERE folder=".$this->_id." AND attrdef=".$attrdef->getId(); + break; + default: + return false; + } + $res = $db->getResult($queryStr); + if (!$res) + return false; + + unset($this->_attributes[$attrdef->getId()]); + } + return true; + } /* }}} */ } /* }}} */ ?>