Skip to content
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

improve label functionality #70

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/Event/CardLabelEvent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

======================

### Set label
```php
setLabel(\Trello\Model\LabelInterface $label)
```

### Get label
```php
getLabel()
```

5 changes: 5 additions & 0 deletions docs/Manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ getList(string $id)
getCard(string $id)
```

### Get label by id or create a new one
```php
getLabel(string $id)
```

### Get checklist by id or create a new one
```php
getChecklist(string $id)
Expand Down
10 changes: 10 additions & 0 deletions docs/Model/Board.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ setLabelNames(array $labelNames)
getLabelNames()
```

### Get labels
```php
getLabels()
```

### Get label that has name $name and color $color
```php
getLabel($name, $color)
```

### Set power ups
```php
setPowerUps(array $powerUps)
Expand Down
10 changes: 10 additions & 0 deletions docs/Model/BoardInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ setLabelNames(array $labelNames)
getLabelNames()
```

### Get labels
```php
getLabels()
```

### Get label that has name $name and color $color
```php
getLabel($name, $color)
```

### Set power ups
```php
setPowerUps(array $powerUps)
Expand Down
16 changes: 8 additions & 8 deletions docs/Model/Card.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,24 @@ setLabels(array $labels)
getLabels()
```

### Get the colors of labels associated to this card
### Get the ids of labels associated to this card
```php
getLabelColors()
getLabelIds()
```

### Does the card have the label of which the color is $color?
### Does the card have the label?
```php
hasLabel($color)
hasLabel(LabelInterface $label)
```

### Add the label of color $color
### Add the label $label
```php
addLabel($color)
addLabel(LabelInterface $label)
```

### Remove the label of color $color
### Remove the label $label
```php
removeLabel($color)
removeLabel(LabelInterface $label)
```

### Set Badges
Expand Down
47 changes: 47 additions & 0 deletions docs/Model/Label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

======================

### Get id
```php
getId()
```

### Set name
```php
setName($name)
```

### Get name
```php
getName()
```

### Set color
```php
setColor($color)
```

### Get color
```php
getColor()
```

### Set boardId
```php
setBoardId($boardId)
```

### Get boardId
```php
getBoardId()
```

### Set board
```php
setBoard(\Trello\Model\BoardInterface $board)
```

### Get board
```php
getBoard()
```
47 changes: 47 additions & 0 deletions docs/Model/LabelInterface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

======================

### Get id
```php
getId()
```

### Set name
```php
setName($name)
```

### Get name
```php
getName()
```

### Set color
```php
setColor($color)
```

### Get color
```php
getColor()
```

### Set boardId
```php
setBoardId($boardId)
```

### Get boardId
```php
getBoardId()
```

### Set board
```php
setBoard(\Trello\Model\BoardInterface $board)
```

### Get board
```php
getBoard()
```
4 changes: 0 additions & 4 deletions lib/Trello/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,11 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr
$parameters[$name] = $parameter ? 'true' : 'false';
}
}

$response = $this->client->getHttpClient()->put(
$path,
$this->createParametersBody($parameters),
$requestHeaders
);

return ResponseMediator::getContent($response);
}

Expand Down Expand Up @@ -258,9 +256,7 @@ protected function createParametersBody(array $parameters)
if (is_bool($subParameter)) {
$subParameter = $subParameter ? 'true' : 'false';
}
$parameters[$name.'/'.$subName] = $subParameter;
}
unset($parameters[$name]);
} elseif ($parameter instanceof DateTime) {
$parameters[$name] = $parameter->format($parameter::ATOM);
}
Expand Down
110 changes: 110 additions & 0 deletions lib/Trello/Api/Label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Trello\Api;

use Trello\Exception\InvalidArgumentException;

class Label extends AbstractApi
{
/**
* Base path of labels api
* @var string
*/
protected $path = 'labels';


public static $fields = array(
'idBoard',
'name',
'color',
);

/**
* Find a label by id
* @link https://developers.trello.com/reference/#id
*
* @param string $id the label's id
* @param array $params optional attributes
*
* @return array label info
*/
public function show($id, array $params = array())
{
return $this->get($this->getPath().'/'.rawurlencode($id), $params);
}

/**
* Create a label
* @link https://developers.trello.com/reference/#id-1
*
* @param array $params optional attributes
*
* @return array label info
*/
public function create(array $params = array())
{
$this->validateRequiredParameters(array('name', 'idBoard', 'color'), $params);

return $this->post('boards/'.rawurlencode($params['idBoard']).'/labels/', $params);
}

/**
* Update a label
* @link https://developers.trello.com/reference/#id-1
*
* @param string $id the label's id
* @param array $params label attributes to update
*
* @return array label info
*/
public function update($id, array $params = array())
{
return $this->put($this->getPath().'/'.rawurlencode($id).'/labels/', $params);
}

/**
* Set a given label's board
* @link https://developers.trello.com/reference/#id-1
*
* @param string $id the label's id
* @param string $boardId the board's id
*
* @return array board info
*/
public function setBoard($id, $boardId)
{
return $this->put($this->getPath().'/'.rawurlencode($id).'/idBoard', array('value' => $boardId));
}

/**
* Get a given label's board
* @link https://developers.trello.com/reference/#id
*
* @param string $id the label's id
* @param array $params optional parameters
*
* @return array board info
*/
public function getBoard($id, array $params = array())
{
return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
}

/**
* Get the field of a board of a given label
* @link https://developers.trello.com/reference/#id
*
* @param string $id the label's id
* @param array $field the name of the field
*
* @return array
*
* @throws InvalidArgumentException if the field does not exist
*/
public function getBoardField($id, $field)
{
$this->validateAllowedParameters(Board::$fields, $field, 'field');

return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
}
}
4 changes: 4 additions & 0 deletions lib/Trello/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public function api($name)
case 'webhooks':
$api = new Api\Webhook($this);
break;
case 'label':
case 'labels':
$api = new Api\Label($this);
break;
default:
throw new InvalidArgumentException(sprintf('Undefined api called: "%s"', $name));
}
Expand Down
33 changes: 33 additions & 0 deletions lib/Trello/Event/CardLabelEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Trello\Event;

use Trello\Model\LabelInterface;

class CardChecklistEvent extends CardEvent
{
/**
* @var LabelInterface
*/
protected $checklist;

/**
* Set label
*
* @param LabelInterface $label
*/
public function setLabel(LabelInterface $label)
{
$this->label = $label;
}

/**
* Get label
*
* @return LabelInterface
*/
public function getLabel()
{
return $this->label;
}
}
4 changes: 2 additions & 2 deletions lib/Trello/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ final class Events

/**
* When a new label is added to a card
* The event listener method receives a Trello\Event\CardEvent instance.
* The event listener method receives a Trello\Event\CardLabelEvent instance.
*/
const CARD_ADD_LABEL = 'addLabelToCard';

/**
* When a new label is removed from a card
* The event listener method receives a Trello\Event\CardEvent instance.
* The event listener method receives a Trello\Event\CardLabelEvent instance.
*/
const CARD_REMOVE_LABEL = 'removeLabelFromCard';

Expand Down
Loading