Fixed some formatting to comply with style guidelines.
This commit is contained in:
parent
6f2013845c
commit
27af739fe8
1 changed files with 247 additions and 154 deletions
|
@ -42,13 +42,12 @@ require_once "XML/Util.php";
|
||||||
* @see MetaData
|
* @see MetaData
|
||||||
* @see StoredFile
|
* @see StoredFile
|
||||||
*/
|
*/
|
||||||
class DataEngine{
|
class DataEngine {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param gb reference to BasicStor object
|
* @param BasicStor $gb
|
||||||
* @return this
|
|
||||||
*/
|
*/
|
||||||
function DataEngine(&$gb)
|
function DataEngine(&$gb)
|
||||||
{
|
{
|
||||||
|
@ -64,12 +63,15 @@ class DataEngine{
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method returning array with where-parts of sql queries
|
* Method returning array with where-parts of sql queries
|
||||||
*
|
*
|
||||||
* @param conditions array - see conditions field in search criteria format
|
* @param array $conditions
|
||||||
|
* See 'conditions' field in search criteria format
|
||||||
* definition in DataEngine class documentation
|
* definition in DataEngine class documentation
|
||||||
* @return array of strings - where-parts of SQL qyeries
|
* @return array
|
||||||
|
* array of strings - WHERE-parts of SQL queries
|
||||||
*/
|
*/
|
||||||
function _makeWhereArr($conditions)
|
function _makeWhereArr($conditions)
|
||||||
{
|
{
|
||||||
|
@ -78,8 +80,8 @@ class DataEngine{
|
||||||
'>'=>"> '%s'", '<='=>"<= '%s'", '>='=>">= '%s'"
|
'>'=>"> '%s'", '<='=>"<= '%s'", '>='=>">= '%s'"
|
||||||
);
|
);
|
||||||
$whereArr = array();
|
$whereArr = array();
|
||||||
if(is_array($conditions)){
|
if (is_array($conditions)) {
|
||||||
foreach($conditions as $cond){
|
foreach ($conditions as $cond) {
|
||||||
$catQn = $cond['cat'];
|
$catQn = $cond['cat'];
|
||||||
$op = strtolower($cond['op']);
|
$op = strtolower($cond['op']);
|
||||||
$value = strtolower($cond['val']);
|
$value = strtolower($cond['val']);
|
||||||
|
@ -88,9 +90,11 @@ class DataEngine{
|
||||||
$cat = $splittedQn['localPart'];
|
$cat = $splittedQn['localPart'];
|
||||||
$opVal = sprintf($ops[$op], pg_escape_string($value));
|
$opVal = sprintf($ops[$op], pg_escape_string($value));
|
||||||
// retype for timestamp value
|
// retype for timestamp value
|
||||||
if($cat == 'mtime'){
|
if ($cat == 'mtime') {
|
||||||
switch($op){
|
switch ($op) {
|
||||||
case'partial': case'prefix': break;
|
case 'partial':
|
||||||
|
case 'prefix':
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$retype = "::timestamp with time zone";
|
$retype = "::timestamp with time zone";
|
||||||
$opVal = "$retype $opVal$retype";
|
$opVal = "$retype $opVal$retype";
|
||||||
|
@ -103,7 +107,7 @@ class DataEngine{
|
||||||
" %s.predicate = '{$cat}' AND".
|
" %s.predicate = '{$cat}' AND".
|
||||||
" %s.objns='_L' AND %s.predxml='T'".
|
" %s.objns='_L' AND %s.predxml='T'".
|
||||||
" AND lower(%s.object) {$opVal}\n";
|
" AND lower(%s.object) {$opVal}\n";
|
||||||
if(!is_null($catNs)){
|
if (!is_null($catNs)) {
|
||||||
$catNs = str_replace("%", "%%", $catNs);
|
$catNs = str_replace("%", "%%", $catNs);
|
||||||
$sqlCond = " %s.predns = '{$catNs}' AND $sqlCond";
|
$sqlCond = " %s.predns = '{$catNs}' AND $sqlCond";
|
||||||
}
|
}
|
||||||
|
@ -113,132 +117,183 @@ class DataEngine{
|
||||||
return $whereArr;
|
return $whereArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method returning SQL query for search/browse with AND operator
|
* Method returning SQL query for search/browse with AND operator
|
||||||
* (without using INTERSECT command)
|
* (without using INTERSECT command)
|
||||||
*
|
*
|
||||||
* @param fldsPart string - fields part of sql query
|
* @param string $fldsPart
|
||||||
* @param whereArr array - array of where-parts
|
* fields part of SQL query
|
||||||
* @param fileCond string - condition for files table
|
* @param array $whereArr
|
||||||
* @param browse boolean - true if browse vals required instead of gunids
|
* array of WHERE-parts
|
||||||
* @param brFldNs string - namespace prefix of category for browse
|
* @param string $fileCond
|
||||||
* @param brFld string - category for browse
|
* Condition for files table
|
||||||
* @return query string
|
* @param boolean $browse
|
||||||
|
* TRUE if browse vals required instead of gunids
|
||||||
|
* @param string $brFldNs
|
||||||
|
* Namespace prefix of category for browse
|
||||||
|
* @param string $brFld
|
||||||
|
* Category for browse
|
||||||
|
* @return string
|
||||||
|
* query
|
||||||
*/
|
*/
|
||||||
function _makeAndSqlWoIntersect($fldsPart, $whereArr, $fileCond, $browse,
|
function _makeAndSqlWoIntersect($fldsPart, $whereArr, $fileCond, $browse,
|
||||||
$brFldNs=NULL, $brFld=NULL)
|
$brFldNs=NULL, $brFld=NULL)
|
||||||
{
|
{
|
||||||
$innerBlocks = array();
|
$innerBlocks = array();
|
||||||
foreach($whereArr as $i=>$v){
|
foreach ($whereArr as $i => $v) {
|
||||||
$whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i");
|
$whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i");
|
||||||
$lastTbl = ($i==0 ? "f" : "md".($i-1));
|
$lastTbl = ($i==0 ? "f" : "md".($i-1));
|
||||||
$innerBlocks[] =
|
$innerBlocks[] = "INNER JOIN {$this->mdataTable} md$i ON md$i.gunid = $lastTbl.gunid\n";
|
||||||
"INNER JOIN {$this->mdataTable} md$i ON md$i.gunid = $lastTbl.gunid\n";
|
|
||||||
}
|
}
|
||||||
// query construcion:
|
// query construcion:
|
||||||
$sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n".join("", $innerBlocks);
|
$sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n".join("", $innerBlocks);
|
||||||
if($browse){
|
if ($browse) {
|
||||||
$sql .= "INNER JOIN {$this->mdataTable} br".
|
$sql .= "INNER JOIN {$this->mdataTable} br".
|
||||||
"\n ON br.gunid = f.gunid AND br.objns='_L'".
|
"\n ON br.gunid = f.gunid AND br.objns='_L'".
|
||||||
" AND br.predicate='{$brFld}' AND br.predxml='T'";
|
" AND br.predicate='{$brFld}' AND br.predxml='T'";
|
||||||
if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'";
|
if (!is_null($brFldNs)) {
|
||||||
|
$sql .= " AND br.predns='{$brFldNs}'";
|
||||||
|
}
|
||||||
$sql .= "\n";
|
$sql .= "\n";
|
||||||
}
|
}
|
||||||
if(!is_null($fileCond)) $whereArr[] = " $fileCond";
|
if (!is_null($fileCond)) {
|
||||||
if(count($whereArr)>0) $sql .= "WHERE\n".join(" AND\n", $whereArr);
|
$whereArr[] = " $fileCond";
|
||||||
if($browse) $sql .= "\nORDER BY br.object";
|
}
|
||||||
|
if (count($whereArr) > 0) {
|
||||||
|
$sql .= "WHERE\n".join(" AND\n", $whereArr);
|
||||||
|
}
|
||||||
|
if ($browse) {
|
||||||
|
$sql .= "\nORDER BY br.object";
|
||||||
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method returning SQL query for search/browse with AND operator
|
* Method returning SQL query for search/browse with AND operator
|
||||||
* (using INTERSECT command)
|
* (using INTERSECT command)
|
||||||
*
|
*
|
||||||
* @param fldsPart string - fields part of sql query
|
* @param string $fldsPart
|
||||||
* @param whereArr array - array of where-parts
|
* Fields part of sql query
|
||||||
* @param fileCond string - condition for files table
|
* @param array $whereArr
|
||||||
* @param browse boolean - true if browse vals required instead of gunids
|
* Array of where-parts
|
||||||
* @param brFldNs string - namespace prefix of category for browse
|
* @param string $fileCond
|
||||||
* @param brFld string - category for browse
|
* Condition for files table
|
||||||
* @return query string
|
* @param boolean $browse
|
||||||
|
* true if browse vals required instead of gunids
|
||||||
|
* @param string $brFldNs
|
||||||
|
* namespace prefix of category for browse
|
||||||
|
* @param string $brFld
|
||||||
|
* category for browse
|
||||||
|
* @return string
|
||||||
|
* query
|
||||||
*/
|
*/
|
||||||
function _makeAndSql($fldsPart, $whereArr, $fileCond, $browse,
|
function _makeAndSql($fldsPart, $whereArr, $fileCond, $browse,
|
||||||
$brFldNs=NULL, $brFld=NULL)
|
$brFldNs=NULL, $brFld=NULL)
|
||||||
{
|
{
|
||||||
if(!USE_INTERSECT) return $this->_makeAndSqlWoIntersect(
|
if (!USE_INTERSECT) {
|
||||||
$fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
|
return $this->_makeAndSqlWoIntersect($fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
|
||||||
|
}
|
||||||
$isectBlocks = array();
|
$isectBlocks = array();
|
||||||
foreach($whereArr as $i=>$v){
|
foreach ($whereArr as $i => $v) {
|
||||||
$whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i");
|
$whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i");
|
||||||
$isectBlocks[] =
|
$isectBlocks[] =
|
||||||
" SELECT gunid FROM {$this->mdataTable} md$i\n".
|
" SELECT gunid FROM {$this->mdataTable} md$i\n".
|
||||||
" WHERE\n {$whereArr[$i]}";
|
" WHERE\n {$whereArr[$i]}";
|
||||||
}
|
}
|
||||||
// query construcion:
|
// query construcion:
|
||||||
if(count($isectBlocks)>0){
|
if (count($isectBlocks)>0) {
|
||||||
$isectBlock =
|
$isectBlock =
|
||||||
"FROM\n(\n".join("INTERSECT\n", $isectBlocks).") sq\n".
|
"FROM\n(\n".join("INTERSECT\n", $isectBlocks).") sq\n".
|
||||||
"INNER JOIN {$this->filesTable} f ON f.gunid = sq.gunid";
|
"INNER JOIN {$this->filesTable} f ON f.gunid = sq.gunid";
|
||||||
}else{
|
} else {
|
||||||
$isectBlock = "FROM {$this->filesTable} f";
|
$isectBlock = "FROM {$this->filesTable} f";
|
||||||
}
|
}
|
||||||
$sql =
|
$sql = "SELECT $fldsPart\n".$isectBlock;
|
||||||
"SELECT $fldsPart\n".$isectBlock;
|
if ($browse) {
|
||||||
if($browse){
|
|
||||||
$sql .= "\nINNER JOIN {$this->mdataTable} br ON br.gunid = f.gunid\n".
|
$sql .= "\nINNER JOIN {$this->mdataTable} br ON br.gunid = f.gunid\n".
|
||||||
"WHERE br.objns='_L' AND br.predxml='T' AND br.predicate='{$brFld}'";
|
"WHERE br.objns='_L' AND br.predxml='T' AND br.predicate='{$brFld}'";
|
||||||
if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'";
|
if (!is_null($brFldNs)) {
|
||||||
|
$sql .= " AND br.predns='{$brFldNs}'";
|
||||||
|
}
|
||||||
$glue = " AND";
|
$glue = " AND";
|
||||||
}else{ $glue = "WHERE";}
|
} else {
|
||||||
if(!is_null($fileCond)) $sql .= "\n$glue $fileCond";
|
$glue = "WHERE";
|
||||||
if($browse) $sql .= "\nORDER BY br.object";
|
}
|
||||||
|
if (!is_null($fileCond)) {
|
||||||
|
$sql .= "\n$glue $fileCond";
|
||||||
|
}
|
||||||
|
if ($browse) {
|
||||||
|
$sql .= "\nORDER BY br.object";
|
||||||
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method returning SQL query for search/browse with OR operator
|
* Method returning SQL query for search/browse with OR operator
|
||||||
*
|
*
|
||||||
* @param fldsPart string - fields part of sql query
|
* @param string $fldsPart
|
||||||
* @param whereArr array - array of where-parts
|
* Fields part of sql query
|
||||||
* @param fileCond string - condition for files table
|
* @param array $whereArr
|
||||||
* @param browse boolean - true if browse vals required instead of gunids
|
* Array of where-parts
|
||||||
* @param brFldNs string - namespace prefix of category for browse
|
* @param string $fileCond
|
||||||
* @param brFld string - category for browse
|
* Condition for files table
|
||||||
* @return query string
|
* @param boolean $browse
|
||||||
|
* True if browse vals required instead of gunids
|
||||||
|
* @param string $brFldNs
|
||||||
|
* Namespace prefix of category for browse
|
||||||
|
* @param string $brFld
|
||||||
|
* Category for browse
|
||||||
|
* @return string
|
||||||
|
* query
|
||||||
*/
|
*/
|
||||||
function _makeOrSql($fldsPart, $whereArr, $fileCond, $browse,
|
function _makeOrSql($fldsPart, $whereArr, $fileCond, $browse,
|
||||||
$brFldNs=NULL, $brFld=NULL)
|
$brFldNs=NULL, $brFld=NULL)
|
||||||
{
|
{
|
||||||
//$whereArr[] = " FALSE\n";
|
//$whereArr[] = " FALSE\n";
|
||||||
foreach($whereArr as $i=>$v){
|
foreach ($whereArr as $i => $v) {
|
||||||
$whereArr[$i] = sprintf($v, "md", "md", "md", "md", "md");
|
$whereArr[$i] = sprintf($v, "md", "md", "md", "md", "md");
|
||||||
}
|
}
|
||||||
// query construcion:
|
// query construcion:
|
||||||
$sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n";
|
$sql = "SELECT $fldsPart\nFROM {$this->filesTable} f\n";
|
||||||
if($browse){
|
if ($browse) {
|
||||||
$sql .= "INNER JOIN {$this->mdataTable} br".
|
$sql .= "INNER JOIN {$this->mdataTable} br".
|
||||||
"\n ON br.gunid = f.gunid AND br.objns='_L'".
|
"\n ON br.gunid = f.gunid AND br.objns='_L'".
|
||||||
" AND br.predxml='T' AND br.predicate='{$brFld}'";
|
" AND br.predxml='T' AND br.predicate='{$brFld}'";
|
||||||
if(!is_null($brFldNs)) $sql .= " AND br.predns='{$brFldNs}'";
|
if (!is_null($brFldNs)) {
|
||||||
|
$sql .= " AND br.predns='{$brFldNs}'";
|
||||||
|
}
|
||||||
$sql .= "\n";
|
$sql .= "\n";
|
||||||
}
|
}
|
||||||
if(count($whereArr)>0){
|
if (count($whereArr) > 0) {
|
||||||
$sql .= "INNER JOIN {$this->mdataTable} md ON md.gunid=f.gunid\n";
|
$sql .= "INNER JOIN {$this->mdataTable} md ON md.gunid=f.gunid\n";
|
||||||
$sql .= "WHERE\n(\n".join(" OR\n", $whereArr).")";
|
$sql .= "WHERE\n(\n".join(" OR\n", $whereArr).")";
|
||||||
$glue = " AND";
|
$glue = " AND";
|
||||||
}else{ $glue = "WHERE"; }
|
} else {
|
||||||
if(!is_null($fileCond)) $sql .= "$glue $fileCond";
|
$glue = "WHERE";
|
||||||
if($browse) $sql .= "\nORDER BY br.object";
|
}
|
||||||
|
if (!is_null($fileCond)) {
|
||||||
|
$sql .= "$glue $fileCond";
|
||||||
|
}
|
||||||
|
if ($browse) {
|
||||||
|
$sql .= "\nORDER BY br.object";
|
||||||
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search in local metadata database.
|
* Search in local metadata database.
|
||||||
*
|
*
|
||||||
* @param cri hash, search criteria see DataEngine class documentation
|
* @param array $cri
|
||||||
* @param limit int, limit for result arrays (0 means unlimited)
|
* Search criteria see DataEngine class documentation
|
||||||
* @param offset int, starting point (0 means without offset)
|
* @param int $limit
|
||||||
* @return hash, fields:
|
* Limit for result arrays (0 means unlimited)
|
||||||
|
* @param int $offset
|
||||||
|
* Starting point (0 means without offset)
|
||||||
|
* @return array
|
||||||
|
* hash, fields:
|
||||||
* results : array with gunid strings
|
* results : array with gunid strings
|
||||||
* cnt : integer - number of matching gunids
|
* cnt : integer - number of matching gunids
|
||||||
* of files have been found
|
* of files have been found
|
||||||
|
@ -246,19 +301,26 @@ class DataEngine{
|
||||||
function localSearch($cri, $limit=0, $offset=0)
|
function localSearch($cri, $limit=0, $offset=0)
|
||||||
{
|
{
|
||||||
$res = $this->_localGenSearch($cri, $limit, $offset);
|
$res = $this->_localGenSearch($cri, $limit, $offset);
|
||||||
// if(PEAR::isError($res)) return $res;
|
// if (PEAR::isError($res)) return $res;
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search in local metadata database, more general version.
|
* Search in local metadata database, more general version.
|
||||||
*
|
*
|
||||||
* @param criteria hash, search criteria see DataEngine class documentation
|
* @param hash $criteria
|
||||||
* @param limit int, limit for result arrays (0 means unlimited)
|
* Search criteria see DataEngine class documentation
|
||||||
* @param offset int, starting point (0 means without offset)
|
* @param int $limit
|
||||||
* @param brFldNs string - namespace prefix of category for browse
|
* Limit for result arrays (0 means unlimited)
|
||||||
* @param brFld string, metadata category identifier for browse
|
* @param int $offset
|
||||||
* @return arrays of hashes, fields:
|
* Starting point (0 means without offset)
|
||||||
|
* @param string $brFldNs
|
||||||
|
* Namespace prefix of category for browse
|
||||||
|
* @param string $brFld
|
||||||
|
* Metadata category identifier for browse
|
||||||
|
* @return array
|
||||||
|
* arrays of hashes, fields:
|
||||||
* cnt : integer - number of matching gunids
|
* cnt : integer - number of matching gunids
|
||||||
* of files have been found
|
* of files have been found
|
||||||
* results : array of hashes:
|
* results : array of hashes:
|
||||||
|
@ -276,7 +338,7 @@ class DataEngine{
|
||||||
{
|
{
|
||||||
$filetype = (isset($criteria['filetype']) ? $criteria['filetype'] : 'all');
|
$filetype = (isset($criteria['filetype']) ? $criteria['filetype'] : 'all');
|
||||||
$filetype = strtolower($filetype);
|
$filetype = strtolower($filetype);
|
||||||
if(!array_key_exists($filetype, $this->filetypes)){
|
if (!array_key_exists($filetype, $this->filetypes)) {
|
||||||
return PEAR::raiseError(
|
return PEAR::raiseError(
|
||||||
'DataEngine::_localGenSearch: unknown filetype in search criteria'
|
'DataEngine::_localGenSearch: unknown filetype in search criteria'
|
||||||
);
|
);
|
||||||
|
@ -293,27 +355,27 @@ class DataEngine{
|
||||||
$obNs = $obSplitQn['namespace'];
|
$obNs = $obSplitQn['namespace'];
|
||||||
$orderby = $obSplitQn['localPart'];
|
$orderby = $obSplitQn['localPart'];
|
||||||
$browse = !is_null($brFld);
|
$browse = !is_null($brFld);
|
||||||
if(!$browse){
|
if (!$browse) {
|
||||||
if(!$orderby){
|
if (!$orderby) {
|
||||||
$fldsPart = "DISTINCT to_hex(f.gunid)as gunid, f.ftype, f.id";
|
$fldsPart = "DISTINCT to_hex(f.gunid)as gunid, f.ftype, f.id";
|
||||||
}else{
|
} else {
|
||||||
$fldsPart = "DISTINCT f.gunid, f.ftype, f.id";
|
$fldsPart = "DISTINCT f.gunid, f.ftype, f.id";
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$fldsPart = "DISTINCT br.object as txt";
|
$fldsPart = "DISTINCT br.object as txt";
|
||||||
}
|
}
|
||||||
$limitPart = ($limit != 0 ? " LIMIT $limit" : '' ).
|
$limitPart = ($limit != 0 ? " LIMIT $limit" : '' ).
|
||||||
($offset != 0 ? " OFFSET $offset" : '' );
|
($offset != 0 ? " OFFSET $offset" : '' );
|
||||||
$fileCond = "f.state='ready'";
|
$fileCond = "f.state='ready'";
|
||||||
if(!is_null($filetype)) $fileCond .= " AND f.ftype='$filetype'";
|
if (!is_null($filetype)) {
|
||||||
if($operator == 'and'){ // operator: and
|
$fileCond .= " AND f.ftype='$filetype'";
|
||||||
$sql = $this->_makeAndSql(
|
|
||||||
$fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
|
|
||||||
}else{ // operator: or
|
|
||||||
$sql = $this->_makeOrSql(
|
|
||||||
$fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
|
|
||||||
}
|
}
|
||||||
if(!$browse && $orderby){
|
if ($operator == 'and') { // operator: and
|
||||||
|
$sql = $this->_makeAndSql($fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
|
||||||
|
} else { // operator: or
|
||||||
|
$sql = $this->_makeOrSql($fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld);
|
||||||
|
}
|
||||||
|
if (!$browse && $orderby) {
|
||||||
$retype = ($orderby == 'mtime' ? '::timestamp with time zone' : '' );
|
$retype = ($orderby == 'mtime' ? '::timestamp with time zone' : '' );
|
||||||
$sql =
|
$sql =
|
||||||
"SELECT to_hex(sq2.gunid)as gunid, m.object, sq2.ftype, sq2.id\n".
|
"SELECT to_hex(sq2.gunid)as gunid, m.object, sq2.ftype, sq2.id\n".
|
||||||
|
@ -326,28 +388,42 @@ class DataEngine{
|
||||||
}
|
}
|
||||||
// echo "\n---\n$sql\n---\n";
|
// echo "\n---\n$sql\n---\n";
|
||||||
$cnt = $this->_getNumRows($sql);
|
$cnt = $this->_getNumRows($sql);
|
||||||
if(PEAR::isError($cnt)) return $cnt;
|
if (PEAR::isError($cnt)) {
|
||||||
|
return $cnt;
|
||||||
|
}
|
||||||
$res = $this->dbc->getAll($sql.$limitPart);
|
$res = $this->dbc->getAll($sql.$limitPart);
|
||||||
if(PEAR::isError($res)) return $res;
|
if (PEAR::isError($res)) {
|
||||||
if(!is_array($res)) $res = array();
|
return $res;
|
||||||
# if(!$browse){
|
}
|
||||||
|
if (!is_array($res)) {
|
||||||
|
$res = array();
|
||||||
|
}
|
||||||
|
# if (!$browse) {
|
||||||
# $res = array_map(array("StoredFile", "_normalizeGunid"), $res);
|
# $res = array_map(array("StoredFile", "_normalizeGunid"), $res);
|
||||||
# }
|
# }
|
||||||
$eres = array();
|
$eres = array();
|
||||||
foreach($res as $it){
|
foreach ($res as $it) {
|
||||||
if(!$browse){
|
if (!$browse) {
|
||||||
$gunid = StoredFile::_normalizeGunid($it['gunid']);
|
$gunid = StoredFile::_normalizeGunid($it['gunid']);
|
||||||
$titleA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:title');
|
$titleA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:title');
|
||||||
if(PEAR::isError($r)) return $r;
|
if (PEAR::isError($r)) {
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
$title = (isset($titleA[0]['value']) ? $titleA[0]['value'] : '');
|
$title = (isset($titleA[0]['value']) ? $titleA[0]['value'] : '');
|
||||||
$creatorA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:creator');
|
$creatorA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:creator');
|
||||||
if(PEAR::isError($r)) return $r;
|
if (PEAR::isError($r)) {
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
$creator = (isset($creatorA[0]['value']) ? $creatorA[0]['value'] : '');
|
$creator = (isset($creatorA[0]['value']) ? $creatorA[0]['value'] : '');
|
||||||
$sourceA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:source');
|
$sourceA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:source');
|
||||||
if(PEAR::isError($r)) return $r;
|
if (PEAR::isError($r)) {
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
$source = (isset($sourceA[0]['value']) ? $sourceA[0]['value'] : '');
|
$source = (isset($sourceA[0]['value']) ? $sourceA[0]['value'] : '');
|
||||||
$lengthA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dcterms:extent');
|
$lengthA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dcterms:extent');
|
||||||
if(PEAR::isError($r)) return $r;
|
if (PEAR::isError($r)) {
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
$length = (isset($lengthA[0]['value']) ? $lengthA[0]['value'] : '');
|
$length = (isset($lengthA[0]['value']) ? $lengthA[0]['value'] : '');
|
||||||
$eres[] = array(
|
$eres[] = array(
|
||||||
'gunid' => $gunid,
|
'gunid' => $gunid,
|
||||||
|
@ -357,22 +433,26 @@ class DataEngine{
|
||||||
'length' => $length,
|
'length' => $length,
|
||||||
'source' => $source,
|
'source' => $source,
|
||||||
);
|
);
|
||||||
}else{
|
} else {
|
||||||
$eres[] = $it['txt'];
|
$eres[] = $it['txt'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array('results'=>$eres, 'cnt'=>$cnt);
|
return array('results'=>$eres, 'cnt'=>$cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return values of specified metadata category
|
* Return values of specified metadata category
|
||||||
*
|
*
|
||||||
* @param category string, metadata category name
|
* @param string $category
|
||||||
* with or without namespace prefix (dc:title, author)
|
* metadata category name, with or without namespace prefix (dc:title, author)
|
||||||
* @param limit int, limit for result arrays (0 means unlimited)
|
* @param int $limit
|
||||||
* @param offset int, starting point (0 means without offset)
|
* limit for result arrays (0 means unlimited)
|
||||||
* @param criteria hash
|
* @param int $offset
|
||||||
* @return hash, fields:
|
* starting point (0 means without offset)
|
||||||
|
* @param array $criteria
|
||||||
|
* @return array
|
||||||
|
* hash, fields:
|
||||||
* results : array with found values
|
* results : array with found values
|
||||||
* cnt : integer - number of matching values
|
* cnt : integer - number of matching values
|
||||||
*/
|
*/
|
||||||
|
@ -382,11 +462,11 @@ class DataEngine{
|
||||||
$r = XML_Util::splitQualifiedName($category);
|
$r = XML_Util::splitQualifiedName($category);
|
||||||
$catNs = $r['namespace'];
|
$catNs = $r['namespace'];
|
||||||
$cat = $r['localPart'];
|
$cat = $r['localPart'];
|
||||||
if(is_array($criteria) && count($criteria)>0){
|
if (is_array($criteria) && count($criteria) > 0) {
|
||||||
return $this->_localGenSearch($criteria, $limit, $offset, $catNs, $cat);
|
return $this->_localGenSearch($criteria, $limit, $offset, $catNs, $cat);
|
||||||
}
|
}
|
||||||
$sqlCond = "m.predicate='$cat' AND m.objns='_L' AND m.predxml='T'";
|
$sqlCond = "m.predicate='$cat' AND m.objns='_L' AND m.predxml='T'";
|
||||||
if(!is_null($catNs)){
|
if (!is_null($catNs)) {
|
||||||
$sqlCond = "m.predns = '{$catNs}' AND $sqlCond";
|
$sqlCond = "m.predns = '{$catNs}' AND $sqlCond";
|
||||||
}
|
}
|
||||||
$limitPart = ($limit != 0 ? " LIMIT $limit" : '' ).
|
$limitPart = ($limit != 0 ? " LIMIT $limit" : '' ).
|
||||||
|
@ -396,29 +476,42 @@ class DataEngine{
|
||||||
"WHERE $sqlCond";
|
"WHERE $sqlCond";
|
||||||
// echo "\n---\n$sql\n---\n";
|
// echo "\n---\n$sql\n---\n";
|
||||||
$cnt = $this->_getNumRows($sql);
|
$cnt = $this->_getNumRows($sql);
|
||||||
if(PEAR::isError($cnt)) return $cnt;
|
if (PEAR::isError($cnt)) {
|
||||||
|
return $cnt;
|
||||||
|
}
|
||||||
$res = $this->dbc->getCol($sql.$limitPart);
|
$res = $this->dbc->getCol($sql.$limitPart);
|
||||||
if(PEAR::isError($res)) return $res;
|
if (PEAR::isError($res)) {
|
||||||
if(!is_array($res)) $res = array();
|
return $res;
|
||||||
|
}
|
||||||
|
if (!is_array($res)) {
|
||||||
|
$res = array();
|
||||||
|
}
|
||||||
return array('results'=>$res, 'cnt'=>$cnt);
|
return array('results'=>$res, 'cnt'=>$cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get number of rows in query result
|
* Get number of rows in query result
|
||||||
*
|
*
|
||||||
* @param query string, sql query
|
* @param string $query
|
||||||
* @return int, number of rows in query result
|
* SQL query
|
||||||
|
* @return int
|
||||||
|
* Number of rows in query result
|
||||||
*/
|
*/
|
||||||
function _getNumRows($query)
|
function _getNumRows($query)
|
||||||
{
|
{
|
||||||
$rh = $this->dbc->query($query);
|
$rh = $this->dbc->query($query);
|
||||||
if(PEAR::isError($rh)) return $rh;
|
if (PEAR::isError($rh)) {
|
||||||
|
return $rh;
|
||||||
|
}
|
||||||
$cnt = $rh->numRows();
|
$cnt = $rh->numRows();
|
||||||
if(PEAR::isError($cnt)) return $cnt;
|
if (PEAR::isError($cnt)) {
|
||||||
|
return $cnt;
|
||||||
|
}
|
||||||
$rh->free();
|
$rh->free();
|
||||||
return $cnt;
|
return $cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // class DataEngine
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue