public function resizeShowAction() { $deltaDay = $this->_getParam('day'); $deltaMin = $this->_getParam('min'); $showId = $this->_getParam('showId'); $instanceId = $this->_getParam('instanceId'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { try { $show = new Application_Model_Show($showId); } catch (Exception $e) { $this->view->show_error = true; return false; } $error = $show->resizeShow($deltaDay, $deltaMin, $instanceId); } if (isset($error)) { $this->view->error = $error; } }
public function populateShowFormAction() { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled' ? false : true; $showInstanceId = $this->_getParam('id'); $this->view->action = "edit-show"; try { $showInstance = new Application_Model_ShowInstance($showInstanceId); } catch (Exception $e) { $this->view->show_error = true; return false; } $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $isDJ = $user->isHostOfShow($showInstance->getShowId()); if (!($isAdminOrPM || $isDJ)) { return; } if ($isDJ) { $this->view->action = "dj-edit-show"; } $formWhat = new Application_Form_AddShowWhat(); $formWho = new Application_Form_AddShowWho(); $formWhen = new Application_Form_AddShowWhen(); $formRepeats = new Application_Form_AddShowRepeats(); $formStyle = new Application_Form_AddShowStyle(); $formLive = new Application_Form_AddShowLiveStream(); $formWhat->removeDecorator('DtDdWrapper'); $formWho->removeDecorator('DtDdWrapper'); $formWhen->removeDecorator('DtDdWrapper'); $formRepeats->removeDecorator('DtDdWrapper'); $formStyle->removeDecorator('DtDdWrapper'); $this->view->what = $formWhat; $this->view->when = $formWhen; $this->view->repeats = $formRepeats; $this->view->who = $formWho; $this->view->style = $formStyle; $this->view->live = $formLive; $this->view->addNewShow = false; $show = new Application_Model_Show($showInstance->getShowId()); $formWhat->populate(array('add_show_id' => $show->getId(), 'add_show_instance_id' => $showInstanceId, 'add_show_name' => $show->getName(), 'add_show_url' => $show->getUrl(), 'add_show_genre' => $show->getGenre(), 'add_show_description' => $show->getDescription())); $startsDateTime = new DateTime($show->getStartDate() . " " . $show->getStartTime(), new DateTimeZone("UTC")); $endsDateTime = new DateTime($show->getEndDate() . " " . $show->getEndTime(), new DateTimeZone("UTC")); $startsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $endsDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $formWhen->populate(array('add_show_start_date' => $startsDateTime->format("Y-m-d"), 'add_show_start_time' => $startsDateTime->format("H:i"), 'add_show_end_date_no_repeat' => $endsDateTime->format("Y-m-d"), 'add_show_end_time' => $endsDateTime->format("H:i"), 'add_show_duration' => $show->getDuration(true), 'add_show_repeats' => $show->isRepeating() ? 1 : 0)); if ($show->isStartDateTimeInPast()) { // for a non-repeating show, we should never allow user to change the start time. // for the repeating show, we should allow because the form works as repeating template form if (!$showInstance->getShow()->isRepeating()) { $formWhen->disableStartDateAndTime(); } else { $formWhen->getElement('add_show_start_date')->setOptions(array('disabled' => true)); } } //need to get the days of the week in the php timezone (for the front end). $days = array(); $showDays = CcShowDaysQuery::create()->filterByDbShowId($showInstance->getShowId())->find(); foreach ($showDays as $showDay) { $showStartDay = new DateTime($showDay->getDbFirstShow(), new DateTimeZone($showDay->getDbTimezone())); $showStartDay->setTimezone(new DateTimeZone(date_default_timezone_get())); array_push($days, $showStartDay->format('w')); } $displayedEndDate = new DateTime($show->getRepeatingEndDate(), new DateTimeZone($showDays[0]->getDbTimezone())); $displayedEndDate->sub(new DateInterval("P1D")); //end dates are stored non-inclusively. $displayedEndDate->setTimezone(new DateTimeZone(date_default_timezone_get())); $formRepeats->populate(array('add_show_repeat_type' => $show->getRepeatType(), 'add_show_day_check' => $days, 'add_show_end_date' => $displayedEndDate->format("Y-m-d"), 'add_show_no_end' => $show->getRepeatingEndDate() == '')); $hosts = array(); $showHosts = CcShowHostsQuery::create()->filterByDbShow($showInstance->getShowId())->find(); foreach ($showHosts as $showHost) { array_push($hosts, $showHost->getDbHost()); } $formWho->populate(array('add_show_hosts' => $hosts)); $formStyle->populate(array('add_show_background_color' => $show->getBackgroundColor(), 'add_show_color' => $show->getColor())); $formLive->populate($show->getLiveStreamInfo()); if (!$isSaas) { $formRecord = new Application_Form_AddShowRR(); $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); $formRebroadcast = new Application_Form_AddShowRebroadcastDates(); $formRecord->removeDecorator('DtDdWrapper'); $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper'); $formRebroadcast->removeDecorator('DtDdWrapper'); $this->view->rr = $formRecord; $this->view->absoluteRebroadcast = $formAbsoluteRebroadcast; $this->view->rebroadcast = $formRebroadcast; $formRecord->populate(array('add_show_record' => $show->isRecorded(), 'add_show_rebroadcast' => $show->isRebroadcast())); $formRecord->getElement('add_show_record')->setOptions(array('disabled' => true)); $rebroadcastsRelative = $show->getRebroadcastsRelative(); $rebroadcastFormValues = array(); $i = 1; foreach ($rebroadcastsRelative as $rebroadcast) { $rebroadcastFormValues["add_show_rebroadcast_date_{$i}"] = $rebroadcast['day_offset']; $rebroadcastFormValues["add_show_rebroadcast_time_{$i}"] = Application_Common_DateHelper::removeSecondsFromTime($rebroadcast['start_time']); $i++; } $formRebroadcast->populate($rebroadcastFormValues); $rebroadcastsAbsolute = $show->getRebroadcastsAbsolute(); $rebroadcastAbsoluteFormValues = array(); $i = 1; foreach ($rebroadcastsAbsolute as $rebroadcast) { $rebroadcastAbsoluteFormValues["add_show_rebroadcast_date_absolute_{$i}"] = $rebroadcast['start_date']; $rebroadcastAbsoluteFormValues["add_show_rebroadcast_time_absolute_{$i}"] = $rebroadcast['start_time']; $i++; } $formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues); if (!$isAdminOrPM) { $formRecord->disable(); $formAbsoluteRebroadcast->disable(); $formRebroadcast->disable(); } } if (!$isAdminOrPM) { $formWhat->disable(); $formWho->disable(); $formWhen->disable(); $formRepeats->disable(); $formStyle->disable(); } $this->view->newForm = $this->view->render('schedule/add-show-form.phtml'); $this->view->entries = 5; }
public static function addUpdateShow($data, $controller, $validateStartDate, $originalStartDate = null, $update = false, $instanceId = null) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $isSaas = Application_Model_Preference::GetPlanLevel() != 'disabled'; $record = false; $formWhat = new Application_Form_AddShowWhat(); $formWho = new Application_Form_AddShowWho(); $formWhen = new Application_Form_AddShowWhen(); $formRepeats = new Application_Form_AddShowRepeats(); $formStyle = new Application_Form_AddShowStyle(); $formLive = new Application_Form_AddShowLiveStream(); $formWhat->removeDecorator('DtDdWrapper'); $formWho->removeDecorator('DtDdWrapper'); $formWhen->removeDecorator('DtDdWrapper'); $formRepeats->removeDecorator('DtDdWrapper'); $formStyle->removeDecorator('DtDdWrapper'); $formLive->removeDecorator('DtDdWrapper'); $what = $formWhat->isValid($data); $when = $formWhen->isValid($data); $live = $formLive->isValid($data); if ($when) { $when = $formWhen->checkReliantFields($data, $validateStartDate, $originalStartDate, $update, $instanceId); } //The way the following code works is that is parses the hour and //minute from a string with the format "1h 20m" or "2h" or "36m". //So we are detecting whether an hour or minute value exists via strpos //and then parse appropriately. A better way to do this in the future is //actually pass the format from javascript in the format hh:mm so we don't //have to do this extra String parsing. $hPos = strpos($data["add_show_duration"], 'h'); $mPos = strpos($data["add_show_duration"], 'm'); $hValue = 0; $mValue = 0; if ($hPos !== false) { $hValue = trim(substr($data["add_show_duration"], 0, $hPos)); } if ($mPos !== false) { $hPos = $hPos === false ? 0 : $hPos + 1; $mValue = trim(substr($data["add_show_duration"], $hPos, -1)); } $data["add_show_duration"] = $hValue . ":" . $mValue; if (!$isSaas) { $formRecord = new Application_Form_AddShowRR(); $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); $formRebroadcast = new Application_Form_AddShowRebroadcastDates(); $formRecord->removeDecorator('DtDdWrapper'); $formAbsoluteRebroadcast->removeDecorator('DtDdWrapper'); $formRebroadcast->removeDecorator('DtDdWrapper'); $record = $formRecord->isValid($data); } if ($data["add_show_repeats"]) { $repeats = $formRepeats->isValid($data); if ($repeats) { $repeats = $formRepeats->checkReliantFields($data); } if (!$isSaas) { $formAbsoluteRebroadcast->reset(); //make it valid, results don't matter anyways. $rebroadAb = 1; if ($data["add_show_rebroadcast"]) { $rebroad = $formRebroadcast->isValid($data); if ($rebroad) { $rebroad = $formRebroadcast->checkReliantFields($data); } } else { $rebroad = 1; } } } else { $repeats = 1; if (!$isSaas) { $formRebroadcast->reset(); //make it valid, results don't matter anyways. $rebroad = 1; if ($data["add_show_rebroadcast"]) { $rebroadAb = $formAbsoluteRebroadcast->isValid($data); if ($rebroadAb) { $rebroadAb = $formAbsoluteRebroadcast->checkReliantFields($data); } } else { $rebroadAb = 1; } } } $who = $formWho->isValid($data); $style = $formStyle->isValid($data); if ($what && $when && $repeats && $who && $style && $live) { if (!$isSaas) { if ($record && $rebroadAb && $rebroad) { if ($isAdminOrPM) { Application_Model_Show::create($data); } //send back a new form for the user. Application_Model_Schedule::createNewFormSections($controller->view); //$controller->view->newForm = $controller->view->render('schedule/add-show-form.phtml'); return true; } else { $controller->view->what = $formWhat; $controller->view->when = $formWhen; $controller->view->repeats = $formRepeats; $controller->view->who = $formWho; $controller->view->style = $formStyle; $controller->view->rr = $formRecord; $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast; $controller->view->rebroadcast = $formRebroadcast; $controller->view->live = $formLive; //$controller->view->addNewShow = !$editShow; //$controller->view->form = $controller->view->render('schedule/add-show-form.phtml'); return false; } } else { if ($isAdminOrPM) { Application_Model_Show::create($data); } //send back a new form for the user. Application_Model_Schedule::createNewFormSections($controller->view); //$controller->view->newForm = $controller->view->render('schedule/add-show-form.phtml'); return true; } } else { $controller->view->what = $formWhat; $controller->view->when = $formWhen; $controller->view->repeats = $formRepeats; $controller->view->who = $formWho; $controller->view->style = $formStyle; $controller->view->live = $formLive; if (!$isSaas) { $controller->view->rr = $formRecord; $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast; $controller->view->rebroadcast = $formRebroadcast; } //$controller->view->addNewShow = !$editShow; //$controller->view->form = $controller->view->render('schedule/add-show-form.phtml'); return false; } }
/** * Delete playlists that match the ids.. * @param array $p_ids */ public static function deletePlaylists($p_ids, $p_userId) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); // get only the files from the playlists // we are about to delete $itemsToDelete = CcPlaylistcontentsQuery::create()->filterByDbPlaylistId($p_ids)->filterByDbFileId(null, Criteria::NOT_EQUAL)->find(); $updateIsPlaylistFlag = false; if (!$isAdminOrPM) { $leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId); if (count($leftOver) == 0) { CcPlaylistQuery::create()->findPKs($p_ids)->delete(); $updateIsPlaylistFlag = true; } else { throw new PlaylistNoPermissionException(); } } else { CcPlaylistQuery::create()->findPKs($p_ids)->delete(); $updateIsPlaylistFlag = true; } if ($updateIsPlaylistFlag) { // update is_playlist flag in cc_files Application_Model_StoredFile::setIsPlaylist($itemsToDelete, 'playlist', false); } }
/** * Delete blocks that match the ids.. * @param array $p_ids */ public static function deleteBlocks($p_ids, $p_userId) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); if (!$isAdminOrPM) { $leftOver = self::blocksNotOwnedByUser($p_ids, $p_userId); if (count($leftOver) == 0) { CcBlockQuery::create()->findPKs($p_ids)->delete(); } else { throw new BlockNoPermissionException(); } } else { CcBlockQuery::create()->findPKs($p_ids)->delete(); } }
public function contextMenuAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); //playlist||timeline $screen = $this->_getParam('screen'); $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); $menu = array(); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); //Open a jPlayer window and play the audio clip. $menu["play"] = array("name" => "Preview", "icon" => "play", "disabled" => false); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); if ($type === "audioclip") { $file = Application_Model_StoredFile::Recall($id); $menu["play"]["mime"] = $file->getPropelOrm()->getDbMime(); if (isset($obj_sess->id) && $screen == "playlist") { // if the user is not admin or pm, check the creator and see if this person owns the playlist or Block if ($obj_sess->type == 'playlist') { $obj = new Application_Model_Playlist($obj_sess->id); } elseif ($obj_sess->type == 'block') { $obj = new Application_Model_Block($obj_sess->id); } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); } elseif ($obj_sess->type === "block") { $menu["pl_add"] = array("name" => "Add to Smart Block", "icon" => "add-playlist", "icon" => "copy"); } } } if ($isAdminOrPM) { $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete"); $menu["edit"] = array("name" => "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); } $url = $file->getRelativeFileUrl($baseUrl) . '/download/true'; $menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url); } elseif ($type === "playlist" || $type === "block") { if ($type === 'playlist') { $obj = new Application_Model_Playlist($id); } elseif ($type === 'block') { $obj = new Application_Model_Block($id); if (!$obj->isStatic()) { unset($menu["play"]); } if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); } } } if ($obj_sess->id !== $id && $screen == "playlist") { if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { $menu["edit"] = array("name" => "Edit", "icon" => "edit"); } } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete"); } } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPK($id); $obj = new Application_Model_Webstream($webstream); if (isset($obj_sess->id) && $screen == "playlist") { if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); } } } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($screen == "playlist") { $menu["edit"] = array("name" => "Edit", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); } $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete"); } } //SOUNDCLOUD MENU OPTIONS if ($type === "audioclip" && Application_Model_Preference::GetUploadToSoundcloudOption()) { //create a menu separator $menu["sep1"] = "-----------"; //create a sub menu for Soundcloud actions. $menu["soundcloud"] = array("name" => "Soundcloud", "icon" => "soundcloud", "items" => array()); $scid = $file->getSoundCloudId(); if ($scid > 0) { $url = $file->getSoundCloudLinkToFile(); $menu["soundcloud"]["items"]["view"] = array("name" => "View on Soundcloud", "icon" => "soundcloud", "url" => $url); } if (!is_null($scid)) { $text = "Re-upload to SoundCloud"; } else { $text = "Upload to SoundCloud"; } $menu["soundcloud"]["items"]["upload"] = array("name" => $text, "icon" => "soundcloud", "url" => "/library/upload-file-soundcloud/id/{$id}"); } if (empty($menu)) { $menu["noaction"] = array("name" => "No action available"); } $this->view->items = $menu; }
/** * Delete stored virtual file * * @param boolean $p_deleteFile * */ public function delete() { $filepath = $this->getFilePath(); // Check if the file is scheduled to be played in the future if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { throw new DeleteScheduledFileException(); } $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); if (!$isAdminOrPM && $this->getFileOwnerId() != $user->getId()) { throw new FileNoPermissionException(); } $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); $type = $music_dir->getType(); if (file_exists($filepath) && $type == "stor") { $data = array("filepath" => $filepath, "delete" => 1); try { Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); } catch (Exception $e) { Logging::error($e->getMessage()); return; } } // set hidden flag to true $this->_file->setDbHidden(true); $this->_file->save(); // need to explicitly update any playlist's and block's length // that contains the file getting deleted $fileId = $this->_file->getDbId(); $plRows = CcPlaylistcontentsQuery::create()->filterByDbFileId()->find(); foreach ($plRows as $row) { $pl = CcPlaylistQuery::create()->filterByDbId($row->getDbPlaylistId($fileId))->findOne(); $pl->setDbLength($pl->computeDbLength(Propel::getConnection(CcPlaylistPeer::DATABASE_NAME))); $pl->save(); } $blRows = CcBlockcontentsQuery::create()->filterByDbFileId($fileId)->find(); foreach ($blRows as $row) { $bl = CcBlockQuery::create()->filterByDbId($row->getDbBlockId())->findOne(); $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME))); $bl->save(); } }