Ejemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $videoItems = array(array("Breakfast Show!", "This is the breakfast show description."), array("BBC News"), array("BBC News 24"), array("Dragons Den"), array("Mock The Week!"), array("Some Other Show"), array("Soundbooth Sessions"), array("The LA1 Show"), array("The One Show"), array("Star Wars"), array("Sugar TV!"), array("The Incredibles"), array("University Challenge"), array("Countdown"), array("8 out of 10 Cats Does Countdown"), array("Jurassic Park"), array("Jurassic Park 2"), array("Shrek"), array("Shrek 2"), array("Shrek 3"), array("Mission Impossible"));
     foreach ($videoItems as $a) {
         $mediaItemVideo = new MediaItemVideo(array("is_live_recording" => rand(0, 1) ? true : false, "time_recorded" => Carbon::now()->subHour(), "description" => rand(0, 4) === 0 ? "A description that should override the general media item one." : null, "enabled" => rand(0, 1) ? true : false));
         $mediaItem = new MediaItem(array("name" => $a[0], "description" => count($a) >= 2 ? $a[1] : null, "enabled" => rand(0, 1) ? true : false, "scheduled_publish_time" => Carbon::now()));
         DB::transaction(function () use(&$mediaItem, &$mediaItemVideo) {
             $mediaItem->save();
             $mediaItem->videoItem()->save($mediaItemVideo);
         });
         $this->addLikes($mediaItem);
         $this->addComments($mediaItem);
     }
     //$mediaItemLiveStream = new MediaItemLiveStream(array(
     //	"enabled"	=>	true
     //));
     $mediaItem = new MediaItem(array("name" => "Lunchtime Show!", "description" => "This is the lunchtime show description.", "enabled" => true, "scheduled_publish_time" => Carbon::now()));
     DB::transaction(function () use(&$mediaItem, &$mediaItemLiveStream) {
         $mediaItem->save();
         //	$mediaItem->liveStreamItem()->save($mediaItemLiveStream);
     });
     $this->addLikes($mediaItem);
     $this->addComments($mediaItem);
     $this->command->info('Media items created!');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!DebugHelpers::shouldSiteBeLive()) {
         $this->info('Not running because site should not be live at the moment.');
         return;
     }
     $this->info('Looking for media items that are starting in 15 minutes.');
     $fifteenMinsAhead = Carbon::now()->addMinutes(15);
     $lowerBound = (new Carbon($fifteenMinsAhead))->subSeconds(90);
     $upperBound = new Carbon($fifteenMinsAhead);
     // media items which have a live stream going live in 15 minutes.
     $mediaItemsStartingInFifteen = DB::transaction(function () use(&$lowerBound, &$upperBound) {
         $mediaItemsStartingInFifteen = MediaItem::accessible()->whereHas("liveStreamItem", function ($q) {
             $q->accessible()->notLive();
         })->whereHas("emailTasksMediaItem", function ($q2) {
             $q2->where("message_type_id", EmailHelpers::getMessageTypeIds()['liveInFifteen'])->where("created_at", ">=", Carbon::now()->subMinutes(40));
         }, "=", 0)->where("email_notifications_enabled", true)->where("scheduled_publish_time", ">=", $lowerBound)->where("scheduled_publish_time", "<", $upperBound)->orderBy("scheduled_publish_time", "desc")->lockForUpdate()->get();
         foreach ($mediaItemsStartingInFifteen as $a) {
             $emailTask = new EmailTasksMediaItem(array("message_type_id" => EmailHelpers::getMessageTypeIds()['liveInFifteen']));
             // create an entry in the tasks table for the emails that are going to be sent
             $a->emailTasksMediaItem()->save($emailTask);
         }
         return $mediaItemsStartingInFifteen;
     });
     foreach ($mediaItemsStartingInFifteen as $a) {
         $this->info("Building and sending email for media item with id " . $a->id . " and name \"" . $a->name . "\" which is starting in 15 minutes.");
         EmailHelpers::sendMediaItemEmail($a, 'LA1:TV Live Shortly With "{title}"', "Live shortly!", "We will be streaming live in less than 15 minutes!");
         $this->info("Sent email to users.");
     }
     $this->info("Finished.");
 }
Ejemplo n.º 3
0
 protected static function boot()
 {
     parent::boot();
     self::saving(function ($model) {
         if ($model->enabled && is_null($model->scheduled_publish_time)) {
             throw new Exception("A MediaItem which is enabled must have a scheduled publish time.");
         }
         // transaction ended in "saved" event
         // needed to make sure if search index version number is incremented it
         // takes effect at the same time that the rest of the media item is updated
         DB::beginTransaction();
         // assume that something has changed and force ths item to be reindexed
         $a = MediaItem::find(intval($model->id));
         // $a may be null if this item is currently being created
         // when the item is being created pending_search_index_version defaults to 1
         // meaning the item will be indexed
         if (!is_null($a)) {
             // make sure get latest version number. The version in $model might have changed before the transaction started
             $currentPendingIndexVersion = intval($a->pending_search_index_version);
             $model->pending_search_index_version = $currentPendingIndexVersion + 1;
         }
         return true;
     });
     self::saved(function ($model) {
         DB::commit();
     });
 }
Ejemplo n.º 4
0
 public function fire($job, $data)
 {
     if (!DebugHelpers::shouldSiteBeLive()) {
         $job->release();
         // put the job back on the queue
         return;
     }
     // remove the job from the queue to make sure it only runs once even if an exception is thrown
     $job->delete();
     $mediaItemId = $data['mediaItemId'];
     Log::info("Starting job to send email for media item with id " . $mediaItemId . " which has gone live.");
     // retrieve the media item
     $mediaItem = DB::transaction(function () use(&$mediaItemId) {
         $mediaItem = MediaItem::accessible()->whereHas("liveStreamItem", function ($q) {
             $q->accessible()->live();
         })->whereHas("emailTasksMediaItem", function ($q2) {
             $q2->where("message_type_id", EmailHelpers::getMessageTypeIds()['liveNow'])->where("created_at", ">=", Carbon::now()->subMinutes(40));
         }, "=", 0)->where("email_notifications_enabled", true)->where("id", $mediaItemId)->lockForUpdate()->first();
         if (!is_null($mediaItem)) {
             $emailTask = new EmailTasksMediaItem(array("message_type_id" => EmailHelpers::getMessageTypeIds()['liveNow']));
             // create an entry in the tasks table for the emails that are going to be sent
             $mediaItem->emailTasksMediaItem()->save($emailTask);
         }
         return $mediaItem;
     });
     if (!is_null($mediaItem)) {
         EmailHelpers::sendMediaItemEmail($mediaItem, 'LA1:TV Live Now With "{title}"', "Live now!", "We are streaming live right now!");
     }
     Log::info("Finished job to send email for media item with id " . $mediaItemId . " which has gone live.");
 }
Ejemplo n.º 5
0
 public function handleMediaItemRequest($mediaItemId)
 {
     $mediaItem = MediaItem::find($mediaItemId);
     if (is_null($mediaItem) || !$mediaItem->getIsAccessible()) {
         $this->do404Response();
         return;
     }
     $playlist = $mediaItem->getDefaultPlaylist();
     if (is_null($playlist)) {
         $this->do404Response();
         return;
     }
     $this->prepareResponse($playlist, $mediaItem);
 }
 private function checkMediaItemsForReindex()
 {
     // check for media items which which should be reindexed because their accessibiliy has changed
     $mediaItemsToReindex = MediaItem::upToDateInIndex()->where(function ($q) {
         $q->where(function ($q) {
             $q->accessible()->where("in_index", false);
         })->orWhere(function ($q) {
             $q->notAccessible()->where("in_index", true);
         });
     })->get();
     foreach ($mediaItemsToReindex as $a) {
         // touching will increment the version number
         $a->touch();
         $this->info("Media item with id " . $a->id . " queued for reindex.");
     }
 }
Ejemplo n.º 7
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // presumes that media items already exist and ids from autoincrement
     DB::transaction(function () {
         $playlist = new Playlist(array("name" => "Roses 2014!", "enabled" => true, "description" => "Description about roses 2014 series.", "series_no" => 1, "scheduled_publish_time" => Carbon::now()));
         $playlist->show()->associate(Show::find(1));
         $playlist->save();
         $playlist->mediaItems()->attach(MediaItem::find(1), array("position" => 0));
         $playlist->mediaItems()->attach(MediaItem::find(2), array("position" => 1));
     });
     DB::transaction(function () {
         $playlist = Playlist::create(array("name" => "Top Shows", "enabled" => true, "description" => "LA1:TV's top shows for 2014.", "scheduled_publish_time" => Carbon::now()));
         $playlist->mediaItems()->attach(MediaItem::find(2), array("position" => 0));
     });
     $this->command->info('Playlists created and media items added!');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!DebugHelpers::shouldSiteBeLive()) {
         $this->info('Not running because site should not be live at the moment.');
         return;
     }
     $this->info('Looking for media items which contain VOD which has just gone live.');
     // media items which have vod which is accessible, have the sent_vod_available_email flag set to 0, and have not had a email about this sent recently
     $mediaItems = DB::transaction(function () {
         $mediaItemsWantingEmail = array();
         $mediaItems = MediaItem::with("emailTasksMediaItem", "liveStreamItem")->accessible()->whereHas("videoItem", function ($q) {
             $q->live();
         })->where("email_notifications_enabled", true)->where("sent_vod_available_email", false)->lockForUpdate()->get();
         foreach ($mediaItems as $a) {
             // set the flag to say that this has been looked at and an email will probably be sent.
             $a->sent_vod_available_email = true;
             $a->save();
             $emailSentRecently = $a->emailTasksMediaItem()->where("created_at", ">=", Carbon::now()->subMinutes(15))->count() > 0;
             if ($emailSentRecently) {
                 continue;
             }
             $mediaItemsWantingEmail[] = $a;
             $emailTask = new EmailTasksMediaItem(array("message_type_id" => EmailHelpers::getMessageTypeIds()['availableNow']));
             // create an entry in the tasks table for the emails that are going to be sent
             $a->emailTasksMediaItem()->save($emailTask);
         }
         return $mediaItemsWantingEmail;
     });
     foreach ($mediaItems as $a) {
         $this->info("Building and sending email for media item with id " . $a->id . " and name \"" . $a->name . "\" which has VOD which has now gone live.");
         $title = null;
         $message = null;
         $liveStreamItem = $a->liveStreamItem;
         $hasBeenLive = !is_null($liveStreamItem) && $liveStreamItem->isOver();
         if ($hasBeenLive) {
             $title = "Did you miss our live show?";
             $message = "Watch it now on our website.";
         } else {
             $title = "New content available!";
             $message = "We now have new content available to watch on demand at our website.";
         }
         EmailHelpers::sendMediaItemEmail($a, '"{title}" Available Now From LA1:TV', $title, $message);
         $this->info("Sent email to users.");
     }
     $this->info("Finished.");
 }
Ejemplo n.º 9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     LiveStream::truncate();
     MediaItem::truncate();
     MediaItemComment::truncate();
     MediaItemLike::truncate();
     MediaItemLiveStream::truncate();
     MediaItemVideo::truncate();
     Permission::truncate();
     PermissionGroup::truncate();
     QualityDefinition::truncate();
     LiveStreamUri::truncate();
     Playlist::truncate();
     Show::truncate();
     SiteUser::truncate();
     User::truncate();
     VideoFile::truncate();
     DB::table("media_item_to_playlist")->truncate();
     DB::table("permission_to_group")->truncate();
     DB::table("user_to_group")->truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     $this->command->info('Tables truncated!');
 }
Ejemplo n.º 10
0
 public function getLatest()
 {
     $feed = Feed::make();
     // cache response for a minute
     $feed->setCache(Config::get("custom.feeds_cache_time", 'feeds-latest'));
     if (!$feed->isCached()) {
         $items = MediaItem::getCachedRecentItems();
         $feed->title = "LA1:TV's Latest Content";
         $feed->description = 'This feed contains the latest content that is published to our website.';
         $feed->logo = asset("/assets/img/logo.png");
         $feed->link = URL::route('home');
         $feed->setDateFormat('datetime');
         $feed->pubdate = Carbon::now();
         $feed->lang = 'en';
         $feed->setShortening(false);
         foreach ($items as $item) {
             $mediaItem = $item['mediaItem'];
             $scheduledPublishTime = new Carbon($mediaItem->scheduled_publish_time);
             // title, author, url, pubdate, description
             $feed->add($item['generatedName'] . " [" . $item['playlistName'] . "]", "LA1:TV", $item['uri'], $scheduledPublishTime, $mediaItem->description);
         }
     }
     return $feed->render('rss');
 }
 private function updateMediaItemsIndex()
 {
     $entries = ["toAdd" => [], "toRemove" => []];
     // in a transaction to make sure that version number that is returned is not one that
     // has been increased during a transaction which is stil in progress
     // mysql transaction isolation level should be REPEATABLE READ which will ensure that
     // the version number that is returned is the old one if it's currently being updated somewhere else,
     // until the update that is happening somewhere else is complete.
     $changedMediaItems = DB::transaction(function () {
         return MediaItem::with("playlists", "playlists.show")->needsReindexing()->get();
     });
     foreach ($changedMediaItems as $mediaItem) {
         if ($mediaItem->getIsAccessible()) {
             $entries["toAdd"][] = ["model" => $mediaItem, "data" => $this->getMediaItemData($mediaItem, $this->coverArtWidth, $this->coverArtHeight)];
         } else {
             // this item is no longer accessible so remove it from the index
             $entries["toRemove"][] = ["model" => $mediaItem];
         }
     }
     $this->syncIndexType("mediaItem", new MediaItem(), $entries);
 }
Ejemplo n.º 12
0
 public function getComingUpMediaItem()
 {
     return MediaItem::accessible()->whereHas("liveStreamItem", function ($q) {
         $q->accessible()->notLive()->whereHas("livestream", function ($q2) {
             // the live stream doesn't actually have to be accessible right now
             // the assumption is that it will be at the time this is due to go live
             $q2->where("id", intval($this->id));
         });
     })->orderBy("scheduled_publish_time", "desc")->first();
 }
Ejemplo n.º 13
0
 public function getIndex($dayGroupOffset = 0)
 {
     $dayGroupOffset = intval($dayGroupOffset);
     $daysPerPage = intval(Config::get("guide.daysPerPage"));
     $numPages = intval(Config::get("guide.numPages"));
     if (abs($dayGroupOffset) > $numPages) {
         App::abort(404);
     }
     $dayOffset = $dayGroupOffset * $daysPerPage;
     $startDate = Carbon::now()->startOfDay()->addDays($dayOffset);
     $endDate = Carbon::now()->startOfDay()->addDays($dayOffset + $daysPerPage);
     $mediaItems = MediaItem::with("liveStreamItem")->accessible()->scheduledPublishTimeBetweenDates($startDate, $endDate)->orderBy("scheduled_publish_time", "asc")->orderBy("name", "asc")->orderBy("description", "asc")->get();
     // of form ("dateStr", "mediaItems")
     $calendarData = array();
     $previousMediaItem = null;
     $lastDate = $startDate;
     foreach ($mediaItems as $a) {
         if (is_null($previousMediaItem) || $previousMediaItem->scheduled_publish_time->startOfDay()->timestamp !== $a->scheduled_publish_time->startOfDay()->timestamp) {
             // new day
             $calendarData[] = array("dateStr" => $this->getDateString($a->scheduled_publish_time->startOfDay()), "mediaItems" => array());
             $lastDate = $a->scheduled_publish_time->startOfDay();
         }
         $calendarData[count($calendarData) - 1]['mediaItems'][] = $a;
         $previousMediaItem = $a;
     }
     $coverArtResolutions = Config::get("imageResolutions.coverArt");
     $viewCalendarData = array();
     foreach ($calendarData as $day) {
         $playlistTableData = array();
         foreach ($day['mediaItems'] as $i => $item) {
             $playlist = $item->getDefaultPlaylist();
             $thumbnailUri = Config::get("custom.default_cover_uri");
             if (!Config::get("degradedService.enabled")) {
                 $thumbnailUri = $playlist->getMediaItemCoverArtUri($item, $coverArtResolutions['thumbnail']['w'], $coverArtResolutions['thumbnail']['h']);
             }
             $playlistName = null;
             if (!is_null($playlist->show)) {
                 // the current item in the playlist is part of a show.
                 $playlistName = $playlist->generateName();
             }
             $isLive = !is_null($item->liveStreamItem) && $item->liveStreamItem->getIsAccessible();
             $playlistTableData[] = array("uri" => $playlist->getMediaItemUri($item), "title" => $playlist->generateEpisodeTitle($item), "escapedDescription" => !is_null($item->description) ? e($item->description) : null, "playlistName" => $playlistName, "episodeNo" => null, "thumbnailUri" => $thumbnailUri, "thumbnailFooter" => array("isLive" => $isLive, "dateTxt" => $item->scheduled_publish_time->format("H:i")), "active" => false);
         }
         $playlistFragment = View::make("fragments.home.playlist", array("stripedTable" => false, "headerRowData" => null, "tableData" => $playlistTableData));
         $viewCalendarData[] = array("dateStr" => $day['dateStr'], "playlistFragment" => $playlistFragment);
     }
     $twitterProperties = array();
     $twitterProperties[] = array("name" => "card", "content" => "summary");
     $openGraphProperties = array();
     $description = "View a schedule of our upcoming content and also content you may have missed.";
     $twitterProperties[] = array("name" => "description", "content" => str_limit($description, 197, "..."));
     $openGraphProperties[] = array("name" => "og:description", "content" => $description);
     $title = "Guide";
     $twitterProperties[] = array("name" => "title", "content" => $title);
     $openGraphProperties[] = array("name" => "og:title", "content" => $title);
     $view = View::make("home.guide.index");
     $view->calendarData = $viewCalendarData;
     $view->titleDatesStr = $this->getDateString($startDate) . " - " . $this->getDateString((new Carbon($endDate))->subDays(1));
     $view->previousPageUri = $dayGroupOffset !== -1 * $numPages ? URL::route("guide", array($dayGroupOffset - 1)) : null;
     $view->previousPageStartDateStr = $this->getDateString($startDate->subDays($daysPerPage));
     $view->nextPageUri = $dayGroupOffset !== $numPages ? URL::route("guide", array($dayGroupOffset + 1)) : null;
     $view->nextPageStartDateStr = $this->getDateString($endDate);
     $this->setContent($view, "guide", "guide", $openGraphProperties, $title, 200, $twitterProperties);
 }
Ejemplo n.º 14
0
 public function postLiveShows()
 {
     $liveItems = MediaItem::getCachedLiveItems();
     $items = array();
     foreach ($liveItems as $a) {
         $items[] = array("id" => intval($a['mediaItem']->id), "name" => $a['generatedName'], "scheduledPublishTime" => $a['mediaItem']->scheduled_publish_time->timestamp, "uri" => $a['uri']);
     }
     return Response::json(array("items" => $items));
 }
Ejemplo n.º 15
0
 public function anyEdit($id = null)
 {
     Auth::getUser()->hasPermissionOr401(Config::get("permissions.playlists"), 1);
     $playlist = null;
     $editing = false;
     if (!is_null($id)) {
         $playlist = Playlist::with("coverFile", "sideBannerFile", "coverArtFile", "mediaItems", "customUri")->find($id);
         if (is_null($playlist)) {
             App::abort(404);
             return;
         }
         $editing = true;
     }
     $formSubmitted = isset($_POST['form-submitted']) && $_POST['form-submitted'] === "1";
     // has id 1
     // populate $formData with default values or received values
     $formData = FormHelpers::getFormData(array(array("enabled", ObjectHelpers::getProp(false, $playlist, "enabled") ? "y" : ""), array("show-id", ObjectHelpers::getProp("", $playlist, "show", "id")), array("series-no", ObjectHelpers::getProp("", $playlist, "series_no")), array("name", ObjectHelpers::getProp("", $playlist, "name")), array("description", ObjectHelpers::getProp("", $playlist, "description")), array("custom-uri", ObjectHelpers::getProp("", $playlist, "custom_uri_name")), array("cover-image-id", ObjectHelpers::getProp("", $playlist, "coverFile", "id")), array("side-banners-image-id", ObjectHelpers::getProp("", $playlist, "sideBannerFile", "id")), array("side-banners-fill-image-id", ObjectHelpers::getProp("", $playlist, "sideBannerFillFile", "id")), array("cover-art-id", ObjectHelpers::getProp("", $playlist, "coverArtFile", "id")), array("publish-time", ObjectHelpers::getProp("", $playlist, "scheduled_publish_time_for_input")), array("playlist-content", json_encode(array())), array("related-items", json_encode(array()))), !$formSubmitted);
     // this will contain any additional data which does not get saved anywhere
     $show = Show::find(intval($formData['show-id']));
     $additionalFormData = array("coverImageFile" => FormHelpers::getFileInfo($formData['cover-image-id']), "sideBannersImageFile" => FormHelpers::getFileInfo($formData['side-banners-image-id']), "sideBannersFillImageFile" => FormHelpers::getFileInfo($formData['side-banners-fill-image-id']), "coverArtFile" => FormHelpers::getFileInfo($formData['cover-art-id']), "showItemText" => !is_null($show) ? $show->name : "", "playlistContentInput" => null, "playlistContentInitialData" => null, "relatedItemsInput" => null, "relatedItemsInitialData" => null);
     if (!$formSubmitted) {
         $additionalFormData['playlistContentInput'] = ObjectHelpers::getProp(json_encode(array()), $playlist, "playlist_content_for_input");
         $additionalFormData['playlistContentInitialData'] = ObjectHelpers::getProp(json_encode(array()), $playlist, "playlist_content_for_reorderable_list");
         $additionalFormData['relatedItemsInput'] = ObjectHelpers::getProp(json_encode(array()), $playlist, "related_items_for_input");
         $additionalFormData['relatedItemsInitialData'] = ObjectHelpers::getProp(json_encode(array()), $playlist, "related_items_for_reorderable_list");
     } else {
         $additionalFormData['playlistContentInput'] = MediaItem::generateInputValueForAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($formData["playlist-content"], true));
         $additionalFormData['playlistContentInitialData'] = MediaItem::generateInitialDataForAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($formData["playlist-content"], true));
         $additionalFormData['relatedItemsInput'] = MediaItem::generateInputValueForAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($formData["related-items"], true));
         $additionalFormData['relatedItemsInitialData'] = MediaItem::generateInitialDataForAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($formData["related-items"], true));
     }
     $errors = null;
     if ($formSubmitted) {
         // validate input
         Validator::extend('valid_file_id', FormHelpers::getValidFileValidatorFunction());
         Validator::extend('my_date', FormHelpers::getValidDateValidatorFunction());
         Validator::extend('valid_show_id', function ($attribute, $value, $parameters) {
             return !is_null(Show::find(intval($value)));
         });
         Validator::extend('valid_playlist_content', function ($attribute, $value, $parameters) {
             return MediaItem::isValidIdsFromAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($value, true));
         });
         Validator::extend('valid_related_items', function ($attribute, $value, $parameters) {
             return MediaItem::isValidIdsFromAjaxSelectReorderableList(JsonHelpers::jsonDecodeOrNull($value, true));
         });
         Validator::extend('unique_custom_uri', function ($attribute, $value, $parameters) use(&$playlist) {
             $q = CustomUri::where("name", $value);
             if (!is_null($playlist)) {
                 $currentCustomUri = $playlist->custom_uri_name;
                 if (!is_null($currentCustomUri)) {
                     $q = $q->where("name", "!=", $currentCustomUri);
                 }
             }
             return $q->count() === 0;
         });
         $modelCreated = DB::transaction(function () use(&$formData, &$playlist, &$errors) {
             $validator = Validator::make($formData, array('show-id' => array('valid_show_id'), 'series-no' => array('required_with:show-id', 'integer'), 'name' => array('required_without:show-id', 'max:50'), 'description' => array('max:500'), 'custom-uri' => array('alpha_dash', 'max:50', 'unique_custom_uri'), 'cover-image-id' => array('valid_file_id'), 'side-banners-image-id' => array('valid_file_id'), 'side-banners-fill-image-id' => array('valid_file_id'), 'description' => array('max:500'), 'cover-art-id' => array('valid_file_id'), 'publish-time' => array('my_date'), 'playlist-content' => array('required', 'valid_playlist_content'), 'related-items' => array('required', 'valid_related_items')), array('show-id.valid_show_id' => FormHelpers::getGenericInvalidMsg(), 'series-no.required_with' => FormHelpers::getRequiredMsg(), 'series-no.integer' => FormHelpers::getMustBeIntegerMsg(), 'name.required_without' => FormHelpers::getRequiredMsg(), 'name.max' => FormHelpers::getLessThanCharactersMsg(50), 'description.max' => FormHelpers::getLessThanCharactersMsg(500), 'custom-uri.alpha_dash' => FormHelpers::getInvalidAlphaDashMsg(), 'custom-uri.max' => FormHelpers::getLessThanCharactersMsg(50), 'custom-uri.unique_custom_uri' => "This is already in use.", 'cover-image-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'side-banners-image-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'side-banners-fill-image-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'cover-art-id.valid_file_id' => FormHelpers::getInvalidFileMsg(), 'publish-time.my_date' => FormHelpers::getInvalidTimeMsg(), 'playlist-content.required' => FormHelpers::getGenericInvalidMsg(), 'playlist-content.valid_playlist_content' => FormHelpers::getGenericInvalidMsg(), 'related-items.required' => FormHelpers::getGenericInvalidMsg(), 'related-items.valid_related_items' => FormHelpers::getGenericInvalidMsg()));
             if (!$validator->fails()) {
                 $show = $formData['show-id'] !== "" ? Show::find(intval($formData['show-id'])) : null;
                 Validator::extend('unique_series_no', function ($attribute, $value, $parameters) use(&$playlist, &$show) {
                     if (is_null($show)) {
                         return true;
                     }
                     $count = $show->playlists()->where("series_no", $value);
                     if (!is_null($playlist)) {
                         $count = $count->where("id", "!=", $playlist->id);
                     }
                     $count = $count->count();
                     return $count === 0;
                 });
                 $validator = Validator::make($formData, array('series-no' => array('unique_series_no')), array('series-no.unique_series_no' => "A series already exists with that number."));
                 if (!$validator->fails()) {
                     // everything is good. save/create model
                     if (is_null($playlist)) {
                         $playlist = new Playlist();
                     }
                     $playlist->name = FormHelpers::nullIfEmpty($formData['name']);
                     $playlist->description = FormHelpers::nullIfEmpty($formData['description']);
                     $playlist->enabled = FormHelpers::toBoolean($formData['enabled']);
                     // if the scheduled publish time is empty and this playlist is enabled, set it to the current time.
                     // an enabled playlist should always have a published time.
                     $scheduledPublishTime = FormHelpers::nullIfEmpty(strtotime($formData['publish-time']));
                     $playlist->scheduled_publish_time = !is_null($scheduledPublishTime) ? $scheduledPublishTime : Carbon::now();
                     EloquentHelpers::associateOrNull($playlist->show(), $show);
                     $playlist->series_no = !is_null($show) ? intval($formData['series-no']) : null;
                     $coverImageId = FormHelpers::nullIfEmpty($formData['cover-image-id']);
                     $file = Upload::register(Config::get("uploadPoints.coverImage"), $coverImageId, $playlist->coverFile);
                     EloquentHelpers::associateOrNull($playlist->coverFile(), $file);
                     $sideBannerFileId = FormHelpers::nullIfEmpty($formData['side-banners-image-id']);
                     $file = Upload::register(Config::get("uploadPoints.sideBannersImage"), $sideBannerFileId, $playlist->sideBannerFile);
                     EloquentHelpers::associateOrNull($playlist->sideBannerFile(), $file);
                     $sideBannerFillFileId = FormHelpers::nullIfEmpty($formData['side-banners-fill-image-id']);
                     $file = Upload::register(Config::get("uploadPoints.sideBannersFillImage"), $sideBannerFillFileId, $playlist->sideBannerFillFile);
                     EloquentHelpers::associateOrNull($playlist->sideBannerFillFile(), $file);
                     $coverArtFileId = FormHelpers::nullIfEmpty($formData['cover-art-id']);
                     $file = Upload::register(Config::get("uploadPoints.coverArt"), $coverArtFileId, $playlist->coverArtFile);
                     EloquentHelpers::associateOrNull($playlist->coverArtFile(), $file);
                     if ($playlist->save() === false) {
                         throw new Exception("Error saving Playlist.");
                     }
                     $customUri = FormHelpers::nullIfEmpty($formData['custom-uri']);
                     $currentCustomUriModel = $playlist->customUri;
                     if (!is_null($customUri)) {
                         if ($playlist->custom_uri_name !== $customUri) {
                             // change needed
                             if (!is_null($currentCustomUriModel)) {
                                 // remove the current one first
                                 $currentCustomUriModel->delete();
                             }
                             $customUriModel = new CustomUri(array("name" => $customUri));
                             $playlist->customUri()->save($customUriModel);
                         }
                     } else {
                         if (!is_null($currentCustomUriModel)) {
                             // remove the current one
                             $currentCustomUriModel->delete();
                         }
                     }
                     // touch so that their search index numbers will be incremented
                     // each media item in the search index has the playlists it's in stored with it
                     // so will therefore need reindexing
                     foreach ($playlist->mediaItems as $a) {
                         $a->touch();
                     }
                     $playlist->mediaItems()->detach();
                     // detaches all
                     $ids = json_decode($formData['playlist-content'], true);
                     if (count($ids) > 0) {
                         $mediaItems = MediaItem::whereIn("id", $ids)->get();
                         foreach ($mediaItems as $a) {
                             $a->touch();
                             // for same reason as touch above
                             $playlist->mediaItems()->attach($a, array("position" => array_search(intval($a->id), $ids, true)));
                         }
                     }
                     $playlist->relatedItems()->detach();
                     // detaches all
                     $ids = json_decode($formData['related-items'], true);
                     if (count($ids) > 0) {
                         $mediaItems = MediaItem::whereIn("id", $ids)->get();
                         foreach ($mediaItems as $a) {
                             $playlist->relatedItems()->attach($a, array("position" => array_search(intval($a->id), $ids, true)));
                         }
                     }
                     // the transaction callback result is returned out of the transaction function
                     return true;
                 } else {
                     $errors = $validator->messages();
                     return false;
                 }
             } else {
                 $errors = $validator->messages();
                 return false;
             }
         });
         if ($modelCreated) {
             return Redirect::to(Config::get("custom.admin_base_url") . "/playlists");
         }
         // if not valid then return form again with errors
     }
     $view = View::make('home.admin.playlists.edit');
     $view->editing = $editing;
     $view->form = $formData;
     $view->additionalForm = $additionalFormData;
     $view->formErrors = $errors;
     // used to uniquely identify these file upload points on the site. Must not be duplicated for different upload points.
     $view->coverImageUploadPointId = Config::get("uploadPoints.coverImage");
     $view->sideBannersImageUploadPointId = Config::get("uploadPoints.sideBannersImage");
     $view->sideBannersFillImageUploadPointId = Config::get("uploadPoints.sideBannersFillImage");
     $view->coverArtUploadPointId = Config::get("uploadPoints.coverArt");
     $view->cancelUri = Config::get("custom.admin_base_url") . "/playlists";
     $view->seriesAjaxSelectDataUri = Config::get("custom.admin_base_url") . "/shows/ajaxselect";
     $this->setContent($view, "playlists", "playlists-edit");
 }
 public function generateMediaItemPlaylistsResponseData($mediaItemId)
 {
     $mediaItem = MediaItem::accessible()->find(intval($mediaItemId));
     if (is_null($mediaItem)) {
         return $this->generateNotFound();
     }
     $playlists = $mediaItem->playlists()->orderBy("id", "asc")->get()->all();
     $data = $this->playlistTransformer->transformCollection($playlists);
     return new ApiResponseData($data);
 }
Ejemplo n.º 17
0
 public function getRelatedItemsForReorderableListAttribute()
 {
     return MediaItem::generateInitialDataForAjaxSelectReorderableList($this->getRelatedItemsIdsForOrderableList());
 }
Ejemplo n.º 18
0
 public function postAdminStreamControlInfoMsg($id)
 {
     Auth::getUser()->hasPermissionOr401(Config::get("permissions.mediaItems"), 1);
     $mediaItem = MediaItem::with("liveStreamItem", "liveStreamItem.stateDefinition")->find($id);
     if (is_null($mediaItem)) {
         App::abort(404);
     }
     $liveStreamItem = $mediaItem->liveStreamItem;
     if (is_null($liveStreamItem)) {
         App::abort(404);
     }
     $requestedInfoMsg = null;
     if (isset($_POST['info_msg'])) {
         $requestedInfoMsg = $_POST['info_msg'];
     }
     if ($requestedInfoMsg === "") {
         $requestedInfoMsg = null;
     }
     if (!is_null($requestedInfoMsg) && strlen($requestedInfoMsg) <= 500) {
         $liveStreamItem->information_msg = $requestedInfoMsg;
         $liveStreamItem->save();
     } else {
         if (is_null($requestedInfoMsg)) {
             $liveStreamItem->information_msg = null;
             $liveStreamItem->save();
         }
     }
     $resp = array("infoMsg" => $liveStreamItem->information_msg);
     return Response::json($resp);
 }
Ejemplo n.º 19
0
 public function getIndex()
 {
     if (Config::get("degradedService.enabled")) {
         $view = View::make("home.degradedIndex");
         $view->contactEmail = Config::get("contactEmails.development");
         $this->setContent($view, "home", "home-degraded", array(), null, 200, array());
         return;
     }
     $promoMediaItem = MediaItem::with("liveStreamItem", "liveStreamItem.liveStream", "videoItem")->accessible()->whereNotNull("time_promoted")->orderBy("time_promoted", "desc")->first();
     if (!is_null($promoMediaItem)) {
         $liveStreamItem = $promoMediaItem->liveStreamItem;
         if (!is_null($liveStreamItem) && !$liveStreamItem->getIsAccessible()) {
             $liveStreamItem = null;
         }
         $videoItem = $promoMediaItem->videoItem;
         if (!is_null($videoItem) && !$videoItem->getIsAccessible()) {
             $videoItem = null;
         }
         $shouldShowItem = false;
         // if there is a live stream which is in the "not live" state the player won't display the vod
         // even if there is one. It will show the countdown to the start of the live stream.
         if (is_null($liveStreamItem) || !$liveStreamItem->isNotLive()) {
             if (!is_null($videoItem) && $videoItem->getIsLive()) {
                 $shouldShowItem = true;
             } else {
                 if (!is_null($liveStreamItem) && $liveStreamItem->hasWatchableContent()) {
                     $shouldShowItem = true;
                 }
             }
         }
         if (!$shouldShowItem) {
             $promoMediaItem = null;
         }
     }
     $promoPlaylist = null;
     if (!is_null($promoMediaItem)) {
         $promoPlaylist = $promoMediaItem->getDefaultPlaylist();
     }
     $promotedItems = MediaItem::getCachedPromotedItems();
     $promotedItemsData = array();
     // if there is an item to promote insert it at the start of the carousel
     if (!is_null($promoMediaItem)) {
         $coverArtResolutions = Config::get("imageResolutions.coverArt");
         $isLiveShow = !is_null($promoMediaItem->liveStreamItem) && !$promoMediaItem->liveStreamItem->isOver();
         $liveNow = $isLiveShow && $promoMediaItem->liveStreamItem->isLive();
         $promotedItemsData[] = array("coverArtUri" => $promoPlaylist->getMediaItemCoverArtUri($promoMediaItem, $coverArtResolutions['full']['w'], $coverArtResolutions['full']['h']), "name" => $promoMediaItem->name, "seriesName" => !is_null($promoPlaylist->show) ? $promoPlaylist->generateName() : null, "availableMsg" => $liveNow ? "Live Now!" : $this->buildTimeStr($isLiveShow, $promoMediaItem->scheduled_publish_time), "uri" => $promoPlaylist->getMediaItemUri($promoMediaItem));
     }
     foreach ($promotedItems as $a) {
         $mediaItem = $a['mediaItem'];
         if (!is_null($promoMediaItem) && intval($mediaItem->id) === intval($promoMediaItem->id)) {
             // prevent duplicate
             continue;
         }
         $isLiveShow = !is_null($mediaItem->liveStreamItem) && !$mediaItem->liveStreamItem->isOver();
         $liveNow = $isLiveShow && $mediaItem->liveStreamItem->isLive();
         $promotedItemsData[] = array("coverArtUri" => $a['coverArtUri'], "name" => $mediaItem->name, "seriesName" => $a['seriesName'], "availableMsg" => $liveNow ? "Live Now!" : $this->buildTimeStr($isLiveShow, $mediaItem->scheduled_publish_time), "uri" => $a['uri']);
     }
     $coverArtResolutions = Config::get("imageResolutions.coverArt");
     $recentlyAddedItems = MediaItem::getCachedRecentItems();
     $recentlyAddedTableData = array();
     foreach ($recentlyAddedItems as $i => $a) {
         $mediaItem = $a['mediaItem'];
         $recentlyAddedTableData[] = array("uri" => $a['uri'], "active" => false, "title" => $mediaItem->name, "escapedDescription" => null, "playlistName" => $a['playlistName'], "episodeNo" => $i + 1, "thumbnailUri" => $a['coverArtUri'], "thumbnailFooter" => null, "duration" => $a['duration']);
     }
     $mostPopularItems = MediaItem::getCachedMostPopularItems();
     $mostPopularTableData = array();
     foreach ($mostPopularItems as $i => $a) {
         $mediaItem = $a['mediaItem'];
         $mostPopularTableData[] = array("uri" => $a['uri'], "active" => false, "title" => $mediaItem->name, "escapedDescription" => null, "playlistName" => $a['playlistName'], "episodeNo" => $i + 1, "thumbnailUri" => $a['coverArtUri'], "thumbnailFooter" => null, "duration" => $a['duration']);
     }
     $view = View::make("home.index");
     $view->promotedItemsData = $promotedItemsData;
     $view->recentlyAddedPlaylistFragment = count($recentlyAddedTableData) > 0 ? View::make("fragments.home.playlist", array("stripedTable" => true, "headerRowData" => null, "tableData" => $recentlyAddedTableData)) : null;
     $view->mostPopularPlaylistFragment = count($mostPopularTableData) > 0 ? View::make("fragments.home.playlist", array("stripedTable" => true, "headerRowData" => null, "tableData" => $mostPopularTableData)) : null;
     $view->twitterWidgetId = Config::get("twitter.timeline_widget_id");
     $hasPromoItem = !is_null($promoMediaItem);
     $showPromoItem = $hasPromoItem;
     if ($hasPromoItem) {
         // determine if the user has already seen the promo
         $cookieVal = Cookie::get('seenPromo-' . $promoMediaItem->id);
         if (!is_null($cookieVal) && $cookieVal === $promoMediaItem->time_promoted->timestamp) {
             // user already seen promo
             $showPromoItem = false;
         }
         // put a cookie in the users browser to inform us in the future that the user has seen this promo video
         // store the time so that if the item is repromoted in the future, it will be shown again.
         Cookie::queue('seenPromo-' . $promoMediaItem->id, $promoMediaItem->time_promoted->timestamp, 40320);
         // store for 4 weeks
     }
     $view->showPromoItem = $showPromoItem;
     if ($showPromoItem) {
         $userHasMediaItemsPermission = false;
         if (Auth::isLoggedIn()) {
             $userHasMediaItemsPermission = Auth::getUser()->hasPermission(Config::get("permissions.mediaItems"), 0);
         }
         $view->promoPlayerInfoUri = PlayerHelpers::getInfoUri($promoPlaylist->id, $promoMediaItem->id);
         $view->promoRegisterWatchingUri = PlayerHelpers::getRegisterWatchingUri($promoPlaylist->id, $promoMediaItem->id);
         $view->promoRegisterLikeUri = PlayerHelpers::getRegisterLikeUri($promoPlaylist->id, $promoMediaItem->id);
         $view->promoAdminOverrideEnabled = $userHasMediaItemsPermission;
         $view->promoLoginRequiredMsg = "Please log in to use this feature.";
     }
     $this->setContent($view, "home", "home", array(), null, 200, array());
 }