/** * Simply sets up the view to play the required audio track. * Gets the parameters from the request and sets them to the view. */ public function audioPreviewAction() { $CC_CONFIG = Config::getConfig(); $audioFileID = $this->_getParam('audioFileID'); $audioFileArtist = $this->_getParam('audioFileArtist'); $audioFileTitle = $this->_getParam('audioFileTitle'); $type = $this->_getParam('type'); $baseUrl = Application_Common_OsPath::getBaseDir(); $this->view->headScript()->appendFile($baseUrl . 'js/airtime/audiopreview/preview_jplayer.js?' . $CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headScript()->appendFile($baseUrl . 'js/jplayer/jplayer.playlist.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headLink()->appendStylesheet($baseUrl . 'js/jplayer/skin/jplayer.airtime.audio.preview.css?' . $CC_CONFIG['airtime_version']); $this->_helper->layout->setLayout('audioPlayer'); $logo = Application_Model_Preference::GetStationLogo(); if ($logo) { $this->view->logo = "data:image/png;base64,{$logo}"; } else { $this->view->logo = $baseUrl . "css/images/airtime_logo_jp.png"; } if ($type == "audioclip") { $uri = $baseUrl . "api/get-media/file/" . $audioFileID; $media = Application_Model_StoredFile::RecallById($audioFileID); $mime = $media->getPropelOrm()->getDbMime(); } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPk($audioFileID); $uri = $webstream->getDbUrl(); $mime = $webstream->getDbMime(); } else { throw new Exception("Unknown type for audio preview!.Type={$type}"); } $this->view->uri = $uri; $this->view->mime = $mime; $this->view->audioFileID = $audioFileID; // We need to decode artist and title because it gets // encoded twice in js $this->view->audioFileArtist = htmlspecialchars(urldecode($audioFileArtist)); $this->view->audioFileTitle = htmlspecialchars(urldecode($audioFileTitle)); $this->view->type = $type; $this->_helper->viewRenderer->setRender('audio-preview'); }
/** * Simply sets up the view to play the required audio track. * Gets the parameters from the request and sets them to the view. */ public function audioPreviewAction() { global $CC_CONFIG; $audioFileID = $this->_getParam('audioFileID'); $audioFileArtist = $this->_getParam('audioFileArtist'); $audioFileTitle = $this->_getParam('audioFileTitle'); $type = $this->_getParam('type'); $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); $this->view->headScript()->appendFile($baseUrl . '/js/airtime/audiopreview/preview_jplayer.js?' . $CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headScript()->appendFile($baseUrl . '/js/jplayer/jplayer.playlist.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headLink()->appendStylesheet($baseUrl . '/js/jplayer/skin/jplayer.airtime.audio.preview.css?' . $CC_CONFIG['airtime_version']); $this->_helper->layout->setLayout('audioPlayer'); $logo = Application_Model_Preference::GetStationLogo(); if ($logo) { $this->view->logo = "data:image/png;base64,{$logo}"; } else { $this->view->logo = "{$baseUrl}/css/images/airtime_logo_jp.png"; } if ($type == "audioclip") { $uri = "/api/get-media/file/" . $audioFileID; $media = Application_Model_StoredFile::Recall($audioFileID); $mime = $media->getPropelOrm()->getDbMime(); } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPk($audioFileID); $uri = $webstream->getDbUrl(); $mime = $webstream->getDbMime(); } else { throw new Exception("Unknown type for audio preview!.Type={$type}"); } $this->view->uri = $uri; $this->view->mime = $mime; $this->view->audioFileID = $audioFileID; $this->view->audioFileArtist = $audioFileArtist; $this->view->audioFileTitle = $audioFileTitle; $this->view->type = $type; $this->_helper->viewRenderer->setRender('audio-preview'); }
public function isAuthorized($webstream_id) { $user = Application_Model_User::getCurrentUser(); if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { return true; } if ($user->isHost()) { // not creating a webstream if ($webstream_id != -1) { $webstream = CcWebstreamQuery::create()->findPK($webstream_id); /*we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission.*/ $user = Application_Model_User::getCurrentUser(); //only allow when webstream belongs to the DJ return $webstream->getDbCreatorId() == $user->getId(); } /*we are creating a new stream. Don't need to check whether the DJ/Host owns the stream*/ return true; } else { Logging::info($user); } return false; }
/** * Returns a new CcWebstreamQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return CcWebstreamQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof CcWebstreamQuery) { return $criteria; } $query = new CcWebstreamQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
private function retrieveMediaFiles($id, $type) { $files = array(); if ($type === "audioclip") { $file = CcFilesQuery::create()->findPK($id, $this->con); if (is_null($file) || !$file->getDbFileExists()) { throw new Exception("A selected File does not exist!"); } else { $data = $this->fileInfo; $data["id"] = $id; $data["cliplength"] = $file->getDbLength(); $data["cueout"] = $file->getDbLength(); $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $files[] = $data; } } elseif ($type === "playlist") { $pl = new Application_Model_Playlist($id); $contents = $pl->getContents(); foreach ($contents as $plItem) { if ($plItem['type'] == 0) { $data["id"] = $plItem['item_id']; $data["cliplength"] = $plItem['length']; $data["cuein"] = $plItem['cuein']; $data["cueout"] = $plItem['cueout']; $data["fadein"] = $plItem['fadein']; $data["fadeout"] = $plItem['fadeout']; $data["type"] = 0; $files[] = $data; } elseif ($plItem['type'] == 1) { $data["id"] = $plItem['item_id']; $data["cliplength"] = $plItem['length']; $data["cuein"] = $plItem['cuein']; $data["cueout"] = $plItem['cueout']; $data["fadein"] = "00.500000"; //$plItem['fadein']; $data["fadeout"] = "00.500000"; //$plItem['fadeout']; $data["type"] = 1; $files[] = $data; } elseif ($plItem['type'] == 2) { // if it's a block $bl = new Application_Model_Block($plItem['item_id']); if ($bl->isStatic()) { foreach ($bl->getContents() as $track) { $data["id"] = $track['item_id']; $data["cliplength"] = $track['length']; $data["cuein"] = $track['cuein']; $data["cueout"] = $track['cueout']; $data["fadein"] = $track['fadein']; $data["fadeout"] = $track['fadeout']; $data["type"] = 0; $files[] = $data; } } else { $dynamicFiles = $bl->getListOfFilesUnderLimit(); foreach ($dynamicFiles as $fileId => $f) { $file = CcFilesQuery::create()->findPk($fileId); if (isset($file) && $file->getDbFileExists()) { $data["id"] = $file->getDbId(); $data["cliplength"] = $file->getDbLength(); $data["cuein"] = "00:00:00"; $data["cueout"] = $file->getDbLength(); $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $data["type"] = 0; $files[] = $data; } } } } } } elseif ($type == "stream") { //need to return $stream = CcWebstreamQuery::create()->findPK($id, $this->con); if (is_null($stream)) { throw new Exception("A selected File does not exist!"); } else { $data = $this->fileInfo; $data["id"] = $id; $data["cliplength"] = $stream->getDbLength(); $data["cueout"] = $stream->getDbLength(); $data["type"] = 1; $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $files[] = $data; } } elseif ($type == "block") { $bl = new Application_Model_Block($id); if ($bl->isStatic()) { foreach ($bl->getContents() as $track) { $data["id"] = $track['item_id']; $data["cliplength"] = $track['length']; $data["cuein"] = $track['cuein']; $data["cueout"] = $track['cueout']; $data["fadein"] = $track['fadein']; $data["fadeout"] = $track['fadeout']; $data["type"] = 0; $files[] = $data; } } else { $dynamicFiles = $bl->getListOfFilesUnderLimit(); foreach ($dynamicFiles as $fileId => $f) { $file = CcFilesQuery::create()->findPk($fileId); if (isset($file) && $file->getDbFileExists()) { $data["id"] = $file->getDbId(); $data["cliplength"] = $file->getDbLength(); $data["cuein"] = "00:00:00"; $data["cueout"] = $file->getDbLength(); $defaultFade = Application_Model_Preference::GetDefaultFade(); if (isset($defaultFade)) { //fade is in format SS.uuuuuu $data["fadein"] = $defaultFade; $data["fadeout"] = $defaultFade; } $data["type"] = 0; $files[] = $data; } } } } return $files; }
public static function save($parameters, $mime, $mediaUrl, $di) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $id = $parameters['id']; if ($id != -1) { $webstream = CcWebstreamQuery::create()->findPK($id); } else { $webstream = new CcWebstream(); } $webstream->setDbName($parameters["name"]); $webstream->setDbDescription($parameters["description"]); $webstream->setDbUrl($mediaUrl); $dblength = $di->format("%H:%I"); $webstream->setDbLength($dblength); $webstream->setDbCreatorId($userInfo->id); $webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC'))); $webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC'))); $ws = new Application_Model_Webstream($webstream); $webstream->setDbMime($mime); $webstream->save(); return $webstream->getDbId(); }
/** * Get the associated CcWebstream object * * @param PropelPDO Optional Connection object. * @return CcWebstream The associated CcWebstream object. * @throws PropelException */ public function getCcWebstream(PropelPDO $con = null) { if ($this->aCcWebstream === null && $this->stream_id !== null) { $this->aCcWebstream = CcWebstreamQuery::create()->findPk($this->stream_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCcWebstream->addCcSchedules($this); */ } return $this->aCcWebstream; }
public static function setIsScheduled($p_webstreamId, $p_status) { $webstream = CcWebstreamQuery::create()->findPK($p_webstreamId); $updateIsScheduled = false; if (isset($webstream) && !in_array($p_webstreamId, Application_Model_Schedule::getAllFutureScheduledWebstreams())) { //$webstream->setDbIsScheduled($p_status)->save(); $updateIsScheduled = true; } return $updateIsScheduled; }
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."); } }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(CcWebstreamPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { CcWebstreamQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
public function getFileMetadataAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); try { if ($type == "audioclip") { $file = Application_Model_StoredFile::Recall($id); $this->view->type = $type; $md = $file->getMetadata(); foreach ($md as $key => $value) { if ($key == 'MDATA_KEY_DIRECTORY') { $musicDir = Application_Model_MusicDir::getDirByPK($value); $md['MDATA_KEY_FILEPATH'] = Application_Common_OsPath::join($musicDir->getDirectory(), $md['MDATA_KEY_FILEPATH']); } } $formatter = new SamplerateFormatter($md["MDATA_KEY_SAMPLERATE"]); $md["MDATA_KEY_SAMPLERATE"] = $formatter->format(); $formatter = new BitrateFormatter($md["MDATA_KEY_BITRATE"]); $md["MDATA_KEY_BITRATE"] = $formatter->format(); $formatter = new LengthFormatter($md["MDATA_KEY_DURATION"]); $md["MDATA_KEY_DURATION"] = $formatter->format(); $this->view->md = $md; } elseif ($type == "playlist") { $file = new Application_Model_Playlist($id); $this->view->type = $type; $md = $file->getAllPLMetaData(); $formatter = new LengthFormatter($md["dcterms:extent"]); $md["dcterms:extent"] = $formatter->format(); $this->view->md = $md; $this->view->contents = $file->getContents(); } elseif ($type == "block") { $block = new Application_Model_Block($id); $this->view->type = $type; $md = $block->getAllPLMetaData(); $formatter = new LengthFormatter($md["dcterms:extent"]); $md["dcterms:extent"] = $formatter->format(); $this->view->md = $md; if ($block->isStatic()) { $this->view->blType = 'Static'; $this->view->contents = $block->getContents(); } else { $this->view->blType = 'Dynamic'; $this->view->contents = $block->getCriteria(); } $this->view->block = $block; } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPK($id); $ws = new Application_Model_Webstream($webstream); $md = $ws->getMetadata(); $this->view->md = $md; $this->view->type = $type; } } catch (Exception $e) { Logging::info($e->getMessage()); } }
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->getDbFileExists() || $obj instanceof CcWebstream || $obj instanceof CcBlock) { $entry = $this->plItem; $entry["id"] = $obj->getDbId(); $entry["pos"] = $pos; $entry["cliplength"] = $obj->getDbLength(); $entry["cueout"] = $obj->getDbLength(); $entry["ftype"] = $objType; } return $entry; } else { throw new Exception("trying to add a object that does not exist."); } }