From 4a83ede603c60c7cfd8150b3fe2f5b86880e1141 Mon Sep 17 00:00:00 2001
From: tomas <tomas@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Wed, 9 Mar 2005 02:55:31 +0000
Subject: [PATCH] moveAudioClipInPlaylist method added to GreenBox.

---
 .../modules/storageServer/var/GreenBox.php    | 41 ++++++++++++--
 .../modules/storageServer/var/Playlist.php    | 55 ++++++++++++++++---
 2 files changed, 81 insertions(+), 15 deletions(-)

diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php
index 69c84fa6e..6f421797b 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.52 $
+    Version  : $Revision: 1.53 $
     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.52 $
+ *  @version $Revision: 1.53 $
  *  @see BasicStor
  */
 class GreenBox extends BasicStor{
@@ -506,6 +506,9 @@ class GreenBox extends BasicStor{
         }
         $res = $pl->addAudioClip($acId, $fadeIn, $fadeOut);
         if(PEAR::isError($res)) return $res;
+        // recalculate offsets and total length:
+        $r = $pl->recalculateTimes();
+        if(PEAR::isError($r)){ return $r; }
         return $res;
     }
 
@@ -513,9 +516,7 @@ class GreenBox extends BasicStor{
      *  Remove audioclip from playlist
      *
      *  @param token string, playlist access token
-     *  <span style="color:green">
      *  @param plElGunid string, global id of deleted playlistElement
-     *  </span>
      *  @param sessid string, session ID
      *  @return boolean
      */
@@ -526,11 +527,14 @@ class GreenBox extends BasicStor{
         if(PEAR::isError($pl)) return $pl;
         $res = $pl->delAudioClip($plElGunid);
         if(PEAR::isError($res)) return $res;
+        // recalculate offsets and total length:
+        $r = $pl->recalculateTimes();
+        if(PEAR::isError($r)){ return $r; }
         return $res;
     }
 
     /**
-     *  <span style="color:red">Change fadInfo values</span>
+     *  Change fadeInfo values
      *
      *  @param token string, playlist access token
      *  @param plElGunid string, global id of deleted playlistElement
@@ -546,7 +550,32 @@ class GreenBox extends BasicStor{
         if(PEAR::isError($pl)) return $pl;
         $res = $pl->changeFadeInfo($plElGunid, $fadeIn, $fadeOut);
         if(PEAR::isError($res)) return $res;
-        return $res;
+        // recalculate offsets and total length:
+        $r = $pl->recalculateTimes();
+        if(PEAR::isError($r)){ return $r; }
+        return TRUE;
+    }
+
+    /**
+     *  <span style="color:green">Move audioClip to the new position in the playlist</span>
+     *
+     *  @param token string, playlist access token
+     *  @param plElGunid string, global id of deleted playlistElement
+     *  @param newPos int - new position in playlist
+     *  @param sessid string, session ID
+     *  @return boolean
+     */
+    function moveAudioClipInPlaylist($token, $plElGunid, $newPos, $sessid)
+    {
+        require_once"Playlist.php";
+        $pl =& Playlist::recallByToken($this, $token);
+        if(PEAR::isError($pl)) return $pl;
+        $res = $pl->moveAudioClip($plElGunid, $newPos);
+        if(PEAR::isError($res)) return $res;
+        // recalculate offsets and total length:
+        $r = $pl->recalculateTimes();
+        if(PEAR::isError($r)){ return $r; }
+        return TRUE;
     }
 
     /**
diff --git a/livesupport/modules/storageServer/var/Playlist.php b/livesupport/modules/storageServer/var/Playlist.php
index d17724dc2..0ca09cd33 100644
--- a/livesupport/modules/storageServer/var/Playlist.php
+++ b/livesupport/modules/storageServer/var/Playlist.php
@@ -23,7 +23,7 @@
  
  
     Author   : $Author: tomas $
-    Version  : $Revision: 1.5 $
+    Version  : $Revision: 1.6 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Playlist.php,v $
 
 ------------------------------------------------------------------------------*/
@@ -303,9 +303,6 @@ class Playlist extends StoredFile{
         $r = $this->md->insertMetadataEl($acId, 'accessToken', $acToken, 'A');
         if(PEAR::isError($r)){ return $r; }
         */
-        // recalculate offsets and total length:
-        $r = $this->recalculateTimes();
-        if(PEAR::isError($r)){ return $r; }
         return $plElGunid;
     }
 
@@ -361,9 +358,6 @@ class Playlist extends StoredFile{
                 " ($plElGunid)"
             );
         }
-        // recalculate offsets and total length:
-        $r = $this->recalculateTimes();
-        if(PEAR::isError($r)){ return $r; }
         return TRUE;
     }
     
@@ -409,8 +403,51 @@ class Playlist extends StoredFile{
                 $fadeOutId, $fadeOut, $fiMid, 'fadeOut');
             if(PEAR::isError($r)){ return $r; }
         }
-        $r = $this->recalculateTimes();
-        if(PEAR::isError($r)){ return $r; }
+        return TRUE;
+    }
+    
+    /**
+     *  Move audioClip to the new position in the playlist
+     *
+     *  @param plElGunid string - playlistElement gunid
+     *  @param newPos int - new position in playlist
+     *  @return
+     */
+    function moveAudioClip($plElGunid, $newPos)
+    {
+        $plGunid = $this->gunid;
+        $arr = $this->md->genPhpArray();
+        $els =& $arr['children'];
+        foreach($els as $i=>$el){
+            if($el['elementname'] != 'playlistelement'){
+                $metadata = array_splice($els, $i, 1);
+                continue;
+            }
+        }
+        foreach($els as $i=>$el){
+            if($el['attrs']['id'] == $plElGunid){
+                $movedi = $i;
+            }
+            $r = $this->delAudioClip($el['attrs']['id']);
+            if(PEAR::isError($r)){ return $r; }
+        }
+        $movedel = array_splice($els, $movedi, 1);
+        array_splice($els, $newPos, 0, $movedel);
+//        var_dump($els);
+        foreach($els as $i=>$el){
+            foreach($el['children'] as $j=>$af){
+                if($af['elementname'] == 'audioclip'){
+                    $acGunid = $af['attrs']['id'];
+                }elseif($af['elementname'] == 'fadeinfo'){
+                    $fadeIn = $af['attrs']['fadein'];
+                    $fadeOut = $af['attrs']['fadeout'];
+                }else{
+                }
+            }
+            $acId = $this->gb->_idFromGunid($acGunid);
+            $r = $this->addAudioClip($acId, $fadeIn, $fadeOut);
+            if(PEAR::isError($r)){ return $r; }
+        }
         return TRUE;
     }