LibraryController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <?php
  2. require_once 'formatters/LengthFormatter.php';
  3. require_once 'formatters/SamplerateFormatter.php';
  4. require_once 'formatters/BitrateFormatter.php';
  5. class LibraryController extends Zend_Controller_Action
  6. {
  7. public function init()
  8. {
  9. $ajaxContext = $this->_helper->getHelper('AjaxContext');
  10. $ajaxContext->addActionContext('contents-feed', 'json')
  11. ->addActionContext('delete', 'json')
  12. ->addActionContext('duplicate', 'json')
  13. ->addActionContext('delete-group', 'json')
  14. ->addActionContext('context-menu', 'json')
  15. ->addActionContext('get-file-metadata', 'html')
  16. ->addActionContext('upload-file-soundcloud', 'json')
  17. ->addActionContext('get-upload-to-soundcloud-status', 'json')
  18. ->addActionContext('set-num-entries', 'json')
  19. ->addActionContext('edit-file-md', 'json')
  20. ->initContext();
  21. }
  22. public function indexAction()
  23. {
  24. $CC_CONFIG = Config::getConfig();
  25. $request = $this->getRequest();
  26. $baseUrl = Application_Common_OsPath::getBaseDir();
  27. $this->view->headScript()->appendFile($baseUrl.'js/blockui/jquery.blockUI.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  28. $this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  29. $this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  30. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  31. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  32. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  33. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  34. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  35. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  36. $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  37. $this->view->headScript()->appendFile($baseUrl.'js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  38. $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  39. $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/library_playlistbuilder.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  40. $this->view->headLink()->appendStylesheet($baseUrl.'css/media_library.css?'.$CC_CONFIG['airtime_version']);
  41. $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']);
  42. $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColVis.css?'.$CC_CONFIG['airtime_version']);
  43. $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColReorder.css?'.$CC_CONFIG['airtime_version']);
  44. $this->view->headLink()->appendStylesheet($baseUrl.'css/waveform.css?'.$CC_CONFIG['airtime_version']);
  45. $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/spl.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  46. $this->view->headScript()->appendFile($baseUrl.'js/airtime/playlist/smart_blockbuilder.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  47. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/observer/observer.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  48. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/config.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  49. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/curves.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  50. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/fades.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  51. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/local_storage.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  52. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/controls.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  53. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/playout.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  54. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/track_render.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  55. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/track.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  56. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/time_scale.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  57. $this->view->headScript()->appendFile($baseUrl.'js/waveformplaylist/playlist.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  58. //arbitrary attributes need to be allowed to set an id for the templates.
  59. $this->view->headScript()->setAllowArbitraryAttributes(true);
  60. //$this->view->headScript()->appendScript(file_get_contents(APPLICATION_PATH.'/../public/js/waveformplaylist/templates/bottombar.tpl'),
  61. // 'text/template', array('id' => 'tpl_playlist_cues', 'noescape' => true));
  62. $this->view->headLink()->appendStylesheet($baseUrl.'css/playlist_builder.css?'.$CC_CONFIG['airtime_version']);
  63. try {
  64. $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
  65. if (isset($obj_sess->id)) {
  66. $objInfo = Application_Model_Library::getObjInfo($obj_sess->type);
  67. Logging::info($obj_sess->id);
  68. Logging::info($obj_sess->type);
  69. $objInfo = Application_Model_Library::getObjInfo($obj_sess->type);
  70. $obj = new $objInfo['className']($obj_sess->id);
  71. $userInfo = Zend_Auth::getInstance()->getStorage()->read();
  72. $user = new Application_Model_User($userInfo->id);
  73. $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
  74. if ($isAdminOrPM || $obj->getCreatorId() == $userInfo->id) {
  75. $this->view->obj = $obj;
  76. if ($obj_sess->type == "block") {
  77. $form = new Application_Form_SmartBlockCriteria();
  78. $form->startForm($obj_sess->id);
  79. $this->view->form = $form;
  80. }
  81. }
  82. $formatter = new LengthFormatter($obj->getLength());
  83. $this->view->length = $formatter->format();
  84. $this->view->type = $obj_sess->type;
  85. }
  86. //get user settings and determine if we need to hide
  87. // or show the playlist editor
  88. $showPlaylist = false;
  89. $data = Application_Model_Preference::getLibraryScreenSettings();
  90. if (!is_null($data)) {
  91. if ($data["playlist"] == "true") {
  92. $showPlaylist = true;
  93. }
  94. }
  95. $this->view->showPlaylist = $showPlaylist;
  96. } catch (PlaylistNotFoundException $e) {
  97. $this->playlistNotFound($obj_sess->type);
  98. } catch (Exception $e) {
  99. $this->playlistNotFound($obj_sess->type);
  100. Logging::info($e->getMessage());
  101. //$this->playlistUnknownError($e);
  102. }
  103. }
  104. protected function playlistNotFound($p_type)
  105. {
  106. $this->view->error = sprintf(_("%s not found"), $p_type);
  107. Logging::info("$p_type not found");
  108. Application_Model_Library::changePlaylist(null, $p_type);
  109. $this->createFullResponse(null);
  110. }
  111. protected function playlistUnknownError($e)
  112. {
  113. $this->view->error = _("Something went wrong.");
  114. Logging::info($e->getMessage());
  115. }
  116. protected function createFullResponse($obj = null, $isJson = false)
  117. {
  118. $isBlock = false;
  119. $viewPath = 'playlist/playlist.phtml';
  120. if ($obj instanceof Application_Model_Block) {
  121. $isBlock = true;
  122. $viewPath = 'playlist/smart-block.phtml';
  123. }
  124. if (isset($obj)) {
  125. $formatter = new LengthFormatter($obj->getLength());
  126. $this->view->length = $formatter->format();
  127. if ($isBlock) {
  128. $form = new Application_Form_SmartBlockCriteria();
  129. $form->removeDecorator('DtDdWrapper');
  130. $form->startForm($obj->getId());
  131. $this->view->form = $form;
  132. $this->view->obj = $obj;
  133. $this->view->id = $obj->getId();
  134. if ($isJson) {
  135. return $this->view->render($viewPath);
  136. } else {
  137. $this->view->html = $this->view->render($viewPath);
  138. }
  139. } else {
  140. $this->view->obj = $obj;
  141. $this->view->id = $obj->getId();
  142. $this->view->html = $this->view->render($viewPath);
  143. unset($this->view->obj);
  144. }
  145. } else {
  146. $this->view->html = $this->view->render($viewPath);
  147. }
  148. }
  149. public function contextMenuAction()
  150. {
  151. $baseUrl = Application_Common_OsPath::getBaseDir();
  152. $id = $this->_getParam('id');
  153. $type = $this->_getParam('type');
  154. //playlist||timeline
  155. $screen = $this->_getParam('screen');
  156. $menu = array();
  157. $userInfo = Zend_Auth::getInstance()->getStorage()->read();
  158. $user = new Application_Model_User($userInfo->id);
  159. //Open a jPlayer window and play the audio clip.
  160. $menu["play"] = array("name"=> _("Preview"), "icon" => "play", "disabled" => false);
  161. $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
  162. $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
  163. if ($type === "audioclip") {
  164. $file = Application_Model_StoredFile::RecallById($id);
  165. $menu["play"]["mime"] = $file->getPropelOrm()->getDbMime();
  166. if (isset($obj_sess->id) && $screen == "playlist") {
  167. // if the user is not admin or pm, check the creator and see if this person owns the playlist or Block
  168. if ($obj_sess->type == 'playlist') {
  169. $obj = new Application_Model_Playlist($obj_sess->id);
  170. } elseif ($obj_sess->type == 'block') {
  171. $obj = new Application_Model_Block($obj_sess->id);
  172. }
  173. if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
  174. if ($obj_sess->type === "playlist") {
  175. $menu["pl_add"] = array("name"=> _("Add to Playlist"), "icon" => "add-playlist", "icon" => "copy");
  176. } elseif ($obj_sess->type === "block" && $obj->isStatic()) {
  177. $menu["pl_add"] = array("name"=> _("Add to Smart Block"), "icon" => "add-playlist", "icon" => "copy");
  178. }
  179. }
  180. }
  181. if ($isAdminOrPM || $file->getFileOwnerId() == $user->getId()) {
  182. $menu["del"] = array("name"=> _("Delete"), "icon" => "delete", "url" => $baseUrl."library/delete");
  183. $menu["edit"] = array("name"=> _("Edit Metadata"), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}");
  184. }
  185. $url = $file->getRelativeFileUrl($baseUrl).'/download/true';
  186. $menu["download"] = array("name" => _("Download"), "icon" => "download", "url" => $url);
  187. } elseif ($type === "playlist" || $type === "block") {
  188. if ($type === 'playlist') {
  189. $obj = new Application_Model_Playlist($id);
  190. $menu["duplicate"] = array("name" => _("Duplicate Playlist"), "icon" => "edit", "url" => $baseUrl."library/duplicate");
  191. } elseif ($type === 'block') {
  192. $obj = new Application_Model_Block($id);
  193. if (!$obj->isStatic()) {
  194. unset($menu["play"]);
  195. }
  196. if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") {
  197. if ($obj_sess->type === "playlist") {
  198. $menu["pl_add"] = array("name"=> _("Add to Playlist"), "icon" => "add-playlist", "icon" => "copy");
  199. }
  200. }
  201. }
  202. if ($obj_sess->id !== $id && $screen == "playlist") {
  203. if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
  204. $menu["edit"] = array("name"=> _("Edit"), "icon" => "edit");
  205. }
  206. }
  207. if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
  208. $menu["del"] = array("name"=> _("Delete"), "icon" => "delete", "url" => $baseUrl."library/delete");
  209. }
  210. } elseif ($type == "stream") {
  211. $webstream = CcWebstreamQuery::create()->findPK($id);
  212. $obj = new Application_Model_Webstream($webstream);
  213. $menu["play"]["mime"] = $webstream->getDbMime();
  214. if (isset($obj_sess->id) && $screen == "playlist") {
  215. if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
  216. if ($obj_sess->type === "playlist") {
  217. $menu["pl_add"] = array("name"=> _("Add to Playlist"), "icon" => "add-playlist", "icon" => "copy");
  218. }
  219. }
  220. }
  221. if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
  222. if ($screen == "playlist") {
  223. $menu["edit"] = array("name"=> _("Edit"), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}");
  224. }
  225. $menu["del"] = array("name"=> _("Delete"), "icon" => "delete", "url" => $baseUrl."library/delete");
  226. }
  227. }
  228. //SOUNDCLOUD MENU OPTIONS
  229. if ($type === "audioclip" && Application_Model_Preference::GetUploadToSoundcloudOption()) {
  230. //create a menu separator
  231. $menu["sep1"] = "-----------";
  232. //create a sub menu for Soundcloud actions.
  233. $menu["soundcloud"] = array("name" => _("Soundcloud"), "icon" => "soundcloud", "items" => array());
  234. $scid = $file->getSoundCloudId();
  235. if ($scid > 0) {
  236. $url = $file->getSoundCloudLinkToFile();
  237. $menu["soundcloud"]["items"]["view"] = array("name" => _("View on Soundcloud"), "icon" => "soundcloud", "url" => $url);
  238. }
  239. if (!is_null($scid)) {
  240. $text = _("Re-upload to SoundCloud");
  241. } else {
  242. $text = _("Upload to SoundCloud");
  243. }
  244. $menu["soundcloud"]["items"]["upload"] = array("name" => $text, "icon" => "soundcloud", "url" => $baseUrl."library/upload-file-soundcloud/id/{$id}");
  245. }
  246. if (empty($menu)) {
  247. $menu["noaction"] = array("name"=>_("No action available"));
  248. }
  249. $this->view->items = $menu;
  250. }
  251. public function deleteAction()
  252. {
  253. //array containing id and type of media to delete.
  254. $mediaItems = $this->_getParam('media', null);
  255. $user = Application_Model_User::getCurrentUser();
  256. //$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
  257. $files = array();
  258. $playlists = array();
  259. $blocks = array();
  260. $streams = array();
  261. $message = null;
  262. $noPermissionMsg = _("You don't have permission to delete selected items.");
  263. foreach ($mediaItems as $media) {
  264. if ($media["type"] === "audioclip") {
  265. $files[] = intval($media["id"]);
  266. } elseif ($media["type"] === "playlist") {
  267. $playlists[] = intval($media["id"]);
  268. } elseif ($media["type"] === "block") {
  269. $blocks[] = intval($media["id"]);
  270. } elseif ($media["type"] === "stream") {
  271. $streams[] = intval($media["id"]);
  272. }
  273. }
  274. try {
  275. Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
  276. } catch (PlaylistNoPermissionException $e) {
  277. $message = $noPermissionMsg;
  278. }
  279. try {
  280. Application_Model_Block::deleteBlocks($blocks, $user->getId());
  281. } catch (BlockNoPermissionException $e) {
  282. $message = $noPermissionMsg;
  283. } catch (Exception $e) {
  284. //TODO: warn user that not all blocks could be deleted.
  285. }
  286. try {
  287. Application_Model_Webstream::deleteStreams($streams, $user->getId());
  288. } catch (WebstreamNoPermissionException $e) {
  289. $message = $noPermissionMsg;
  290. } catch (Exception $e) {
  291. //TODO: warn user that not all streams could be deleted.
  292. Logging::info($e);
  293. }
  294. foreach ($files as $id) {
  295. $file = Application_Model_StoredFile::RecallById($id);
  296. if (isset($file)) {
  297. try {
  298. $res = $file->delete();
  299. } catch (FileNoPermissionException $e) {
  300. $message = $noPermissionMsg;
  301. } catch (Exception $e) {
  302. //could throw a scheduled in future exception.
  303. $message = _("Could not delete some scheduled files.");
  304. Logging::debug($e->getMessage());
  305. }
  306. }
  307. }
  308. if (isset($message)) {
  309. $this->view->message = $message;
  310. }
  311. }
  312. // duplicate playlist
  313. public function duplicateAction(){
  314. $params = $this->getRequest()->getParams();
  315. $id = $params['id'];
  316. $originalPl = new Application_Model_Playlist($id);
  317. $newPl = new Application_Model_Playlist();
  318. $contents = $originalPl->getContents();
  319. foreach ($contents as &$c) {
  320. if ($c['type'] == '0') {
  321. $c[1] = 'audioclip';
  322. } else if ($c['type'] == '2') {
  323. $c[1] = 'block';
  324. } else if ($c['type'] == '1') {
  325. $c[1] = 'stream';
  326. }
  327. $c[0] = $c['item_id'];
  328. }
  329. $newPl->addAudioClips($contents, null, 'before');
  330. $newPl->setCreator(Application_Model_User::getCurrentUser()->getId());
  331. $newPl->setDescription($originalPl->getDescription());
  332. list($plFadeIn, ) = $originalPl->getFadeInfo(0);
  333. list(, $plFadeOut) = $originalPl->getFadeInfo($originalPl->getSize()-1);
  334. $newPl->setfades($plFadeIn, $plFadeOut);
  335. $newPl->setName(sprintf(_("Copy of %s"), $originalPl->getName()));
  336. }
  337. public function contentsFeedAction()
  338. {
  339. $params = $this->getRequest()->getParams();
  340. # terrible name for the method below. it does not only search files.
  341. $r = Application_Model_StoredFile::searchLibraryFiles($params);
  342. $this->view->sEcho = $r["sEcho"];
  343. $this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
  344. $this->view->iTotalRecords = $r["iTotalRecords"];
  345. $this->view->files = $r["aaData"];
  346. }
  347. public function editFileMdAction()
  348. {
  349. $user = Application_Model_User::getCurrentUser();
  350. $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
  351. $request = $this->getRequest();
  352. $file_id = $this->_getParam('id', null);
  353. $file = Application_Model_StoredFile::RecallById($file_id);
  354. if (!$isAdminOrPM && $file->getFileOwnerId() != $user->getId()) {
  355. return;
  356. }
  357. $form = new Application_Form_EditAudioMD();
  358. $form->startForm($file_id);
  359. $form->populate($file->getDbColMetadata());
  360. if ($request->isPost()) {
  361. $js = $this->_getParam('data');
  362. $serialized = array();
  363. //need to convert from serialized jQuery array.
  364. foreach ($js as $j) {
  365. $serialized[$j["name"]] = $j["value"];
  366. }
  367. if ($form->isValid($serialized)) {
  368. $formValues = $this->_getParam('data', null);
  369. $formdata = array();
  370. foreach ($formValues as $val) {
  371. $formdata[$val["name"]] = $val["value"];
  372. }
  373. $file->setDbColMetadata($formdata);
  374. $data = $file->getMetadata();
  375. // set MDATA_KEY_FILEPATH
  376. $data['MDATA_KEY_FILEPATH'] = $file->getFilePath();
  377. Logging::info($data['MDATA_KEY_FILEPATH']);
  378. Application_Model_RabbitMq::SendMessageToMediaMonitor("md_update", $data);
  379. $this->_redirect('Library');
  380. }
  381. }
  382. $this->view->form = $form;
  383. $this->view->dialog = $this->view->render('library/edit-file-md.phtml');
  384. }
  385. public function getFileMetadataAction()
  386. {
  387. $id = $this->_getParam('id');
  388. $type = $this->_getParam('type');
  389. try {
  390. if ($type == "audioclip") {
  391. $file = Application_Model_StoredFile::RecallById($id);
  392. $this->view->type = $type;
  393. $md = $file->getMetadata();
  394. foreach ($md as $key => $value) {
  395. if ($key == 'MDATA_KEY_DIRECTORY') {
  396. $musicDir = Application_Model_MusicDir::getDirByPK($value);
  397. $md['MDATA_KEY_FILEPATH'] = Application_Common_OsPath::join($musicDir->getDirectory(), $md['MDATA_KEY_FILEPATH']);
  398. }
  399. }
  400. $formatter = new SamplerateFormatter($md["MDATA_KEY_SAMPLERATE"]);
  401. $md["MDATA_KEY_SAMPLERATE"] = $formatter->format();
  402. $formatter = new BitrateFormatter($md["MDATA_KEY_BITRATE"]);
  403. $md["MDATA_KEY_BITRATE"] = $formatter->format();
  404. $formatter = new LengthFormatter($md["MDATA_KEY_DURATION"]);
  405. $md["MDATA_KEY_DURATION"] = $formatter->format();
  406. $this->view->md = $md;
  407. } elseif ($type == "playlist") {
  408. $file = new Application_Model_Playlist($id);
  409. $this->view->type = $type;
  410. $md = $file->getAllPLMetaData();
  411. $formatter = new LengthFormatter($md["dcterms:extent"]);
  412. $md["dcterms:extent"] = $formatter->format();
  413. $this->view->md = $md;
  414. $this->view->contents = $file->getContents();
  415. } elseif ($type == "block") {
  416. $block = new Application_Model_Block($id);
  417. $this->view->type = $type;
  418. $md = $block->getAllPLMetaData();
  419. $formatter = new LengthFormatter($md["dcterms:extent"]);
  420. $md["dcterms:extent"] = $formatter->format();
  421. $this->view->md = $md;
  422. if ($block->isStatic()) {
  423. $this->view->blType = 'Static';
  424. $this->view->contents = $block->getContents();
  425. } else {
  426. $this->view->blType = 'Dynamic';
  427. $this->view->contents = $block->getCriteria();
  428. }
  429. $this->view->block = $block;
  430. } elseif ($type == "stream") {
  431. $webstream = CcWebstreamQuery::create()->findPK($id);
  432. $ws = new Application_Model_Webstream($webstream);
  433. $md = $ws->getMetadata();
  434. $this->view->md = $md;
  435. $this->view->type = $type;
  436. }
  437. } catch (Exception $e) {
  438. Logging::info($e->getMessage());
  439. }
  440. }
  441. public function uploadFileSoundcloudAction()
  442. {
  443. $id = $this->_getParam('id');
  444. Application_Model_Soundcloud::uploadSoundcloud($id);
  445. // we should die with ui info
  446. $this->_helper->json->sendJson(null);
  447. }
  448. public function getUploadToSoundcloudStatusAction()
  449. {
  450. $id = $this->_getParam('id');
  451. $type = $this->_getParam('type');
  452. if ($type == "show") {
  453. $show_instance = new Application_Model_ShowInstance($id);
  454. $this->view->sc_id = $show_instance->getSoundCloudFileId();
  455. $file = $show_instance->getRecordedFile();
  456. $this->view->error_code = $file->getSoundCloudErrorCode();
  457. $this->view->error_msg = $file->getSoundCloudErrorMsg();
  458. } elseif ($type == "file") {
  459. $file = Application_Model_StoredFile::RecallById($id);
  460. $this->view->sc_id = $file->getSoundCloudId();
  461. $this->view->error_code = $file->getSoundCloudErrorCode();
  462. $this->view->error_msg = $file->getSoundCloudErrorMsg();
  463. } else {
  464. Logging::warn("Trying to upload unknown type: $type with id: $id");
  465. }
  466. }
  467. }