/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $id = $input->getOption('id'); try { $data = $this->demoRepository->getById($id); $table = $this->getHelper('table'); $table->setHeaders(array(__('ID'), __('Title'), __('Created'), __('Updated'), __('Visible'), __('Active')))->setRows([[$data->getId(), $data->getTitle(), $data->getCreationTime(), $data->getUpdateTime(), $data->getIsVisible() ? __('Yes') : __('No'), $data->getIsActive() ? __('Yes') : __('No')]]); $table->render($output); } catch (\Exception $ex) { $output->writeln('<error>' . $ex->getMessage() . '</error>'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { // Get list of available records $searchCriteria = $this->searchCriteriaBuilder->create(); $searchResult = $this->demoRepository->getList($searchCriteria); $rows = []; foreach ($searchResult->getItems() as $item) { $rows[] = [$item->getId(), $item->getTitle()]; } $table = $this->getHelper('table'); $table->setHeaders(array(__('ID'), __('Title')))->setRows($rows); $table->render($output); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $title = $input->getArgument('title'); $active = $input->getOption('active') ? 1 : 0; $visible = $input->getOption('visible') ? 1 : 0; if (!$title) { $dialog = $this->getHelper('dialog'); $title = $dialog->ask($output, '<question>Enter the Title:</question> ', false); $active = $dialog->ask($output, '<question>Should record be active: [Y/n]</question> ', 'y'); $active = strtolower($active) == 'y' ? 1 : 0; $visible = $dialog->ask($output, '<question>Should record be visible: [Y/n]</question> ', 'y'); $visible = strtolower($visible) == 'y' ? 1 : 0; } /** @var DemoInterface $demoRecord */ $demoRecord = $this->demoFactory->create(); $demoRecord->setIsActive($active)->setIsVisible($visible)->setTitle($title); try { $demo = $this->demoRepository->save($demoRecord); $output->writeln('New record created (id=' . $demo->getId() . ')'); } catch (\Exception $ex) { $output->writeln('<error>' . $ex->getMessage() . '</error>'); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); $id = $input->getOption('id'); try { if (!$input->getOption('force')) { $data = $this->demoRepository->getById($id); $output->writeln('Id :' . $data->getId()); $output->writeln('Title :' . $data->getTitle()); $question = new ConfirmationQuestion('Are you sure you want to delete this record? ', false); if (!$helper->ask($input, $output, $question)) { return; } } $data = $this->demoRepository->deleteById($id); if ($data) { $output->writeln('<info>Record deleted!</info>'); } else { $output->writeln('<error>Unable to delete record!</error>'); } } catch (\Exception $ex) { $output->writeln('<error>' . $ex->getMessage() . '</error>'); } }