add method concat() and use it in getStatistics() for docspersuser and foldersperuser

This commit is contained in:
Uwe Steinmann 2021-07-11 20:41:53 +02:00
parent 51b72eb7b2
commit 39eda2a180
2 changed files with 23 additions and 2 deletions

View File

@ -3174,14 +3174,14 @@ class SeedDMS_Core_DMS {
function getStatisticalData($type='') { /* {{{ */
switch($type) {
case 'docsperuser':
$queryStr = "select concat(b.`fullName`, ' (', b.`login`, ')') as `key`, count(`owner`) as total from `tblDocuments` a left join `tblUsers` b on a.`owner`=b.`id` group by `owner`, b.`fullName`";
$queryStr = "select ".$this->db->concat(array('b.`fullName`', "' ('", 'b.`login`', "')'"))." as `key`, count(`owner`) as total from `tblDocuments` a left join `tblUsers` b on a.`owner`=b.`id` group by `owner`, b.`fullName`";
$resArr = $this->db->getResultArray($queryStr);
if (!$resArr)
return false;
return $resArr;
case 'foldersperuser':
$queryStr = "select concat(b.`fullName`, ' (', b.`login`, ')') as `key`, count(`owner`) as total from `tblFolders` a left join `tblUsers` b on a.`owner`=b.`id` group by `owner`, b.`fullName`";
$queryStr = "select ".$this->db->concat(array('b.`fullName`', "' ('", 'b.`login`', "')'"))." as `key`, count(`owner`) as total from `tblFolders` a left join `tblUsers` b on a.`owner`=b.`id` group by `owner`, b.`fullName`";
$resArr = $this->db->getResultArray($queryStr);
if (!$resArr)
return false;

View File

@ -346,6 +346,27 @@ class SeedDMS_Core_DatabaseAccess {
return str_replace('`', '"', $text);
} /* }}} */
/**
* Return sql to concat strings or fields
*
* @param array $arr list of field names or strings
* @return string concated string
*/
function concat($arr) { /* {{{ */
switch($this->_driver) {
case 'mysql':
return 'concat('.implode(',', $arr).')';
break;
case 'pgsql':
return implode(' || ', $arr);
break;
case 'sqlite':
return implode(' || ', $arr);
break;
}
return '';
} /* }}} */
/**
* Execute SQL query and return result
*