mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-10-09 02:22:40 +00:00
add regex for checking attribute values
This commit is contained in:
parent
d11c6d9a74
commit
216eee25b1
|
@ -221,6 +221,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
||||||
*/
|
*/
|
||||||
protected $_valueset;
|
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
|
* @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
|
* @param string $valueset separated list of allowed values, the first char
|
||||||
* is taken as the separator
|
* 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->_id = $id;
|
||||||
$this->_name = $name;
|
$this->_name = $name;
|
||||||
$this->_type = $type;
|
$this->_type = $type;
|
||||||
|
@ -268,6 +275,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
||||||
$this->_maxvalues = $maxvalues;
|
$this->_maxvalues = $maxvalues;
|
||||||
$this->_valueset = $valueset;
|
$this->_valueset = $valueset;
|
||||||
$this->_separator = '';
|
$this->_separator = '';
|
||||||
|
$this->_regex = $regex;
|
||||||
$this->_dms = null;
|
$this->_dms = null;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
@ -438,6 +446,35 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
||||||
return true;
|
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
|
* Check if the attribute definition is used
|
||||||
*
|
*
|
||||||
|
|
|
@ -1453,7 +1453,7 @@ class SeedDMS_Core_DMS {
|
||||||
|
|
||||||
$resArr = $resArr[0];
|
$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);
|
$attrdef->setDMS($this);
|
||||||
return $attrdef;
|
return $attrdef;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
@ -1477,7 +1477,7 @@ class SeedDMS_Core_DMS {
|
||||||
|
|
||||||
$resArr = $resArr[0];
|
$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);
|
$attrdef->setDMS($this);
|
||||||
return $attrdef;
|
return $attrdef;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
@ -1505,7 +1505,7 @@ class SeedDMS_Core_DMS {
|
||||||
$attrdefs = array();
|
$attrdefs = array();
|
||||||
|
|
||||||
for ($i = 0; $i < count($resArr); $i++) {
|
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);
|
$attrdef->setDMS($this);
|
||||||
$attrdefs[$i] = $attrdef;
|
$attrdefs[$i] = $attrdef;
|
||||||
}
|
}
|
||||||
|
@ -1524,13 +1524,13 @@ class SeedDMS_Core_DMS {
|
||||||
* @param string $valueset list of allowed values (csv format)
|
* @param string $valueset list of allowed values (csv format)
|
||||||
* @return object of {@link SeedDMS_Core_User}
|
* @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))) {
|
if (is_object($this->getAttributeDefinitionByName($name))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!$type)
|
if(!$type)
|
||||||
return false;
|
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);
|
$res = $this->db->getResult($queryStr);
|
||||||
if (!$res)
|
if (!$res)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -158,5 +158,37 @@ class SeedDMS_Core_Object { /* {{{ */
|
||||||
return true;
|
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;
|
||||||
|
} /* }}} */
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user