/**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $group = $input->getOption('title');
     if (!$group) {
         $output->writeln('<fg=red>You must provide a title for your command</>');
         return;
     }
     $check = WatchlistGroup::where('title', $group)->first();
     if ($check) {
         $output->writeln('<fg=yellow>A group with this name already exists</>');
         return;
     }
     $watchListGroup = new WatchlistGroup();
     $watchListGroup->title = $group;
     $watchListGroup->save();
     $output->writeln('<fg=green>Success! Group with the title of ' . $group . ' created successfully!</>');
 }
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $group = $input->getOption('group');
     $show = $input->getOption('show');
     $link = $input->getOption('link');
     if (!$show && !$link) {
         $output->writeln('<fg=red>You must provide a show ID or link</>');
         return;
     }
     //Let's fetch the ID
     if ($show && !$link) {
         if (!is_numeric($show) || intval($show) != $show || intval($show) <= 0) {
             $output->writeln('<fg=red>Error: Invalid ID</>');
             return;
         } else {
             $showId = intval($show);
         }
     } else {
         $link = $input->getOption('link');
         $url = parse_url($link);
         if (!$url || $url['host'] != 'www.tvmaze.com') {
             $output->writeln('<fg=red>Error: invalid URL</>');
             return;
         }
         preg_match("/\\/shows\\/([0-9]+)\\//i", $url['path'], $matches);
         $showId = $matches[1];
     }
     $check = Watchlist::with('group')->whereHas('group', function ($q) use($group) {
         $q->where('title', $group);
     })->where('tvmaze_id', $showId)->first();
     if ($check) {
         $output->writeln('<fg=red>Error: The show you have provided already exists in the watchlist "' . $check->group->title . '"</>');
         return;
     }
     $groupData = WatchlistGroup::where('title', $group)->first();
     if (!$groupData) {
         $output->writeln('<fg=red>Error: Watchlist group not found</>');
         return;
     }
     $watchlist = new Watchlist();
     $watchlist->watchlist_group_id = $groupData->id;
     $watchlist->tvmaze_id = $showId;
     $watchlist->save();
     $output->writeln('<fg=green>Success: The show is successfully added to watchlist</>');
 }
示例#3
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return string Output to console
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $group = $input->getArgument('group');
     if (!$group) {
         $output->writeln('<fg=red>Error: You have to provide the group name</>');
         return;
     }
     $watchListGroup = WatchlistGroup::with('watchlists')->where('title', $group)->first();
     if (!$watchListGroup) {
         $output->writeln('<fg=red>Error: No watchlist group found</>');
         return;
     }
     //Let's get the ID of of the shows
     $shows = $watchListGroup->watchlists->pluck('tvmaze_id')->toArray();
     //Now let's fetch episodes:
     $episodes = Episode::join('series', 'series.id', '=', 'episodes.serie_id_internal', 'inner')->whereIn('series.external_id', $shows)->orderBy('episodes.airdate', 'ASC')->select(['episodes.id', 'series.title as series_title', 'episodes.title', 'episodes.season_id', 'episodes.episode_id', 'episodes.is_special', 'episodes.url'])->get()->toArray();
     $rows = array_map('array_values', $episodes);
     $table = new Table($output);
     $table->setHeaders(array('Episode ID', 'Show', 'Title', 'Season', 'Episode', 'Is Special?', 'URL'))->setRows($rows);
     $table->render();
 }