From 61e38381afb43b969b738626dc9d0703f9cc88a7 Mon Sep 17 00:00:00 2001
From: James <james@sourcefabric-DX4840.(none)>
Date: Wed, 8 Aug 2012 11:46:48 -0400
Subject: [PATCH] CC-4176: Smart Playlist: Set implicit item limit when user
 uses time as a limit

- done
---
 airtime_mvc/application/models/Block.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php
index 5ff84a3d1..05459ee04 100644
--- a/airtime_mvc/application/models/Block.php
+++ b/airtime_mvc/application/models/Block.php
@@ -1211,6 +1211,7 @@ EOT;
     
         $insertList = array();
         $totalTime = 0;
+        $totalItems = 0;
     
         // this moves the pointer to the first element in the collection
         $files->getFirst();
@@ -1220,7 +1221,9 @@ EOT;
             $length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
             $insertList[$id] = $length;
             $totalTime += $length;
-            if ( !is_null($limit['items']) && $limit['items'] == count($insertList)) {
+            $totalItems++;
+            
+            if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500) {
                 break;
             }