mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-17 15:11:21 +00:00
getStatistics() returns single values, add removeValue(), fix sql in getObjects()
This commit is contained in:
parent
3a6dc48a38
commit
c4addcd4aa
|
@ -809,7 +809,17 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
|||
$queryStr = "SELECT count(*) c, `value` FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." GROUP BY `value` ORDER BY c DESC";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if($resArr) {
|
||||
$result['frequencies']['document'] = $resArr;
|
||||
foreach($resArr as $row) {
|
||||
$tmpattr = new SeedDMS_Core_Attribute(0, null, $this, $row['value']);
|
||||
foreach($tmpattr->getValueAsArray() as $value) {
|
||||
if(isset($possiblevalues[md5($value)])) {
|
||||
$possiblevalues[md5($value)]['c'] += $row['c'];
|
||||
} else {
|
||||
$possiblevalues[md5($value)] = array('value'=>$value, 'c'=>$row['c']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$result['frequencies']['document'] = $possiblevalues;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -826,10 +836,25 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
|||
}
|
||||
}
|
||||
}
|
||||
$valueset = $this->getValueSetAsArray();
|
||||
$possiblevalues = array();
|
||||
foreach($valueset as $value) {
|
||||
$possiblevalues[md5($value)] = array('value'=>$value, 'c'=>0);
|
||||
}
|
||||
$queryStr = "SELECT count(*) c, `value` FROM `tblFolderAttributes` WHERE `attrdef`=".$this->_id." GROUP BY `value` ORDER BY c DESC";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if($resArr) {
|
||||
$result['frequencies']['folder'] = $resArr;
|
||||
foreach($resArr as $row) {
|
||||
$tmpattr = new SeedDMS_Core_Attribute(0, null, $this, $row['value']);
|
||||
foreach($tmpattr->getValueAsArray() as $value) {
|
||||
if(isset($possiblevalues[md5($value)])) {
|
||||
$possiblevalues[md5($value)]['c'] += $row['c'];
|
||||
} else {
|
||||
$possiblevalues[md5($value)] = array('value'=>$value, 'c'=>$row['c']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$result['frequencies']['folder'] = $possiblevalues;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -846,10 +871,25 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
|||
}
|
||||
}
|
||||
}
|
||||
$valueset = $this->getValueSetAsArray();
|
||||
$possiblevalues = array();
|
||||
foreach($valueset as $value) {
|
||||
$possiblevalues[md5($value)] = array('value'=>$value, 'c'=>0);
|
||||
}
|
||||
$queryStr = "SELECT count(*) c, `value` FROM `tblDocumentContentAttributes` WHERE `attrdef`=".$this->_id." GROUP BY `value` ORDER BY c DESC";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if($resArr) {
|
||||
$result['frequencies']['content'] = $resArr;
|
||||
foreach($resArr as $row) {
|
||||
$tmpattr = new SeedDMS_Core_Attribute(0, null, $this, $row['value']);
|
||||
foreach($tmpattr->getValueAsArray() as $value) {
|
||||
if(isset($possiblevalues[md5($value)])) {
|
||||
$possiblevalues[md5($value)]['c'] += $row['c'];
|
||||
} else {
|
||||
$possiblevalues[md5($value)] = array('value'=>$value, 'c'=>$row['c']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$result['frequencies']['content'] = $possiblevalues;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -876,19 +916,25 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
|||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Get all documents and folder by a given attribute value
|
||||
* Get all documents and folders by a given attribute value
|
||||
*
|
||||
* @param string $attrvalue value of attribute
|
||||
* @param integer $limit limit number of documents/folders
|
||||
* @return array array containing list of documents and folders
|
||||
*/
|
||||
public function getObjects($attrvalue, $limit) { /* {{{ */
|
||||
public function getObjects($attrvalue, $limit='') { /* {{{ */
|
||||
$db = $this->_dms->getDB();
|
||||
|
||||
$result = array('docs'=>array(), 'folders'=>array(), 'contents'=>array());
|
||||
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all ||
|
||||
$this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_document) {
|
||||
$queryStr = "SELECT * FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." AND `value`=".$db->qstr($attrvalue);
|
||||
$queryStr = "SELECT * FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." AND ";
|
||||
if($this->getMultipleValues()) {
|
||||
$sep = $this->getValueSetSeparator();
|
||||
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
|
||||
} else {
|
||||
$queryStr .= "`value`=".$db->qstr($attrvalue);
|
||||
}
|
||||
if($limit)
|
||||
$queryStr .= " limit ".(int) $limit;
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
|
@ -903,7 +949,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
|||
|
||||
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all ||
|
||||
$this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_folder) {
|
||||
$queryStr = "SELECT * FROM `tblFolderAttributes` WHERE `attrdef`=".$this->_id." AND `value`=".$db->qstr($attrvalue);
|
||||
$queryStr = "SELECT * FROM `tblFolderAttributes` WHERE `attrdef`=".$this->_id." AND ";
|
||||
if($this->getMultipleValues()) {
|
||||
$sep = $this->getValueSetSeparator();
|
||||
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
|
||||
} else {
|
||||
$queryStr .= "`value`=".$db->qstr($attrvalue);
|
||||
}
|
||||
if($limit)
|
||||
$queryStr .= " limit ".(int) $limit;
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
|
@ -919,6 +971,72 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
|
|||
return $result;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Remove a given attribute value from all documents, versions and folders
|
||||
*
|
||||
* @param string $attrvalue value of attribute
|
||||
* @return array array containing list of documents and folders
|
||||
*/
|
||||
public function removeValue($attrvalue) { /* {{{ */
|
||||
$db = $this->_dms->getDB();
|
||||
|
||||
foreach(array('document', 'documentcontent', 'folder') as $type) {
|
||||
if($type == 'document') {
|
||||
$tablename = "tblDocumentAttributes";
|
||||
$objtype = SeedDMS_Core_AttributeDefinition::objtype_document;
|
||||
} elseif($type == 'documentcontent') {
|
||||
$tablename = "tblDocumentContentAttributes";
|
||||
$objtype = SeedDMS_Core_AttributeDefinition::objtype_documentcontent;
|
||||
} elseif($type == 'folder') {
|
||||
$tablename = "tblFolderAttributes";
|
||||
$objtype = SeedDMS_Core_AttributeDefinition::objtype_folder;
|
||||
}
|
||||
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all || $objtype) {
|
||||
$queryStr = "SELECT * FROM `".$tablename."` WHERE `attrdef`=".$this->_id." AND ";
|
||||
if($this->getMultipleValues()) {
|
||||
$sep = $this->getValueSetSeparator();
|
||||
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
|
||||
} else {
|
||||
$queryStr .= "`value`=".$db->qstr($attrvalue);
|
||||
}
|
||||
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if($resArr) {
|
||||
$db->startTransaction();
|
||||
foreach($resArr as $rec) {
|
||||
if($rec['value'] == $attrvalue) {
|
||||
$queryStr = "DELETE FROM `".$tablename."` WHERE `id`=".$rec['id'];
|
||||
} else {
|
||||
if($this->getMultipleValues()) {
|
||||
$sep = substr($rec['value'], 0, 1);
|
||||
$vsep = $this->getValueSetSeparator();
|
||||
if($sep == $vsep)
|
||||
$values = explode($sep, substr($rec['value'], 1));
|
||||
else
|
||||
$values = array($rec['value']);
|
||||
if (($key = array_search($attrvalue, $values)) !== false) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
if($values) {
|
||||
$queryStr = "UPDATE `".$tablename."` SET `value`=".$db->qstr($sep.implode($sep, $values))." WHERE `id`=".$rec['id'];
|
||||
} else {
|
||||
$queryStr = "DELETE FROM `".$tablename."` WHERE `id`=".$rec['id'];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
if (!$db->getResult($queryStr)) {
|
||||
$db->rollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$db->commitTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Validate value against attribute definition
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user