From d2f43058c28ed84b35981a6b5796336d6866f097 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 12:09:28 -0400
Subject: [PATCH 01/11] fixed comment

---
 airtime_mvc/application/models/StoredFile.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index dd945d328..b0a0f4056 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -582,7 +582,7 @@ SQL;
     /**
      * Fetch the Application_Model_StoredFile by looking up its filepath.
      *
-     * @param  string                            $p_filepath path of file stored in Airtime.
+     * @param  string  $p_filepath path of file stored in Airtime.
      * @return Application_Model_StoredFile|NULL
      */
     public static function RecallByFilepath($p_filepath)

From a22ba39de10536852da894c3f62678d04fc64bfe Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 12:26:07 -0400
Subject: [PATCH 02/11] formatting

---
 airtime_mvc/application/models/StoredFile.php | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index b0a0f4056..1135084db 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -678,21 +678,21 @@ SQL;
                 $fileSelect[]   = $key;
                 $streamSelect[] = "NULL::NUMERIC AS ".$key;
             } elseif ($key === "lptime") {
-                $plSelect[] = "NULL::TIMESTAMP AS ".$key;
-                $blSelect[] = "NULL::TIMESTAMP AS ".$key;
-                $fileSelect[] = $key;
+                $plSelect[]     = "NULL::TIMESTAMP AS ".$key;
+                $blSelect[]     = "NULL::TIMESTAMP AS ".$key;
+                $fileSelect[]   = $key;
                 $streamSelect[] = $key;
             }
             //same columns in each table.
             else if (in_array($key, array("length", "utime", "mtime"))) {
-                $plSelect[] = $key;
-                $blSelect[] = $key;
-                $fileSelect[] = $key;
+                $plSelect[]     = $key;
+                $blSelect[]     = $key;
+                $fileSelect[]   = $key;
                 $streamSelect[] = $key;
             } elseif ($key === "year") {
-                $plSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
-                $blSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
-                $fileSelect[] = "year AS ".$key;
+                $plSelect[]     = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
+                $blSelect[]     = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
+                $fileSelect[]   = "year AS ".$key;
                 $streamSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
             }
             //need to cast certain data as ints for the union to search on.

From 6ac241b1fc787a72ad4c9a87682187ae7775b146 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 12:48:45 -0400
Subject: [PATCH 03/11] Added todo

---
 airtime_mvc/application/models/StoredFile.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index 1135084db..ac858e521 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -729,6 +729,7 @@ SQL;
         $unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS";
 
         //choose which table we need to select data from.
+        // TODO : use constants instead of numbers -- RG
         switch ($type) {
             case 0:
                 $fromTable = $unionTable;

From b069b1254e000b2a3607cd153c7eb85afb315e0d Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 12:56:01 -0400
Subject: [PATCH 04/11] Aligned

---
 airtime_mvc/application/models/StoredFile.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index ac858e521..d905b8e80 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -1182,11 +1182,11 @@ SQL;
         if (Application_Model_Preference::GetUploadToSoundcloudOption()) {
             for ($i=0; $i<$CC_CONFIG['soundcloud-connection-retries']; $i++) {
                 $description = $file->getDbTrackTitle();
-                $tag = array();
-                $genre = $file->getDbGenre();
-                $release = $file->getDbYear();
+                $tag         = array();
+                $genre       = $file->getDbGenre();
+                $release     = $file->getDbYear();
                 try {
-                    $soundcloud = new Application_Model_Soundcloud();
+                    $soundcloud     = new Application_Model_Soundcloud();
                     $soundcloud_res = $soundcloud->uploadTrack(
                         $this->getFilePath(), $this->getName(), $description,
                         $tag, $release, $genre);
@@ -1196,9 +1196,9 @@ SQL;
                     break;
                 } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
                     $code = $e->getHttpCode();
-                    $msg = $e->getHttpBody();
+                    $msg  = $e->getHttpBody();
                     $temp = explode('"error":',$msg);
-                    $msg = trim($temp[1], '"}');
+                    $msg  = trim($temp[1], '"}');
                     $this->setSoundCloudErrorCode($code);
                     $this->setSoundCloudErrorMsg($msg);
                     // setting sc id to -3 which indicates error

From 98f0692b8d569ec462fd63a9c9c523e618a29d25 Mon Sep 17 00:00:00 2001
From: James <james@sourcefabric-DX4840.(none)>
Date: Tue, 18 Sep 2012 14:40:18 -0400
Subject: [PATCH 05/11] CC-4457: Media Library: The background of 'Adding
 items' is minimize to a point

- fixed
---
 .../public/js/airtime/library/events/library_playlistbuilder.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js
index 751024e24..8c3239927 100644
--- a/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js
+++ b/airtime_mvc/public/js/airtime/library/events/library_playlistbuilder.js
@@ -64,7 +64,7 @@ var AIRTIME = (function(AIRTIME) {
                     helper : function() {
 
                         var $el = $(this), selected = mod
-                                .getChosenAudioFilesLength(), container, message, li = $("#side_playlist ul li:first"), width = li
+                                .getChosenAudioFilesLength(), container, message, li = $("#side_playlist ul[id='spl_sortable'] li:first"), width = li
                                 .width(), height = li.height();
 
                         // dragging an element that has an unselected

From 3a60d729fdc7ad4709212961292f61da01006311 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 15:02:07 -0400
Subject: [PATCH 06/11] added todo

---
 airtime_mvc/application/models/StoredFile.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index d905b8e80..22b7a431e 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -1197,6 +1197,7 @@ SQL;
                 } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
                     $code = $e->getHttpCode();
                     $msg  = $e->getHttpBody();
+                    // TODO : Do not parse JSON by hand
                     $temp = explode('"error":',$msg);
                     $msg  = trim($temp[1], '"}');
                     $this->setSoundCloudErrorCode($code);

From 2cfb0c85d5c0b43cb5a1466113c4a4aaf12b577b Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 15:04:22 -0400
Subject: [PATCH 07/11] Formatted sql

---
 airtime_mvc/application/models/StoredFile.php | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index 22b7a431e..deada4d38 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -1057,12 +1057,14 @@ SQL;
     {
         $con = Propel::getConnection();
 
-        $sql = "SELECT id, filepath as fp"
-                ." FROM CC_FILES"
-                ." WHERE directory = :dir_id"
-                ." AND file_exists = 'TRUE'"
-                ." AND replay_gain is NULL"
-                ." LIMIT :lim";
+        $sql = <<<SQL
+SELECT id,
+       filepath AS fp
+FROM cc_files
+WHERE directory = :dir_id
+  AND file_exists = 'TRUE'
+  AND replay_gain IS NULL LIMIT :lim
+SQL;
 
         $stmt = $con->prepare($sql);
         $stmt->bindParam(':dir_id', $dir_id);
@@ -1171,6 +1173,8 @@ SQL;
         return $this->_file->getDbFileExists();
     }
 
+
+    // note: never call this method from controllers because it does a sleep
     public function uploadToSoundCloud()
     {
         global $CC_CONFIG;

From 66aee1a01b91ea1727b5a3d7d45b5234a43081b2 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 15:13:39 -0400
Subject: [PATCH 08/11] Added TODO

---
 python_apps/media-monitor2/media/monitor/organizer.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py
index 7bead4e21..713bd2156 100644
--- a/python_apps/media-monitor2/media/monitor/organizer.py
+++ b/python_apps/media-monitor2/media/monitor/organizer.py
@@ -66,6 +66,7 @@ class Organizer(ReportHandler,Loggable):
 
             # See hack in mmp.magic_move
             def new_dir_watch(d):
+                # TODO : rewrite as return lambda : dispatcher.send(...
                 def cb():
                     dispatcher.send(signal="add_subwatch", sender=self,
                             directory=d)

From 7bbd10556b9f3f9a2ba7006991b0310b5ecb7847 Mon Sep 17 00:00:00 2001
From: denise <denise@denise-DX4860sourcefabric.org>
Date: Tue, 18 Sep 2012 15:14:46 -0400
Subject: [PATCH 09/11] CC-4465: Calendar: Remove warning icon on empty shows
 if show is in the past

-done
---
 .../schedule/full-calendar-functions.js       | 73 ++++++++++++++-----
 1 file changed, 54 insertions(+), 19 deletions(-)

diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js
index 88435c84e..281e904f9 100644
--- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js
+++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js
@@ -255,28 +255,31 @@ function eventRender(event, element, view) {
     }
     
     //add scheduled show content empty icon
-    if (view.name === 'agendaDay' || view.name === 'agendaWeek') {
-        if (event.show_empty === 1 && event.record === 0 && event.rebroadcast === 0) {
-            if (event.soundcloud_id === -1) {
-                $(element).find(".fc-event-time").before('<span id="'+event.id+'" class="small-icon show-empty"></span>');
-            } else if (event.soundcloud_id > 0) {
-                
-            } else if (event.soundcloud_id === -2) {
-            
-            } else if (event.soundcloud_id === -3) {
+    addIcon = checkEmptyShowStatus(event);
+    if (!addIcon) {
+        if (view.name === 'agendaDay' || view.name === 'agendaWeek') {
+            if (event.show_empty === 1 && event.record === 0 && event.rebroadcast === 0) {
+                if (event.soundcloud_id === -1) {
+                    $(element).find(".fc-event-time").before('<span id="'+event.id+'" class="small-icon show-empty"></span>');
+                } else if (event.soundcloud_id > 0) {
+                    
+                } else if (event.soundcloud_id === -2) {
                 
+                } else if (event.soundcloud_id === -3) {
+                    
+                }
             }
-        }
-    } else if (view.name === 'month') {
-        if (event.show_empty === 1 && event.record === 0 && event.rebroadcast === 0) {
-            if (event.soundcloud_id === -1) {
-                $(element).find(".fc-event-title").after('<span id="'+event.id+'" class="small-icon show-empty"></span>');
-            } else if (event.soundcloud_id > 0) {
-                
-            } else if (event.soundcloud_id === -2) {
-            
-            } else if (event.soundcloud_id === -3) {
+        } else if (view.name === 'month') {
+            if (event.show_empty === 1 && event.record === 0 && event.rebroadcast === 0) {
+                if (event.soundcloud_id === -1) {
+                    $(element).find(".fc-event-title").after('<span id="'+event.id+'" class="small-icon show-empty"></span>');
+                } else if (event.soundcloud_id > 0) {
+                    
+                } else if (event.soundcloud_id === -2) {
                 
+                } else if (event.soundcloud_id === -3) {
+                    
+                }
             }
         }
     }
@@ -416,6 +419,7 @@ function getCurrentShow(){
 
 function addQtipToSCIcons(ele){
     var id = $(ele).attr("id");
+    console.log(ele);
     if($(ele).hasClass("progress")){
         $(ele).qtip({
             content: {
@@ -508,6 +512,36 @@ function addQtipToSCIcons(ele){
     }
 }
 
+/* This functions does two things:
+ * 1. Checks if each event(i.e. a show) is over and removes the show empty icon if it is
+ * 2. Else, if an event is passed in, it checks if the event(i.e. a show) is over
+ *    This gets checked when we are deciding if the show-empty icon should be added
+ *    at the beginning of an event render callback.
+ */
+function checkEmptyShowStatus(e) {
+    var currDate = new Date();
+    var endTime;
+    
+    if (e === undefined) {
+        var events = $('#schedule_calendar').fullCalendar('clientEvents');
+        
+        $.each(events, function(i, event){
+            endTime = event.end;
+            $emptyIcon = $("span[id="+event.id+"][class='small-icon show-empty']");
+            if (currDate.getTime() > endTime.getTime() && $emptyIcon.length === 1) {
+                $emptyIcon.remove();
+            }
+        });
+    } else {
+        endTime = e.end;
+        var showOver = false;
+        if (currDate.getTime() > endTime.getTime()) {
+            showOver = true;
+        }
+        return showOver;
+    }
+}
+
 //Alert the error and reload the page
 //this function is used to resolve concurrency issue
 function alertShowErrorAndReload(){
@@ -518,6 +552,7 @@ function alertShowErrorAndReload(){
 $(document).ready(function(){
     setInterval( "checkSCUploadStatus()", 5000 );
     setInterval( "getCurrentShow()", 5000 );
+    setInterval( "checkEmptyShowStatus()", 5000 );
 });
 
 var view_name;

From e676cf856f973e5d760a890658545229edfadbc6 Mon Sep 17 00:00:00 2001
From: denise <denise@denise-DX4860sourcefabric.org>
Date: Tue, 18 Sep 2012 15:16:54 -0400
Subject: [PATCH 10/11] -remove console.log

---
 .../public/js/airtime/schedule/full-calendar-functions.js       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js
index 281e904f9..5e95a31c8 100644
--- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js
+++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js
@@ -419,7 +419,7 @@ function getCurrentShow(){
 
 function addQtipToSCIcons(ele){
     var id = $(ele).attr("id");
-    console.log(ele);
+
     if($(ele).hasClass("progress")){
         $(ele).qtip({
             content: {

From 72e6ee35fa1589dc11580e5853546e08a852ebc9 Mon Sep 17 00:00:00 2001
From: Rudi Grinberg <rudi.grinberg@sourcefabric.org>
Date: Tue, 18 Sep 2012 15:26:43 -0400
Subject: [PATCH 11/11] cc-4304: Temporarily fixed

---
 .../controllers/UserController.php            |  9 +++++---
 airtime_mvc/application/models/User.php       | 21 +++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/airtime_mvc/application/controllers/UserController.php b/airtime_mvc/application/controllers/UserController.php
index 1ee54fe39..40415b760 100644
--- a/airtime_mvc/application/controllers/UserController.php
+++ b/airtime_mvc/application/controllers/UserController.php
@@ -109,7 +109,7 @@ class UserController extends Zend_Controller_Action
         # TODO : remove this. we only use default for now not to break the UI.
         if (!$files_action) { # set default action
             $files_action = "reassign_to";
-            $delId = 1;
+            $new_owner    = Application_Model_User::getFirstAdmin();
         }
 
         # only delete when valid action is selected for the owned files
@@ -132,8 +132,11 @@ class UserController extends Zend_Controller_Action
         if ($files_action == "delete_cascade") {
             $user->deleteAllFiles();
         } elseif ($files_action == "reassign_to") {
-            $new_owner = $this->_getParam("new_owner");
-            $user->reassignTo( $new_owner );
+            // TODO : fix code to actually use the line below and pick a
+            // real owner instead of defaulting to the first found admin
+            //$new_owner_id = $this->_getParam("new_owner");
+            //$new_owner    = new Application_Model_User($new_owner_id);
+            $user->donateFilesTo( $new_owner );
         }
         # Finally delete the user
         $this->view->entries = $user->delete();
diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php
index 1d9d94e07..326e04940 100644
--- a/airtime_mvc/application/models/User.php
+++ b/airtime_mvc/application/models/User.php
@@ -215,7 +215,7 @@ class Application_Model_User
         return $user->getCcFilessRelatedByDbOwnerId();
     }
 
-    public function donateFilesTo($user)
+    public function donateFilesTo($user) // $user is object not user id
     {
         $my_files = $this->getOwnedFiles();
         foreach ($my_files as $file) {
@@ -242,18 +242,27 @@ class Application_Model_User
     {
         return CcSubjsQuery::create()->filterByDbType($type)->find();
     }
-    public static function getFirstAdminId()
-    {
+
+    public static function getFirstAdmin() {
         $admins = Application_Model_User::getUsersOfType('A');
         if (count($admins) > 0) { // found admin => pick first one
-
-            return $admins[0]->getDbId();
+            return $admins[0];
         } else {
             Logging::warn("Warning. no admins found in database");
-
             return null;
         }
     }
+
+    public static function getFirstAdminId()
+    {
+        $admin = self::getFirstAdmin();
+        if ($admin) { 
+            return $admin->getDbId();
+        } else {
+            return null;
+        }
+    }
+
     public static function getUsers(array $type, $search=null)
     {
         $con     = Propel::getConnection();