From 7590bbaa495b341101f85ff1099de66a5333e44a Mon Sep 17 00:00:00 2001
From: tomas <tomas@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Mon, 7 Feb 2005 23:14:51 +0000
Subject: [PATCH] Method for update one metadata value added, method for return
 one metadata value modified.

---
 .../modules/storageServer/var/BasicStor.php   | 35 +++++++++++++++----
 .../modules/storageServer/var/GreenBox.php    | 35 ++++++++++++++++---
 2 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php
index e850c5ba3..3173fe762 100644
--- a/livesupport/modules/storageServer/var/BasicStor.php
+++ b/livesupport/modules/storageServer/var/BasicStor.php
@@ -23,7 +23,7 @@
  
  
     Author   : $Author: tomas $
-    Version  : $Revision: 1.25 $
+    Version  : $Revision: 1.26 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $
 
 ------------------------------------------------------------------------------*/
@@ -52,7 +52,7 @@ require_once "Transport.php";
  *  Core of LiveSupport file storage module
  *
  *  @author  $Author: tomas $
- *  @version $Revision: 1.25 $
+ *  @version $Revision: 1.26 $
  *  @see Alib
  */
 class BasicStor extends Alib{
@@ -602,15 +602,36 @@ class BasicStor extends Alib{
      *
      *  @param id int, virt.file's local id
      *  @param category string, metadata element name
-     *  @return array of matching records
+     *  @param lang string, optional xml:lang value for select language version
+     *  @return array of matching records (as hash {id, value, attrs})
+     *  @see Metadata::getMetadataValue
      */
-    function bsGetMetadataValue($id, $category)
+    function bsGetMetadataValue($id, $category, $lang=NULL)
     {   
-        require_once "DataEngine.php";
-        $de =& new DataEngine($this);
-        return $de->getMetadataValue($id, $category);
+        $ac =& StoredFile::recall($this, $id);
+        return $ac->md->getMetadataValue($category, $lang);
     }
     
+    /**
+     *  Set metadata element value
+     *
+     *  @param id int, virt.file's local id
+     *  @param category string, metadata element identification (e.g. dc:title)
+     *  @param value string/NULL value to store, if NULL then delete record
+     *  @param lang string, optional xml:lang value for select language version
+     *  @param mid int, metadata record id (OPTIONAL on unique elements)
+     *  @return boolean
+     */
+    function bsSetMetadataValue($id, $category, $value, $lang=NULL, $mid=NULL)
+    {
+        $ac =& StoredFile::recall($this, $id);
+        $res = $ac->md->setMetadataValue($category, $value, $lang, $mid);
+        if(PEAR::isError($res)) return $res;
+        $r = $ac->md->regenerateXmlFile();
+        if(PEAR::isError($r)) return $r;
+        return $res;
+    }
+
     /**
      *  Search in local metadata database.
      *
diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php
index a83d6b6eb..332bd4444 100644
--- a/livesupport/modules/storageServer/var/GreenBox.php
+++ b/livesupport/modules/storageServer/var/GreenBox.php
@@ -23,7 +23,7 @@
  
  
     Author   : $Author: tomas $
-    Version  : $Revision: 1.28 $
+    Version  : $Revision: 1.29 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
 
 ------------------------------------------------------------------------------*/
@@ -35,7 +35,7 @@ require_once "BasicStor.php";
  *  LiveSupport file storage module
  *
  *  @author  $Author: tomas $
- *  @version $Revision: 1.28 $
+ *  @version $Revision: 1.29 $
  *  @see BasicStor
  */
 class GreenBox extends BasicStor{
@@ -232,13 +232,38 @@ class GreenBox extends BasicStor{
      *  @param id int, virt.file's local id
      *  @param category string, metadata element name
      *  @param sessid string, session id
-     *  @return array of matching records
+     *  @param lang string, optional xml:lang value for select language version
+     *  @return array of matching records as hash with fields:
+     *   <ul>
+     *      <li>mid int, local metadata record id</li>
+     *      <li>value string, element value</li>
+     *      <li>attrs hasharray of element's attributes indexed by
+     *          qualified name (e.g. xml:lang)</li>
+     *   </ul>
      */
-    function getMdataValue($id, $category, $sessid='')
+    function getMdataValue($id, $category, $sessid='', $lang=NULL)
     {
         if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
             return $res;
-        return $this->bsGetMetadataValue($id, $category);
+        return $this->bsGetMetadataValue($id, $category, $lang);
+    }
+
+    /**
+     *  Set metadata element value
+     *
+     *  @param id int, virt.file's local id
+     *  @param category string, metadata element identification (e.g. dc:title)
+     *  @param sessid string, session id
+     *  @param value string/NULL value to store, if NULL then delete record
+     *  @param lang string, optional xml:lang value for select language version
+     *  @param mid int, metadata record id (OPTIONAL on unique elements)
+     *  @return boolean
+     */
+    function setMdataValue($id, $category, $sessid='', $value, $lang=NULL, $mid=NULL)
+    {
+        if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE)
+            return $res;
+        return $this->bsSetMetadataValue($id, $category, $value, $lang, $mid);
     }
 
     /**