protected function execute(InputInterface $input, OutputInterface $output) { // Style the output $output = $this->setOutputFormat($output); // Helper to ask questions through Console $helper = $this->getHelper('question'); // Welcome message $output->writeln("\n<say>Let me grab all the unactive cities from the <high>DB</high>...</say>"); // Get cities from DB $this->allCities = $this->city->getAll(); $output->writeln("\n<say>Ok, here you have them <high>↓ </high></say>"); // Create array with only inactive cities and display them $unactiveCities = []; foreach ($this->allCities as $city) { if (!$city->active) { $output->writeln("- {$city->name}"); $unactiveCities[] = $city; } } // Get the City $question = new ValidableQuestion("<ask>\nWhich city do you want to activate?: </ask>", ['required']); $question->setAutocompleterValues(array_merge($this->city->getNames($unactiveCities), $this->city->getNames($unactiveCities, true))); $cityName = $helper->ask($input, $output, $question); $city = $this->city->getByName($this->allCities, $cityName); $this->city->activate($city); $this->city->setOrder($city, 100); // $this->showFireworks($output); $output->writeln("\n\n <say><high>{$city->name}</high> is now live!</say>\n"); }
public function execute(InputInterface $input, OutputInterface $output) { $output = $this->setOutputFormat($output); $helper = $this->getHelper('question'); // Show welcome message $this->displayWelcomeMessage($output); // Show menu option $this->displayMenuOptions($output); $question = new ValidableQuestion("\n<say>Please select one <high>command</high>: </say>", ['required']); foreach ($this->menuOptions as $option) { $this->menuOptions[] = strtoupper($option); } $question->setAutocompleterValues($this->menuOptions); $command = strtolower($helper->ask($input, $output, $question)); return $this->getApplication()->find($command)->run($input, $output); }
protected function execute(InputInterface $input, OutputInterface $output) { // Style the output $output = $this->setOutputFormat($output); // Helper to ask questions through Console $helper = $this->getHelper('question'); // Welcome message $output->writeln("\n<say>Hello again! Let me grab the cities from the <high>DB</high>...</say>"); // Get cities from DB $this->allCities = $this->city->getAll(); $output->writeln("<high>Done!</high>"); // Get the City $question = new ValidableQuestion("<ask>\nWhich city do you want to edit?: </ask>", ['required']); $question->setAutocompleterValues(array_merge($this->city->getNames($this->allCities), $this->city->getNames($this->allCities, true))); $cityName = $helper->ask($input, $output, $question); $city = $this->city->getByName($this->allCities, $cityName); var_dump($city); }
public function execute(InputInterface $input, OutputInterface $output) { $output = $this->setOutputFormat($output); $helper = $this->getHelper('question'); // Get cities info from DB $output->writeln("<say>Loading cities from DB...</say>"); $this->allCities = $this->city->getAll(); $dataset = $input->getArgument('dataset'); $cityId = $input->getArgument('cityId'); $source = $input->getOption('source'); if (!$dataset || !$cityId || !$source) { // Get the City ID $question = new ValidableQuestion("<ask>Which city do you want to get datasets for?: </ask>", ['required']); // set autocompleter values to city names, including all lowercase $question->setAutocompleterValues(array_merge($this->city->getNames($this->allCities), $this->city->getNames($this->allCities, true))); $cityName = $helper->ask($input, $output, $question); $cityId = $this->city->getByName($this->allCities, $cityName)->bkID; // Get the Dataset $question = new ValidableQuestion("<ask>Which dataset do you want to get?: </ask>", ['required']); $question->setAutocompleterValues($this->config->layers); $dataset = $helper->ask($input, $output, $question); // Get the source $sources = $this->config->scrapSourcesFor($dataset); if (!$sources) { $output->writeln("<error>We don't have scrappers for that dataset, YET</error>"); die; } $question = new ChoiceQuestion("<ask>These are the sources we can get {$dataset} from. Please select one: </ask>", $sources); $source = $helper->ask($input, $output, $question); } $output->writeln("\n<say>Getting <high>{$dataset}</high> from <high>{$source}</high> for <high>" . strtoupper($cityId) . "</high>... Please stand by.</say>"); $scrapper = ScrapperFactory::getInstance($source); $data = $scrapper->scrap($cityId, $dataset, $input, $output); $countItems = count(json_decode($data)->features); $fullpath = $this->geojson->getGeojsonFullpath($dataset, $this->city->getById($cityId)); $this->geojson->saveDataset($dataset, $this->city->getById($cityId), $data); $this->uploadToCartoDB($fullpath); $output->writeln("<ask>{$countItems} items saved to " . $this->getCartoDBUrl($fullpath, $cityId)); }
/** * @param InputInterface $input * @param OutputInterface $output * @param $helper */ protected function selectCity(InputInterface $input, OutputInterface $output, $helper) { $question = new ValidableQuestion("\n<say>Which city you want to work with? </say>", ['required']); // set autocompleter values to city names, including all lowercase $question->setAutocompleterValues(array_merge($this->city->getNames($this->allCities), $this->city->getNames($this->allCities, true))); $cityName = $helper->ask($input, $output, $question); $output->writeln("\n<say>*** <high>" . ucwords($cityName) . "</high> it is! ***</say>"); return $this->city->getByName($this->allCities, $cityName); }