From 012d344db2a2c6a1ea1fa54359df6aa21560fb99 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 21 Nov 2006 15:46:55 +0000 Subject: [PATCH] Added public/private status to functions. Changed _localGenSearch() to take advantage of new Greenbox::bsGetMetadataValue() function which allows you to pass an array of values to fetch. --- .../modules/storageServer/var/DataEngine.php | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/campcaster/src/modules/storageServer/var/DataEngine.php b/campcaster/src/modules/storageServer/var/DataEngine.php index d7ffd2beb..51fd2a657 100644 --- a/campcaster/src/modules/storageServer/var/DataEngine.php +++ b/campcaster/src/modules/storageServer/var/DataEngine.php @@ -1,7 +1,7 @@ "='%s'", 'partial'=>"like '%%%s%%'", 'prefix'=>"like '%s%%'", '<'=>"< '%s'", '='=>"= '%s'", @@ -148,7 +148,7 @@ class DataEngine { * @return string * query */ - function _makeAndSqlWoIntersect($fldsPart, $whereArr, $fileCond, $browse, + private function _makeAndSqlWoIntersect($fldsPart, $whereArr, $fileCond, $browse, $brFldNs=NULL, $brFld=NULL) { $innerBlocks = array(); @@ -200,7 +200,7 @@ class DataEngine { * @return string * query */ - function _makeAndSql($fldsPart, $whereArr, $fileCond, $browse, + private function _makeAndSql($fldsPart, $whereArr, $fileCond, $browse, $brFldNs=NULL, $brFld=NULL) { if (!USE_INTERSECT) { @@ -259,7 +259,7 @@ class DataEngine { * @return string * query */ - function _makeOrSql($fldsPart, $whereArr, $fileCond, $browse, + private function _makeOrSql($fldsPart, $whereArr, $fileCond, $browse, $brFldNs=NULL, $brFld=NULL) { //$whereArr[] = " FALSE\n"; @@ -309,7 +309,7 @@ class DataEngine { * cnt : integer - number of matching gunids * of files have been found */ - function localSearch($cri, $limit=0, $offset=0) + public function localSearch($cri, $limit=0, $offset=0) { $res = $this->_localGenSearch($cri, $limit, $offset); // if (PEAR::isError($res)) return $res; @@ -344,7 +344,7 @@ class DataEngine { * OR (in browse mode) * results: array of strings - browsed values */ - function _localGenSearch($criteria, $limit=0, $offset=0, + private function _localGenSearch($criteria, $limit=0, $offset=0, $brFldNs=NULL, $brFld=NULL) { $filetype = (isset($criteria['filetype']) ? $criteria['filetype'] : 'all'); @@ -359,9 +359,11 @@ class DataEngine { $operator = strtolower($operator); $conditions = (isset($criteria['conditions']) ? $criteria['conditions'] : array()); $whereArr = $this->_makeWhereArr($conditions); - $orderby = TRUE; // if there is any default - if ( (!isset($criteria['orderby'])) || (is_array($criteria['orderby']) && (count($criteria['orderby'])<1) ) ) { - $orderbyQns = array('dc:creator', 'dc:source', 'dc:title'); // default + $orderby = TRUE; + if ((!isset($criteria['orderby'])) + || (is_array($criteria['orderby']) && (count($criteria['orderby'])==0))) { + // default ORDER BY + $orderbyQns = array('dc:creator', 'dc:source', 'dc:title'); } else { $orderbyQns = $criteria['orderby']; } @@ -371,8 +373,8 @@ class DataEngine { $desc = (isset($criteria['desc']) ? $criteria['desc'] : NULL); $orderJoinSql = array(); $orderBySql = array(); - foreach($orderbyQns as $j=>$orderbyQn){ - $i = $j+1; + foreach ($orderbyQns as $j => $orderbyQn) { + $i = $j + 1; $obSplitQn = XML_Util::splitQualifiedName($orderbyQn); $obNs = $obSplitQn['namespace']; $obLp = $obSplitQn['localPart']; @@ -408,11 +410,10 @@ class DataEngine { $sql = $this->_makeOrSql($fldsPart, $whereArr, $fileCond, $browse, $brFldNs, $brFld); } if (!$browse && $orderby) { - $sql = - "SELECT to_hex(sq2.gunid)as gunid, m1.object, sq2.ftype, sq2.id\n". - "FROM (\n$sql\n)sq2\n". - join("\n", $orderJoinSql). - "ORDER BY ".join(",", $orderBySql)."\n"; + $sql = "SELECT to_hex(sq2.gunid)as gunid, m1.object, sq2.ftype, sq2.id\n". + "FROM (\n$sql\n)sq2\n". + join("\n", $orderJoinSql). + "ORDER BY ".join(",", $orderBySql)."\n"; } // echo "\n---\n$sql\n---\n"; $cnt = $this->_getNumRows($sql); @@ -428,36 +429,20 @@ class DataEngine { } $eres = array(); // echo "\n---\n"; var_dump($res); echo"\n---\n"; + $categoryNames = array('dc:title', 'dc:creator', 'dc:source', 'dcterms:extent'); foreach ($res as $it) { if (!$browse) { $gunid = StoredFile::_normalizeGunid($it['gunid']); - $titleA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:title'); - if (PEAR::isError($r)) { - return $r; - } - $title = (isset($titleA[0]['value']) ? $titleA[0]['value'] : ''); - $creatorA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:creator'); - if (PEAR::isError($r)) { - return $r; - } - $creator = (isset($creatorA[0]['value']) ? $creatorA[0]['value'] : ''); - $sourceA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dc:source'); - if (PEAR::isError($r)) { - return $r; - } - $source = (isset($sourceA[0]['value']) ? $sourceA[0]['value'] : ''); - $lengthA = $r = $this->gb->bsGetMetadataValue($it['id'], 'dcterms:extent'); - if (PEAR::isError($r)) { - return $r; - } - $length = (isset($lengthA[0]['value']) ? $lengthA[0]['value'] : ''); + $values = $this->gb->bsGetMetadataValue($it['id'], $categoryNames); $eres[] = array( + 'id' => $it['id'], 'gunid' => $gunid, 'type' => $it['ftype'], - 'title' => $title, - 'creator' => $creator, - 'length' => $length, - 'source' => $source, + 'title' => $values['dc:title'], + 'creator' => $values['dc:creator'], + 'duration' => $values['dcterms:extent'], + 'length' => $values['dcterms:extent'], + 'source' => $values['dc:source'], ); } else { $eres[] = $it['txt']; @@ -482,7 +467,7 @@ class DataEngine { * results : array with found values * cnt : integer - number of matching values */ - function browseCategory($category, $limit=0, $offset=0, $criteria=NULL) + public function browseCategory($category, $limit=0, $offset=0, $criteria=NULL) { //$category = strtolower($category); $r = XML_Util::splitQualifiedName($category); @@ -524,7 +509,7 @@ class DataEngine { * @return int * Number of rows in query result */ - function _getNumRows($query) + private function _getNumRows($query) { $rh = $this->dbc->query($query); if (PEAR::isError($rh)) {