diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index e5972aadc..43103edf9 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -199,7 +199,6 @@ class PlaylistController extends Zend_Controller_Action $this->view->form = $form; } } - $formatter = new LengthFormatter($obj->getLength()); $this->view->length = $formatter->format(); $this->view->type = $this->obj_sess->type; diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 884c387b7..8d5cd2290 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -242,10 +242,20 @@ EOT; return $fade; } - //aggregate column on blockcontents cliplength column. + // function return "N/A" if dynamic public function getLength() { - return $this->block->getDbLength(); + $length = $this->block->getDbLength(); + $length = $length == null ? "N/A" : $length; + return $length; + } + + // + public function getStaticLength(){ + $sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}"; + $r = $this->con->query($sql); + $result = $r->fetchAll(PDO::FETCH_NUM); + return $result[0][0]; } private function insertBlockElement($info) @@ -849,6 +859,12 @@ EOT; CcBlockQuery::create()->findPk($this->id)->setDbType($p_blockType)->save(); } + public function setLength($value){ + $this->block->setDbLength($value); + $this->block->save($this->con); + } + + /** * Saves smart block criteria * @param array $p_criteria @@ -1004,14 +1020,26 @@ EOT; }//for loop $result = count($errors) > 0 ? 1 :0; + $files["count"] = 0; + $output = array("result"=>$result, "errors"=>$errors); if ($result == 0) { $this->storeCriteriaIntoDb($data); + //get number of files that meet the criteria + $files = $this->getListofFilesMeetCriteria(); + $output['poolCount'] = $files["count"]; + // if the block is dynamic, put null to the length + // as it cannot be calculated + if ($blockType == 'dynamic') { + $this->setLength(null); + $output['blockLength'] = "N/A"; + } else { + $length = $this->getStaticLength(); + $this->setLength($length); + $formatter = new LengthFormatter($length); + $output['blockLength'] = $formatter->format(); + } } - - //get number of files that meet the criteria - $files = $this->getListofFilesMeetCriteria(); - - return array("result"=>$result, "errors"=>$errors, "poolCount"=>$files["count"]); + return $output; } public function storeCriteriaIntoDb($p_criteriaData){ @@ -1071,6 +1099,15 @@ EOT; $insertList = $this->getListOfFilesUnderLimit(); $this->deleteAllFilesFromBlock(); $this->addAudioClips(array_keys($insertList)); + // update length in playlist contents. + $blocks = CcPlaylistcontentsQuery::create()->filterByDbBlockId($this->id)->find(); + $blocks->getFirst(); + $iterator = $blocks->getIterator(); + while ($iterator->valid()) { + $iterator->current()->setDbClipLength($this->getLength()); + $iterator->current()->save(); + $iterator->next(); + } return array("result"=>0); } } diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php index 3e588a112..545b08cbb 100644 --- a/airtime_mvc/application/models/Datatables.php +++ b/airtime_mvc/application/models/Datatables.php @@ -87,6 +87,14 @@ class Application_Model_Datatables $r = $con->query($sql); $r->setFetchMode(PDO::FETCH_ASSOC); $results = $r->fetchAll(); + // we need to go over all items and fix length for playlist + // in case the playlist contains dynamic block + foreach ($results as &$r) { + if ($r['ftype'] == 'playlist') { + $pl = new Application_Model_Playlist($r['id']); + $r['length'] = $pl->getLength(); + } + } } catch (Exception $e) { Logging::debug($e->getMessage()); } diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index fddd8684d..faf3d838d 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -137,7 +137,6 @@ class Application_Model_Playlist { //Logging::log($this->pl->getDbMtime($format)); //Logging::log($this->pl); - Logging::log("5555"); return $this->pl->getDbMtime($format); } @@ -252,11 +251,29 @@ EOT; //done, just need to set back the formated values return $fade; } + + public function hasDynamicBlockOrWebStream(){ + $sql = "SELECT count(*) as count FROM cc_playlistcontents as pc + JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic' + WHERE playlist_id={$this->id} AND (pc.type=2 OR pc.type=1)"; + $r = $this->con->query($sql); + $result = $r->fetchAll(PDO::FETCH_NUM); + if (intval($result[0][0]) > 0) { + return true; + } else { + return false; + } + } //aggregate column on playlistcontents cliplength column. public function getLength() { - return $this->pl->getDbLength(); + Logging::log($this->hasDynamicBlockOrWebStream()); + if ($this->hasDynamicBlockOrWebStream()){ + return "N/A"; + } else { + return $this->pl->getDbLength(); + } } private function insertPlaylistElement($info) diff --git a/airtime_mvc/application/models/formatters/LengthFormatter.php b/airtime_mvc/application/models/formatters/LengthFormatter.php index 4551e4680..d41ffc563 100644 --- a/airtime_mvc/application/models/formatters/LengthFormatter.php +++ b/airtime_mvc/application/models/formatters/LengthFormatter.php @@ -16,6 +16,9 @@ class LengthFormatter { } public function format() { + if ($this->_length == "N/A" || $this->_length == "") { + return "N/A"; + } $pieces = explode(":", $this->_length); diff --git a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js index 40cb56e3f..cab5349a6 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js @@ -478,6 +478,10 @@ function callback(data, type) { $('#sp_pool_count_icon').removeClass('checked-icon sp-checked-icon').addClass('sp-warning-icon'); } } + //redraw library table so the length gets updated + var dt = $('table[id="library_display"]').dataTable(); + dt.fnStandingRedraw(); + $('div[class="playlist_title"]').find("h4").html(json.blockLength); } setTimeout('removeSuccessMsg()', 5000); }