Renamed the function getMetadataValue() to getMetadataValueWithAttrs() - this function actually isnt used anywhere. Created a new getMetadataValue() which just returns the value you are looking for without any extra stuff.

This commit is contained in:
paul 2006-11-21 15:55:39 +00:00
parent b5f2262b0a
commit 716b1d3a8c
1 changed files with 28 additions and 13 deletions

View File

@ -209,8 +209,9 @@ class MetaData {
* metadata element name * metadata element name
* @param int $parid * @param int $parid
* metadata record id of parent element * metadata record id of parent element
* @return hash * @return array
* {mid: int - record id, value: metadata alue} * int 'mid': record id
* string 'value': metadata value}
*/ */
function getMetadataEl($category, $parid=NULL) function getMetadataEl($category, $parid=NULL)
{ {
@ -228,12 +229,10 @@ class MetaData {
if (!is_null($parid)) { if (!is_null($parid)) {
$cond .= " AND subjns='_I' AND subject='$parid'"; $cond .= " AND subjns='_I' AND subject='$parid'";
} }
$sql = " $sql = "SELECT id as mid, object as value
SELECT id as mid, object as value FROM {$this->mdataTable}
FROM {$this->mdataTable} WHERE $cond
WHERE $cond ORDER BY id";
ORDER BY id
";
$all = $this->dbc->getAll($sql); $all = $this->dbc->getAll($sql);
foreach ($all as $i => $v) { foreach ($all as $i => $v) {
if (is_null($all[$i]['value'])) { if (is_null($all[$i]['value'])) {
@ -371,7 +370,7 @@ class MetaData {
* </ul> * </ul>
* @see BasicStor::bsGetMetadataValue * @see BasicStor::bsGetMetadataValue
*/ */
function getMetadataValue($category, $lang=NULL, $deflang=NULL, $objns='_L') function getMetadataValueWithAttrs($category, $lang=NULL, $deflang=NULL, $objns='_L')
{ {
$all = $this->getMetadataEl($category); $all = $this->getMetadataEl($category);
$res = array(); $res = array();
@ -400,7 +399,7 @@ class MetaData {
break; break;
case strtolower($deflang): case strtolower($deflang):
$def = array($all[$i]); $def = array($all[$i]);
break; break;
} }
} }
} }
@ -417,6 +416,22 @@ class MetaData {
} }
/**
* Get metadata element value.
*
* @param string $category
* metadata element name
* @return string
* If the value doesnt exist, return the empty string.
*/
function getMetadataValue($category)
{
$element = $this->getMetadataEl($category);
$value = (isset($element[0]['value']) ? $element[0]['value'] : '');
return $value;
}
/** /**
* Set metadata element value * Set metadata element value
* *
@ -435,7 +450,7 @@ class MetaData {
function setMetadataValue($category, $value, $lang=NULL, $mid=NULL, function setMetadataValue($category, $value, $lang=NULL, $mid=NULL,
$container='metadata') $container='metadata')
{ {
// resolve aktual element: // resolve actual element:
$rows = $this->getMetadataValue($category, $lang); $rows = $this->getMetadataValue($category, $lang);
$aktual = NULL; $aktual = NULL;
if (count($rows) > 1) { if (count($rows) > 1) {
@ -444,7 +459,7 @@ class MetaData {
$aktual = array_pop($rows); $aktual = array_pop($rows);
} else { } else {
return PEAR::raiseError( return PEAR::raiseError(
"MetaData::setMdataValue:". "MetaData::setMetadataValue:".
" nonunique category, mid required" " nonunique category, mid required"
); );
} }
@ -492,7 +507,7 @@ class MetaData {
$parid = $contArr[0]['mid']; $parid = $contArr[0]['mid'];
if (is_null($parid)) { if (is_null($parid)) {
return PEAR::raiseError( return PEAR::raiseError(
"MetaData::setMdataValue: container ($container) not found" "MetaData::setMetadataValue: container ($container) not found"
); );
} }
$nid = $this->insertMetadataEl($parid, $category, $value); $nid = $this->insertMetadataEl($parid, $category, $value);