add more documentation

This commit is contained in:
Uwe Steinmann 2021-09-16 16:14:21 +02:00
parent 32dda4b3e9
commit 4aa4556df8

View File

@ -704,6 +704,8 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
/** /**
* Get the whole value set as an array * Get the whole value set as an array
* *
* Each element is trimmed.
*
* @return array values of value set or false if the value set has * @return array values of value set or false if the value set has
* less than 2 chars * less than 2 chars
*/ */
@ -715,9 +717,9 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
} /* }}} */ } /* }}} */
/** /**
* Get the n'th value of a value set * Get the n'th trimmed value of a value set
* *
* @param $ind * @param $ind starting from 0 for the first element in the value set
* @return string n'th value of value set or false if the index is * @return string n'th value of value set or false if the index is
* out of range or the value set has less than 2 chars * out of range or the value set has less than 2 chars
* @internal param int $index * @internal param int $index
@ -738,7 +740,9 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
* *
* A value set is a list of values allowed for an attribute. The values * A value set is a list of values allowed for an attribute. The values
* are separated by a char which must also be the first char of the * are separated by a char which must also be the first char of the
* value set string. * value set string. The method decomposes the value set, removes all
* leading and trailing white space from the elements and recombines them
* into a string.
* *
* @param string $valueset * @param string $valueset
* @return boolean true if value set could be set, otherwise false * @return boolean true if value set could be set, otherwise false
@ -784,12 +788,23 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
* *
* A value of the attribute must match this regular expression. * A value of the attribute must match this regular expression.
* *
* The methods checks if the regular expression is valid by running
* preg_match() on an empty string and see if it fails. Trying to set
* an invalid regular expression will not overwrite the current
* regular expression.
*
* All leading and trailing spaces of $regex will be removed.
*
* @param string $regex * @param string $regex
* @return boolean true if regex could be set, otherwise false * @return boolean true if regex could be set or is invalid, otherwise false
*/ */
function setRegex($regex) { /* {{{ */ function setRegex($regex) { /* {{{ */
$db = $this->_dms->getDB(); $db = $this->_dms->getDB();
$regex = trim($regex);
if(@preg_match($regex, '') === false)
return false;
$queryStr = "UPDATE `tblAttributeDefinitions` SET `regex` =".$db->qstr($regex)." WHERE `id` = " . $this->_id; $queryStr = "UPDATE `tblAttributeDefinitions` SET `regex` =".$db->qstr($regex)." WHERE `id` = " . $this->_id;
$res = $db->getResult($queryStr); $res = $db->getResult($queryStr);
if (!$res) if (!$res)
@ -830,13 +845,15 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
/** /**
* Parse a given value according to attribute definition * Parse a given value according to attribute definition
* *
* The return value is always an array, even if the attribute is single * The return value is always an array, even if the attribute is a single
* value attribute. * value attribute. If the type of attribute is any of document, folder, user,
* or group then this method will fetch each object from the database and
* return an array of SeedDMS_Core_Document, SeedDMS_Core_Folder, etc.
* *
* @param $value * @param $value string
* @return array|bool * @return array|bool
*/ */
function parseValue($value) { /* {{{ */ function parseValue(string $value) { /* {{{ */
if($this->getMultipleValues()) { if($this->getMultipleValues()) {
/* If the value doesn't start with the separator used in the value set, /* If the value doesn't start with the separator used in the value set,
* then assume that the value was not saved with a leading separator. * then assume that the value was not saved with a leading separator.
@ -1165,8 +1182,10 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
* *
* @param string|array $attrvalue attribute value * @param string|array $attrvalue attribute value
* @param object $object set if the current attribute is saved for this object * @param object $object set if the current attribute is saved for this object
* (this will only be passed to the onAttributeValidate callback)
* @param boolean $new set to true if the value is new value and not taken from * @param boolean $new set to true if the value is new value and not taken from
* an existing attribute * an existing attribute
* (this will only be passed to the onAttributeValidate callback)
* @return boolean true if validation succeds, otherwise false * @return boolean true if validation succeds, otherwise false
*/ */
function validate($attrvalue, $object=null, $new=false) { /* {{{ */ function validate($attrvalue, $object=null, $new=false) { /* {{{ */