/** * Run the command * @param InputInterface $input Input * @param OutputInterface $output Output * @return bool */ public function execute(InputInterface $input, OutputInterface $output) { $trello = HelperCommand::getTrelloClient($output); if (!$trello) { return false; } $boards = HelperCommand::getCachedBoards($output); if (!$boards) { return false; } $listCache = []; $config = HelperCommand::getConfig(); foreach ($boards as $board => $data) { $trelloBoard = $trello->getBoard($board); if (!$trelloBoard) { $error = "Board {$board} failed to load"; $output->writeln("<error>{$error}</error>"); continue; } if (!array_key_exists($board, $config['boards'])) { $config['boards'][$board] = HelperCommand::getDefaultBoardConfig(); } $lists = $trelloBoard->getLists(); $listCache[$board] = []; foreach ($lists as $list) { $listCache[$board][$list->id] = ['name' => $list->name, 'pos' => $list->pos, 'closed' => $list->closed]; if (!array_key_exists($list->id, $config['boards'][$board]['lists'])) { $config['boards'][$board]['lists'][] = $list->id; } } } HelperCommand::setConfig($config); file_put_contents(dirname(__DIR__) . self::FILE_CACHE, Yaml::dump($listCache, 2, 4, false, true)); return true; }
/** * Which Board to look at * @param InputInterface $input Input * @param OutputInterface $output Output * @return bool */ public function selectBoard(InputInterface $input, OutputInterface $output) { $trello = HelperCommand::getTrelloClient($output); if (!$trello) { return false; } $boards = HelperCommand::getCachedBoards($output); if (!$boards) { return false; } $keys = array_keys($boards); $output->writeln("<info>Select a board to work with:</info>"); foreach ($keys as $key => $board) { $num = $key + 1; $output->writeln("\t ({$num})\t {$boards[$board]['name']}"); } $helper = $this->getHelper('question'); $question = new Question('Enter a Board : '); $answer = (int) $helper->ask($input, $output, $question); if (!$answer) { return false; } $key = $answer - 1; $board = $boards[$keys[$key]]; return $board; }
/** * Run the command * @param InputInterface $input Input * @param OutputInterface $output Output * @return bool */ public function execute(InputInterface $input, OutputInterface $output) { $trello = HelperCommand::getTrelloClient($output); $boardKey = $input->getArgument('boardKey'); $config = HelperCommand::getConfig(); if (empty($config['boards'][$boardKey])) { $output->writeln("<error>Board not in config</error>"); return false; } $boardConfig = $config['boards'][$boardKey]; $cachedBoards = HelperCommand::getCachedBoards($output); $cachedLists = HelperCommand::getCachedLists($output); $boardLists = $cachedLists[$boardKey]; $lists = []; $cards = []; foreach ($boardLists as $listKey => $listData) { $lists[$listKey] = $listData['name']; $cards[$listKey] = []; } $trelloCards = $trello->getBoard($boardKey)->getCards(); foreach ($trelloCards as $card) { if (!array_key_exists($card->idList, $lists)) { continue; } $cards[$card->idList][] = ['id' => $card->id, 'url' => $card->shortUrl, 'name' => $card->name]; } $send = ''; foreach ($cards as $list => $listCards) { $send .= "<h3>{$lists[$list]}</h3>"; foreach ($listCards as $card) { $send .= "<a href='{$card['url']}' style='margin-left:30px'>{$card['name']}</a><br/>"; } } echo $send; $transport = new \Swift_SendmailTransport(); $mail = new \Swift_Mailer($transport); $message = \Swift_Message::newInstance(); $message->setSubject('Trello:'); $message->addFrom($boardConfig['email'][0]); $message->addTo($boardConfig['email'][0]); $message->addPart($send, 'text/html'); $mail->send($message); return true; }
/** * Run the command * @param InputInterface $input Input * @param OutputInterface $output Output * @return bool */ public function execute(InputInterface $input, OutputInterface $output) { $boards = HelperCommand::getCachedBoards($output); $lists = HelperCommand::getCachedLists($output); $boardKey = $input->getArgument('boardKey'); if ($boardKey) { $this->boardKey = $boardKey; } if (!array_key_exists($boardKey, $boards)) { $output->writeln("<error>" . HelperCommand::ERROR_BOARDS . "</error>"); return false; } $output->writeln("<info>Lists for '{$boards[$boardKey]['name']}'</info>"); $boardLists = $lists['lists'][$this->boardKey]; foreach ($boardLists as $id => $listData) { $output->writeln("\t{$listData['name']}"); } $output->writeln(''); return true; }