From b2a490ac470de47652d24f1431c5b8f8ee64dab9 Mon Sep 17 00:00:00 2001
From: Naomi <naomiaro@gmail.com>
Date: Mon, 29 Apr 2013 18:09:12 -0400
Subject: [PATCH] CC-2301 : working on creating a crossfade method for
 waveforms.

---
 .../controllers/PlaylistController.php        | 27 ++++++++++++++++
 airtime_mvc/application/models/Playlist.php   | 31 +++++++++++++++++--
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php
index 3f0dd66b7..ab42823e7 100644
--- a/airtime_mvc/application/controllers/PlaylistController.php
+++ b/airtime_mvc/application/controllers/PlaylistController.php
@@ -417,6 +417,33 @@ class PlaylistController extends Zend_Controller_Action
             $this->playlistUnknownError($e);
         }
     }
+    
+    public function setCrossFadeAction()
+    {
+    	$id = $this->_getParam('id');
+    	$fadeIn = $this->_getParam('fadeIn', 0);
+    	$fadeOut = $this->_getParam('fadeOut', 0);
+    	$type = $this->_getParam('type');
+    	$offset = $this->_getParam('offset', 0);
+    
+    	try {
+    		$obj = $this->getPlaylist($type);
+    		$response = $obj->changeFadeInfo($id, $fadeIn, $fadeOut);
+    
+    		if (!isset($response["error"])) {
+    			$this->createUpdateResponse($obj);
+    			$this->view->response = $response;
+    		} else {
+    			$this->view->fade_error = $response["error"];
+    		}
+    	} catch (PlaylistOutDatedException $e) {
+    		$this->playlistOutdated($e);
+    	} catch (PlaylistNotFoundException $e) {
+    		$this->playlistNotFound($type);
+    	} catch (Exception $e) {
+    		$this->playlistUnknownError($e);
+    	}
+    }
 
     public function getPlaylistFadesAction()
     {
diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php
index 764a8695c..e5610ec4f 100644
--- a/airtime_mvc/application/models/Playlist.php
+++ b/airtime_mvc/application/models/Playlist.php
@@ -645,12 +645,39 @@ SQL;
 
         return array($fadeIn, $fadeOut);
     }
+    
+    /*
+     * create a crossfade from item in cc_playlist_contents with $id1 to item $id2.
+     * 
+     * $fadeOut length of fade out in seconds if $id1
+     * $fadeIn length of fade in in seconds of $id2
+     * $offset time in seconds from end of $id1 that $id2 will begin to play.
+     */
+    public function createCrossfade($id1, $id2, $fadeIn, $fadeOut, $offset)
+    {
+    	$this->con->beginTransaction();
+    	
+    	try {
+    		$this->changeFadeInfo($id1, null, $fadeOut);
+    		$this->changeFadeInfo($id2, $fadeIn, null);
+    		
+    		$item = CcPlaylistcontentsQuery::create()->findPK($id2);
+    		$item->setDbOffset($offset);
+    		$item->save($this->con);
+    		
+    		$this->con->commit();
+    		
+    	} catch (Exception $e) {
+            $this->con->rollback();
+            throw $e;
+        }	
+    }
 
     /**
      * Change fadeIn and fadeOut values for playlist Element
      *
-     * @param int $pos
-     *         position of audioclip in playlist
+     * @param int $id
+     *         id of audioclip in playlist contents table.
      * @param string $fadeIn
      *         new value in ss.ssssss or extent format
      * @param string $fadeOut