add regex for checking attribute values

This commit is contained in:
Uwe Steinmann 2013-05-28 09:01:04 +02:00
parent d11c6d9a74
commit 216eee25b1
3 changed files with 75 additions and 6 deletions

View File

@ -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
*

View File

@ -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;

View File

@ -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;
} /* }}} */
} /* }}} */
?>