-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a New Card Filter For Labels #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
/vendor/ | ||
/web/bundles/ | ||
composer.lock | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
|
||
namespace AppBundle\Helper\CardFilter; | ||
|
||
|
||
use AppBundle\Helper\TrelloClient\Model\Card; | ||
use AppBundle\Helper\TrelloClient\Model\Label; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
|
||
class LabelNameCardFilter extends AbstractCardFilter | ||
{ | ||
/** | ||
* @var Label | ||
*/ | ||
private $targetLabel; | ||
|
||
/** | ||
* Initialization of the filter should be implemented in this function. This may include asking the user for input. | ||
* If setup needs to be cancelled, then an exception can be thrown for the filter not to be created | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @param string $boardId | ||
* | ||
* @return CardFilterInterface | ||
* @throws \Exception | ||
*/ | ||
static public function setUp(InputInterface $input, OutputInterface $output, $boardId) | ||
{ | ||
$trelloClient = self::getContainer()->get('trello_client'); | ||
|
||
$boardLabels = $trelloClient->getBoardLabels($boardId); | ||
$options = []; | ||
$count = 1; | ||
foreach($boardLabels as $boardLabel ){ | ||
$labelName = $boardLabel->getName(); | ||
if ( isset($options[ $boardLabel->getName() ]) && ( isset( $labelName ) && !empty( $boardLabel->getName()) ) ) | ||
{ | ||
$options[$count.' '.$boardLabel->getName() ] = $boardLabel; | ||
} | ||
elseif( isset( $labelName ) && !empty( $boardLabel->getName()) ) | ||
{ | ||
$options[$count.' '.$boardLabel->getName()] = $boardLabel; | ||
} | ||
$count ++; | ||
//$options[$boardLabel->getId()] = $boardLabel; | ||
} | ||
$filterOptionQuestion = new ChoiceQuestion( | ||
'Select Label to filter by:', | ||
array_merge(array_keys($options), ['<- Back']) | ||
); | ||
$questionHelper = new QuestionHelper(); | ||
$selectedLabelName = $questionHelper->ask($input, $output, $filterOptionQuestion); | ||
if($selectedLabelName == '<- Back'){ | ||
throw new \Exception('Back option selected'); | ||
} | ||
|
||
$filter = new self(); | ||
$filter->targetLabel = $options[$selectedLabelName]; | ||
|
||
return $filter; | ||
} | ||
|
||
/** | ||
* Should return TRUE if the provided card passes this filter and FALSE otherwise | ||
* | ||
* @param Card $card | ||
* | ||
* @return boolean | ||
*/ | ||
public function satisfiedBy(Card $card) | ||
{ | ||
foreach ($card->getLabels() as $cardLabel){ | ||
if ($cardLabel->getId() == $this->getTargetLabel()->getId()){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Should return a unique, static friendly name for the filter to identify it in interfaces | ||
* | ||
* @return string | ||
*/ | ||
static public function getName() | ||
{ | ||
return 'Has Label'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you choose to go implement the functionality in #2, then this should probably change to something like See |
||
} | ||
|
||
/** | ||
* Should return a short description (around 50 characters or less) of what this specific instantiation of the filter | ||
* is filtering for | ||
* | ||
* @return string | ||
*/ | ||
public function getConfigDescription() | ||
{ | ||
return 'Label: '.$this->getTargetLabel()->getName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you chose to go implement matching a specific label, then have a look at how the labels are rendered in This covers Labels without names and attempts to differentiate Labels by colour |
||
} | ||
|
||
private function getTargetLabel() | ||
{ | ||
return $this->targetLabel; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The display for the setup renders as follows:
You can rely on the
ChoiceQuestion
to do the option numbering for you