public function format()
 {
     $formatted = "";
     $sign = $this->_seconds < 0 ? "-" : "+";
     $perfect = true;
     $time = Application_Common_DateHelper::secondsToPlaylistTime(abs($this->_seconds));
     $info = explode(":", $time);
     $formatted .= $sign;
     if (intval($info[0]) > 0) {
         $info[0] = ltrim($info[0], "0");
         $formatted .= " {$info[0]}h";
         $perfect = false;
     }
     if (intval($info[1]) > 0) {
         $info[1] = ltrim($info[1], "0");
         $formatted .= " {$info[1]}m";
         $perfect = false;
     }
     if (intval($info[2]) > 0) {
         $sec = round($info[2], 0);
         $formatted .= " {$sec}s";
         $perfect = false;
     }
     //0 over/under lap of content.
     if ($perfect === true) {
         $formatted = "+ 0s";
     }
     return $formatted;
 }
Exemplo n.º 2
0
 public function getCueLength()
 {
     $cuein = $this->getDbCuein();
     $cueout = $this->getDbCueout();
     $cueinSec = Application_Common_DateHelper::calculateLengthInSeconds($cuein);
     $cueoutSec = Application_Common_DateHelper::calculateLengthInSeconds($cueout);
     $lengthSec = bcsub($cueoutSec, $cueinSec, 6);
     $length = Application_Common_DateHelper::secondsToPlaylistTime($lengthSec);
     return $length;
 }
Exemplo n.º 3
0
 public function removeItems($scheduledItems, $adjustSched = true)
 {
     $showInstances = array();
     $this->con->beginTransaction();
     try {
         $this->validateRequest($scheduledItems);
         $scheduledIds = array();
         foreach ($scheduledItems as $item) {
             $scheduledIds[] = $item["id"];
         }
         $removedItems = CcScheduleQuery::create()->findPks($scheduledIds);
         //check to make sure all items selected are up to date
         foreach ($removedItems as $removedItem) {
             $instance = $removedItem->getCcShowInstances($this->con);
             //check to truncate the currently playing item instead of deleting it.
             if ($removedItem->isCurrentItem($this->epochNow)) {
                 $nEpoch = $this->epochNow;
                 $sEpoch = $removedItem->getDbStarts('U.u');
                 $length = bcsub($nEpoch, $sEpoch, 6);
                 $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length);
                 $cueinSec = Application_Common_DateHelper::playlistTimeToSeconds($removedItem->getDbCueIn());
                 $cueOutSec = bcadd($cueinSec, $length, 6);
                 $cueout = Application_Common_DateHelper::secondsToPlaylistTime($cueOutSec);
                 //Set DbEnds - 1 second because otherwise there can be a timing issue
                 //when sending the new schedule to Pypo where Pypo thinks the track is still
                 //playing.
                 $removedItem->setDbCueOut($cueout)->setDbClipLength($cliplength)->setDbEnds($this->nowDT)->save($this->con);
             } else {
                 $removedItem->delete($this->con);
             }
         }
         if ($adjustSched === true) {
             //get the show instances of the shows we must adjust times for.
             foreach ($removedItems as $item) {
                 $instance = $item->getDBInstanceId();
                 if (!in_array($instance, $showInstances)) {
                     $showInstances[] = $instance;
                 }
             }
             foreach ($showInstances as $instance) {
                 $this->removeGaps($instance);
             }
         }
         //update the status flag in cc_schedule.
         $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->find($this->con);
         foreach ($instances as $instance) {
             $instance->updateScheduleStatus($this->con);
         }
         //update the last scheduled timestamp.
         CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
         $this->con->commit();
         Application_Model_RabbitMq::PushSchedule();
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
Exemplo n.º 4
0
 public function updateCueValuesBySilanAction()
 {
     $request = $this->getRequest();
     $data = json_decode($request->getParam('data'), $assoc = true);
     foreach ($data as $pair) {
         list($id, $info) = $pair;
         // TODO : move this code into model -- RG
         $file = Application_Model_StoredFile::RecallById($p_id = $id)->getPropelOrm();
         //What we are doing here is setting a more accurate length that was
         //calculated with silan by actually scanning the entire file. This
         //process takes a really long time, and so we only do it in the background
         //after the file has already been imported -MK
         try {
             $length = $file->getDbLength();
             if (isset($info['length'])) {
                 $length = $info['length'];
                 //length decimal number in seconds. Need to convert it to format
                 //HH:mm:ss to get around silly PHP limitations.
                 $length = Application_Common_DateHelper::secondsToPlaylistTime($length);
                 $file->setDbLength($length);
             }
             $cuein = isset($info['cuein']) ? $info['cuein'] : 0;
             $cueout = isset($info['cueout']) ? $info['cueout'] : $length;
             $file->setDbCuein($cuein);
             $file->setDbCueout($cueout);
             $file->setDbSilanCheck(true);
             $file->save();
         } catch (Exception $e) {
             Logging::info("Failed to update silan values for " . $file->getDbTrackTitle());
             Logging::info("File length analyzed by Silan is: " . $length);
             //set silan_check to true so we don't attempt to re-anaylze again
             $file->setDbSilanCheck(true);
             $file->save();
         }
     }
     $this->_helper->json->sendJson(array());
 }
Exemplo n.º 5
0
 private function makeScheduledItemRow($p_item)
 {
     $row = $this->defaultRowArray;
     if (isset($p_item["sched_starts"])) {
         $schedStartDT = new DateTime($p_item["sched_starts"], new DateTimeZone("UTC"));
         $schedStartDT->setTimezone(new DateTimeZone($this->timezone));
         $schedEndDT = new DateTime($p_item["sched_ends"], new DateTimeZone("UTC"));
         $schedEndDT->setTimezone(new DateTimeZone($this->timezone));
         $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
         $this->getItemStatus($p_item, $row);
         $startsEpoch = floatval($schedStartDT->format("U.u"));
         $endsEpoch = floatval($schedEndDT->format("U.u"));
         $showEndEpoch = floatval($showEndDT->format("U.u"));
         //don't want an overbooked item to stay marked as current.
         $this->getScheduledStatus($startsEpoch, min($endsEpoch, $showEndEpoch), $row);
         $row["id"] = intval($p_item["sched_id"]);
         $row["image"] = $p_item["file_exists"];
         $row["instance"] = intval($p_item["si_id"]);
         $row["starts"] = $schedStartDT->format("H:i:s");
         $row["ends"] = $schedEndDT->format("H:i:s");
         $cue_out = Application_Common_DateHelper::playlistTimeToSeconds($p_item['cue_out']);
         $cue_in = Application_Common_DateHelper::playlistTimeToSeconds($p_item['cue_in']);
         $run_time = $cue_out - $cue_in;
         $formatter = new LengthFormatter(Application_Common_DateHelper::secondsToPlaylistTime($run_time));
         $row['runtime'] = $formatter->format();
         $row["title"] = htmlspecialchars($p_item["file_track_title"]);
         $row["creator"] = htmlspecialchars($p_item["file_artist_name"]);
         $row["album"] = htmlspecialchars($p_item["file_album_title"]);
         $row["cuein"] = $p_item["cue_in"];
         $row["cueout"] = $p_item["cue_out"];
         $row["fadein"] = round(substr($p_item["fade_in"], 6), 6);
         $row["fadeout"] = round(substr($p_item["fade_out"], 6), 6);
         $row["mime"] = $p_item["file_mime"];
         $row["pos"] = $this->pos++;
         $this->contentDT = $schedEndDT;
     } else {
         if (intval($p_item["si_record"]) === 1) {
             $row["record"] = true;
             $row["instance"] = intval($p_item["si_id"]);
             $showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
             $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
             $startsEpoch = floatval($showStartDT->format("U.u"));
             $endsEpoch = floatval($showEndDT->format("U.u"));
             $this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
         } else {
             $row["empty"] = true;
             $row["id"] = 0;
             $row["instance"] = intval($p_item["si_id"]);
         }
     }
     if (intval($p_item["si_rebroadcast"]) === 1) {
         $row["rebroadcast"] = true;
     }
     if ($this->currentShow === true) {
         $row["currentShow"] = true;
     }
     $this->getItemColor($p_item, $row);
     $this->getRowTimestamp($p_item, $row);
     $this->isAllowed($p_item, $row);
     return $row;
 }
Exemplo n.º 6
0
 public function removeItems($scheduledItems, $adjustSched = true, $cancelShow = false)
 {
     $showInstances = array();
     $this->con->beginTransaction();
     try {
         $this->validateRequest($scheduledItems);
         $scheduledIds = array();
         foreach ($scheduledItems as $item) {
             $scheduledIds[] = $item["id"];
         }
         $removedItems = CcScheduleQuery::create()->findPks($scheduledIds);
         //check to make sure all items selected are up to date
         foreach ($removedItems as $removedItem) {
             $instance = $removedItem->getCcShowInstances($this->con);
             //check if instance is linked and if so get the schedule items
             //for all linked instances so we can delete them too
             if (!$cancelShow && $instance->getCcShow()->isLinked()) {
                 //returns all linked instances if linked
                 $ccShowInstances = $this->getInstances($instance->getDbId());
                 $instanceIds = array();
                 foreach ($ccShowInstances as $ccShowInstance) {
                     $instanceIds[] = $ccShowInstance->getDbId();
                 }
                 /*
                  * Find all the schedule items that are in the same position
                  * as the selected item by the user.
                  * The position of each track is the same across each linked instance
                  */
                 $itemsToDelete = CcScheduleQuery::create()->filterByDbPosition($removedItem->getDbPosition())->filterByDbInstanceId($instanceIds, Criteria::IN)->find();
                 foreach ($itemsToDelete as $item) {
                     if (!$removedItems->contains($item)) {
                         $removedItems->append($item);
                     }
                 }
             }
             //check to truncate the currently playing item instead of deleting it.
             if ($removedItem->isCurrentItem($this->epochNow)) {
                 $nEpoch = $this->epochNow;
                 $sEpoch = $removedItem->getDbStarts('U.u');
                 $length = bcsub($nEpoch, $sEpoch, 6);
                 $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length);
                 $cueinSec = Application_Common_DateHelper::playlistTimeToSeconds($removedItem->getDbCueIn());
                 $cueOutSec = bcadd($cueinSec, $length, 6);
                 $cueout = Application_Common_DateHelper::secondsToPlaylistTime($cueOutSec);
                 //Set DbEnds - 1 second because otherwise there can be a timing issue
                 //when sending the new schedule to Pypo where Pypo thinks the track is still
                 //playing.
                 $removedItem->setDbCueOut($cueout)->setDbClipLength($cliplength)->setDbEnds($this->nowDT)->save($this->con);
             } else {
                 $removedItem->delete($this->con);
             }
             // update is_scheduled in cc_files but only if
             // the file is not scheduled somewhere else
             $fileId = $removedItem->getDbFileId();
             // check if the removed item is scheduled somewhere else
             $futureScheduledFiles = Application_Model_Schedule::getAllFutureScheduledFiles();
             if (!is_null($fileId) && !in_array($fileId, $futureScheduledFiles)) {
                 $db_file = CcFilesQuery::create()->findPk($fileId, $this->con);
                 $db_file->setDbIsScheduled(false)->save($this->con);
             }
         }
         if ($adjustSched === true) {
             //get the show instances of the shows we must adjust times for.
             foreach ($removedItems as $item) {
                 $instance = $item->getDBInstanceId();
                 if (!in_array($instance, $showInstances)) {
                     $showInstances[] = $instance;
                 }
             }
             foreach ($showInstances as $instance) {
                 $this->removeGaps($instance);
                 $this->calculateCrossfades($instance);
             }
         }
         //update the status flag in cc_schedule.
         $instances = CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->find($this->con);
         foreach ($instances as $instance) {
             $instance->updateScheduleStatus($this->con);
             $instance->correctSchedulePositions();
         }
         //update the last scheduled timestamp.
         CcShowInstancesQuery::create()->filterByPrimaryKeys($showInstances)->update(array('DbLastScheduled' => new DateTime("now", new DateTimeZone("UTC"))), $this->con);
         $this->con->commit();
         Application_Model_RabbitMq::PushSchedule();
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
Exemplo n.º 7
0
 private function buildEntry($p_item, $pos)
 {
     $objType = $p_item[1];
     $objId = $p_item[0];
     if ($objType == 'audioclip') {
         $obj = CcFilesQuery::create()->findPK($objId, $this->con);
     } elseif ($objType == "stream") {
         $obj = CcWebstreamQuery::create()->findPK($objId, $this->con);
     } elseif ($objType == "block") {
         $obj = CcBlockQuery::create()->findPK($objId, $this->con);
     } else {
         throw new Exception("Unknown file type");
     }
     if (isset($obj)) {
         if ($obj instanceof CcFiles && $obj->visible() || $obj instanceof CcWebstream || $obj instanceof CcBlock) {
             $entry = $this->plItem;
             $entry["id"] = $obj->getDbId();
             $entry["pos"] = $pos;
             $entry["cliplength"] = $obj->getDbLength();
             if ($obj instanceof CcFiles && $obj) {
                 $entry["cuein"] = isset($p_item['cuein']) ? $p_item['cuein'] : $obj->getDbCuein();
                 $entry["cueout"] = isset($p_item['cueout']) ? $p_item['cueout'] : $obj->getDbCueout();
                 $cue_in = isset($p_item['cueInSec']) ? $p_item['cueInSec'] : Application_Common_DateHelper::calculateLengthInSeconds($entry['cuein']);
                 $cue_out = isset($p_item['cueOutSec']) ? $p_item['cueOutSec'] : Application_Common_DateHelper::calculateLengthInSeconds($entry['cueout']);
                 $entry["cliplength"] = isset($p_item['length']) ? $p_item['length'] : Application_Common_DateHelper::secondsToPlaylistTime($cue_out - $cue_in);
             } elseif ($obj instanceof CcWebstream && $obj) {
                 $entry["cuein"] = "00:00:00";
                 $entry["cueout"] = $entry["cliplength"];
             }
             $entry["ftype"] = $objType;
             $entry["fadein"] = isset($p_item['fadein']) ? $p_item['fadein'] : $entry["fadein"];
             $entry["fadeout"] = isset($p_item['fadeout']) ? $p_item['fadeout'] : $entry["fadeout"];
         }
         return $entry;
     } else {
         throw new Exception("trying to add a object that does not exist.");
     }
 }
Exemplo n.º 8
0
    /**
     * Get the entire block as a two dimentional array, sorted in order of play.
     * @param boolean $filterFiles if this is true, it will only return files that has
     *             file_exists flag set to true
     * @return array
     */
    public function getContents($filterFiles = false)
    {
        Logging::info("Getting contents for block {$this->id}");
        $sql = <<<SQL
SELECT pc.id AS id,
       pc.position,
       pc.cliplength AS LENGTH,
       pc.cuein,
       pc.cueout,
       pc.fadein,
       pc.fadeout,
       bl.type,
       f.LENGTH AS orig_length,
       f.id AS item_id,
       f.track_title,
       f.artist_name AS creator,
       f.file_exists AS EXISTS,
       f.filepath AS path,
       f.mime as mime
FROM cc_blockcontents AS pc
LEFT JOIN cc_files AS f ON pc.file_id=f.id
LEFT JOIN cc_block AS bl ON pc.block_id = bl.id
WHERE pc.block_id = :block_id
ORDER BY pc.position
SQL;
        $rows = Application_Common_Database::prepareAndExecute($sql, array(':block_id' => $this->id));
        $offset = 0;
        foreach ($rows as &$row) {
            $clipSec = Application_Common_DateHelper::playlistTimeToSeconds($row['length']);
            $offset += $clipSec;
            $offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset);
            //format the length for UI.
            $formatter = new LengthFormatter($row['length']);
            $row['length'] = $formatter->format();
            $formatter = new LengthFormatter($offset_cliplength);
            $row['offset'] = $formatter->format();
            //format the fades in format 00(.0)
            $fades = $this->getFadeInfo($row['position']);
            $row['fadein'] = $fades[0];
            $row['fadeout'] = $fades[1];
            // format the cues in format 00:00:00(.0)
            // we need to add the '.0' for cues and not fades
            // because propel takes care of this for us
            // (we use propel to fetch the fades)
            $row['cuein'] = str_pad(substr($row['cuein'], 0, 10), 10, '.0');
            $row['cueout'] = str_pad(substr($row['cueout'], 0, 10), 10, '.0');
            //format original length
            $formatter = new LengthFormatter($row['orig_length']);
            $row['orig_length'] = $formatter->format();
        }
        return $rows;
    }
Exemplo n.º 9
0
 private function buildEntry($p_item, $pos)
 {
     $file = CcFilesQuery::create()->findPK($p_item, $this->con);
     if (isset($file) && $file->visible()) {
         $entry = $this->blockItem;
         $entry["id"] = $file->getDbId();
         $entry["pos"] = $pos;
         $entry["cueout"] = $file->getDbCueout();
         $entry["cuein"] = $file->getDbCuein();
         $cue_out = Application_Common_DateHelper::calculateLengthInSeconds($entry['cueout']);
         $cue_in = Application_Common_DateHelper::calculateLengthInSeconds($entry['cuein']);
         $entry["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cue_out - $cue_in);
         return $entry;
     } else {
         throw new Exception("trying to add a file that does not exist.");
     }
 }
Exemplo n.º 10
0
 public static function searchLibraryFiles($datatables)
 {
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
     $displayColumns = self::getLibraryColumns();
     $plSelect = array();
     $blSelect = array();
     $fileSelect = array();
     $streamSelect = array();
     foreach ($displayColumns as $key) {
         if ($key === "id") {
             $plSelect[] = "PL.id AS " . $key;
             $blSelect[] = "BL.id AS " . $key;
             $fileSelect[] = "FILES.id AS {$key}";
             $streamSelect[] = "ws.id AS " . $key;
         } elseif ($key === "track_title") {
             $plSelect[] = "name AS " . $key;
             $blSelect[] = "name AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "name AS " . $key;
         } elseif ($key === "ftype") {
             $plSelect[] = "'playlist'::varchar AS " . $key;
             $blSelect[] = "'block'::varchar AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "'stream'::varchar AS " . $key;
         } elseif ($key === "artist_name") {
             $plSelect[] = "login AS " . $key;
             $blSelect[] = "login AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "login AS " . $key;
         } elseif ($key === "owner_id") {
             $plSelect[] = "login AS " . $key;
             $blSelect[] = "login AS " . $key;
             $fileSelect[] = "sub.login AS {$key}";
             $streamSelect[] = "login AS " . $key;
         } elseif ($key === "replay_gain") {
             $plSelect[] = "NULL::NUMERIC AS " . $key;
             $blSelect[] = "NULL::NUMERIC AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::NUMERIC AS " . $key;
         } elseif ($key === "lptime") {
             $plSelect[] = "NULL::TIMESTAMP AS " . $key;
             $blSelect[] = "NULL::TIMESTAMP AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = $key;
         } elseif ($key === "is_scheduled" || $key === "is_playlist") {
             $plSelect[] = "NULL::boolean AS " . $key;
             $blSelect[] = "NULL::boolean AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::boolean AS " . $key;
         } elseif ($key === "cuein" || $key === "cueout") {
             $plSelect[] = "NULL::INTERVAL AS " . $key;
             $blSelect[] = "NULL::INTERVAL AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::INTERVAL AS " . $key;
         } else {
             if ($key === "length") {
                 $plSelect[] = $key;
                 $blSelect[] = $key;
                 $fileSelect[] = "(cueout - cuein)::INTERVAL AS length";
                 $streamSelect[] = $key;
             } else {
                 if (in_array($key, array("utime", "mtime"))) {
                     $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;
                     $streamSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                 } else {
                     if (in_array($key, array("track_number", "bit_rate", "sample_rate", "bpm"))) {
                         $plSelect[] = "NULL::int AS " . $key;
                         $blSelect[] = "NULL::int AS " . $key;
                         $fileSelect[] = $key;
                         $streamSelect[] = "NULL::int AS " . $key;
                     } elseif ($key === "filepath") {
                         $plSelect[] = "NULL::VARCHAR AS " . $key;
                         $blSelect[] = "NULL::VARCHAR AS " . $key;
                         $fileSelect[] = $key;
                         $streamSelect[] = "url AS " . $key;
                     } else {
                         if ($key == "mime") {
                             $plSelect[] = "NULL::VARCHAR AS " . $key;
                             $blSelect[] = "NULL::VARCHAR AS " . $key;
                             $fileSelect[] = $key;
                             $streamSelect[] = $key;
                         } else {
                             $plSelect[] = "NULL::text AS " . $key;
                             $blSelect[] = "NULL::text AS " . $key;
                             $fileSelect[] = $key;
                             $streamSelect[] = "NULL::text AS " . $key;
                         }
                     }
                 }
             }
         }
     }
     $plSelect = "SELECT " . join(",", $plSelect);
     $blSelect = "SELECT " . join(",", $blSelect);
     $fileSelect = "SELECT " . join(",", $fileSelect);
     $streamSelect = "SELECT " . join(",", $streamSelect);
     $type = intval($datatables["type"]);
     $plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))";
     $blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))";
     $fileTable = "({$fileSelect} FROM cc_files AS FILES LEFT JOIN cc_subjs AS sub ON (sub.id = FILES.owner_id) WHERE file_exists = 'TRUE' AND hidden='FALSE')";
     //$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
     $streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))";
     $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;
             break;
         case 1:
             $fromTable = $fileTable . " AS File";
             //need an alias for the table if it's standalone.
             break;
         case 2:
             $fromTable = $plTable . " AS Playlist";
             //need an alias for the table if it's standalone.
             break;
         case 3:
             $fromTable = $blTable . " AS Block";
             //need an alias for the table if it's standalone.
             break;
         case 4:
             $fromTable = $streamTable . " AS StreamTable";
             //need an alias for the table if it's standalone.
             break;
         default:
             $fromTable = $unionTable;
     }
     // update is_scheduled to false for tracks that
     // have already played out
     self::updatePastFilesIsScheduled();
     $results = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $utcTimezone = new DateTimeZone("UTC");
     foreach ($results['aaData'] as &$row) {
         $row['id'] = intval($row['id']);
         //taken from Datatables.php, needs to be cleaned up there.
         if (isset($r['ftype'])) {
             if ($r['ftype'] == 'playlist') {
                 $pl = new Application_Model_Playlist($r['id']);
                 $r['length'] = $pl->getLength();
             } elseif ($r['ftype'] == "block") {
                 $bl = new Application_Model_Block($r['id']);
                 $r['bl_type'] = $bl->isStatic() ? 'static' : 'dynamic';
                 $r['length'] = $bl->getLength();
             }
         }
         if ($row['ftype'] === "audioclip") {
             $cuein_formatter = new LengthFormatter($row["cuein"]);
             $row["cuein"] = $cuein_formatter->format();
             $cueout_formatter = new LengthFormatter($row["cueout"]);
             $row["cueout"] = $cueout_formatter->format();
             $cuein = Application_Common_DateHelper::playlistTimeToSeconds($row["cuein"]);
             $cueout = Application_Common_DateHelper::playlistTimeToSeconds($row["cueout"]);
             $row_length = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
             $formatter = new SamplerateFormatter($row['sample_rate']);
             $row['sample_rate'] = $formatter->format();
             $formatter = new BitrateFormatter($row['bit_rate']);
             $row['bit_rate'] = $formatter->format();
             //soundcloud status
             $file = Application_Model_StoredFile::RecallById($row['id']);
             $row['soundcloud_id'] = $file->getSoundCloudId();
             // for audio preview
             $row['audioFile'] = $row['id'] . "." . pathinfo($row['filepath'], PATHINFO_EXTENSION);
         } else {
             $row['audioFile'] = $row['id'];
             $row_length = $row['length'];
         }
         $len_formatter = new LengthFormatter($row_length);
         $row['length'] = $len_formatter->format();
         //convert mtime and utime to localtime
         $row['mtime'] = new DateTime($row['mtime'], $utcTimezone);
         $row['mtime']->setTimeZone($displayTimezone);
         $row['mtime'] = $row['mtime']->format('Y-m-d H:i:s');
         $row['utime'] = new DateTime($row['utime'], $utcTimezone);
         $row['utime']->setTimeZone($displayTimezone);
         $row['utime'] = $row['utime']->format('Y-m-d H:i:s');
         //need to convert last played to localtime if it exists.
         if (isset($row['lptime'])) {
             $row['lptime'] = new DateTime($row['lptime'], $utcTimezone);
             $row['lptime']->setTimeZone($displayTimezone);
             $row['lptime'] = $row['lptime']->format('Y-m-d H:i:s');
         }
         // we need to initalize the checkbox and image row because we do not retrieve
         // any data from the db for these and datatables will complain
         $row['checkbox'] = "";
         $row['image'] = "";
         $type = substr($row['ftype'], 0, 2);
         $row['tr_id'] = "{$type}_{$row['id']}";
     }
     return $results;
 }
Exemplo n.º 11
0
    /**
     * Get the entire playlist as a two dimentional array, sorted in order of play.
     * @param boolean $filterFiles if this is true, it will only return files that has
     *             file_exists flag set to true
     * @return array
     */
    public function getContents($filterFiles = false)
    {
        Logging::info("Getting contents for playlist {$this->id}");
        $sql = <<<SQL
  SELECT *
   FROM (
           (SELECT pc.id AS id,
                   pc.type,
                   pc.position,
                   pc.cliplength AS LENGTH,
                   pc.cuein,
                   pc.cueout,
                   pc.fadein,
                   pc.fadeout,
                   f.id AS item_id,
                   f.track_title,
                   f.artist_name AS creator,
                   f.file_exists AS EXISTS,
                   f.filepath AS path,
                   f.length AS orig_length,
                   f.mime AS mime
            FROM cc_playlistcontents AS pc
            JOIN cc_files AS f ON pc.file_id=f.id
            WHERE pc.playlist_id = :playlist_id1
              AND TYPE = 0)
         UNION ALL
           (SELECT pc.id AS id,
                   pc.TYPE, pc.position,
                            pc.cliplength AS LENGTH,
                            pc.cuein,
                            pc.cueout,
                            pc.fadein,
                            pc.fadeout,
                            ws.id AS item_id,
                            (ws.name || ': ' || ws.url) AS title,
                            sub.login AS creator,
                            't'::boolean AS EXISTS,
                            ws.url AS path,
                            ws.length AS orig_length,
                            ws.mime as mime
            FROM cc_playlistcontents AS pc
            JOIN cc_webstream AS ws ON pc.stream_id=ws.id
            LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id
            WHERE pc.playlist_id = :playlist_id2
              AND pc.TYPE = 1)
         UNION ALL
           (SELECT pc.id AS id,
                   pc.TYPE, pc.position,
                            pc.cliplength AS LENGTH,
                            pc.cuein,
                            pc.cueout,
                            pc.fadein,
                            pc.fadeout,
                            bl.id AS item_id,
                            bl.name AS title,
                            sbj.login AS creator,
                            't'::boolean AS EXISTS,
                            NULL::text AS path,
                            bl.length AS orig_length,
                            NULL::text as mime
            FROM cc_playlistcontents AS pc
            JOIN cc_block AS bl ON pc.block_id=bl.id
            JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id
            WHERE pc.playlist_id = :playlist_id3
              AND pc.TYPE = 2)) AS temp
   ORDER BY temp.position;
SQL;
        $rows = Application_Common_Database::prepareAndExecute($sql, array(':playlist_id1' => $this->id, ':playlist_id2' => $this->id, ':playlist_id3' => $this->id));
        $offset = 0;
        foreach ($rows as &$row) {
            $clipSec = Application_Common_DateHelper::playlistTimeToSeconds($row['length']);
            $offset += $clipSec;
            $offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset);
            //format the length for UI.
            if ($row['type'] == 2) {
                $bl = new Application_Model_Block($row['item_id']);
                $formatter = new LengthFormatter($bl->getLength());
            } else {
                $formatter = new LengthFormatter($row['length']);
            }
            $row['length'] = $formatter->format();
            $formatter = new LengthFormatter($offset_cliplength);
            $row['offset'] = $formatter->format();
            //format the fades in format 00(.000000)
            $fades = $this->getFadeInfo($row['position']);
            $row['fadein'] = $fades[0];
            $row['fadeout'] = $fades[1];
            // format the cues in format 00:00:00(.0)
            // we need to add the '.0' for cues and not fades
            // because propel takes care of this for us
            // (we use propel to fetch the fades)
            $row['cuein'] = str_pad(substr($row['cuein'], 0, 10), 10, '.0');
            $row['cueout'] = str_pad(substr($row['cueout'], 0, 10), 10, '.0');
            //format original length
            $formatter = new LengthFormatter($row['orig_length']);
            $row['orig_length'] = $formatter->format();
        }
        return $rows;
    }