/** * 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; }
/** * 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; }