-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Classes for the Portfolio Board endpoints (#45)
* Add Portfolio Board Model Add the Model for the /portfolio/boards endpoints for the Teamwork API https://developer.teamwork.com/projects/portfolio-boards/boards-in-portfolio-view * Add Portfolio Column Model Add the Model for the /portfolio/columns endpoints for the Teamwork API https://developer.teamwork.com/projects/portfolio-boards/columns-inside-a-portfolio-board gatAll / insert use this end point: /portfolio/boards/{boardId}/columns * Change getAll to getAllForBoard in Column The getAll method wasn't really correct, as there isn't a get all method. You can only get all columns for a given board (the ID of which was already being passed in), so added ForBoard to the function name * Add Portfolio Card Model Add the Model for the /portfolio/cards endpoints for the Teamwork API Some use special endpoints: - getAllForColumn: portfolio/columns/{columnId}/cards - insert: portfolio/columns/{columnId}/cards (this adds a project as a card on the given column) - update - portfolio/cards/{cardId}/move (this moves the card from one column to another)
- Loading branch information
1 parent
482997b
commit 29b2006
Showing
8 changed files
with
816 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace TeamWorkPm\Portfolio; | ||
|
||
use TeamWorkPm\Model; | ||
|
||
class Board extends Model | ||
{ | ||
public function init() | ||
{ | ||
$this->parent = 'board'; | ||
$this->action = 'portfolio/boards'; | ||
|
||
$this->fields = [ | ||
'canEdit' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'boolean'], | ||
], | ||
|
||
'name' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'displayOrder' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'description' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'deletedDate' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'id' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'dateCreated' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'color' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'deleted' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'boolean'], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Get all the Portfolio Boards | ||
* GET /portfolio/boards | ||
* | ||
* @return \TeamWorkPm\Response\Model | ||
* @throws \TeamWorkPm\Exception | ||
*/ | ||
public function getAll() | ||
{ | ||
return $this->rest->get("$this->action"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace TeamWorkPm\Portfolio; | ||
|
||
use TeamWorkPm\Exception; | ||
use TeamWorkPm\Model; | ||
|
||
class Card extends Model | ||
{ | ||
public function init() | ||
{ | ||
$this->parent = 'card'; | ||
$this->action = 'portfolio/cards'; | ||
|
||
$this->fields = [ | ||
'projectId' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
// These are only used by the update method | ||
'cardId' => [ | ||
'required' => false, | ||
'sibling' => true, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'columnId' => [ | ||
'required' => false, | ||
'sibling' => true, // Dont nest under 'Card' | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'oldColumnId' => [ | ||
'required' => false, | ||
'sibling' => true, // Dont nest under 'Card' | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'positionAfterId' => [ | ||
'required' => false, | ||
'sibling' => true, // Dont nest under 'Card' | ||
'attributes' => ['type' => 'integer'], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Get all the Columns for a Portfolio Column | ||
* GET /portfolio/columns/{columnId}/cards | ||
* | ||
* @param int $columnId | ||
* | ||
* @return \TeamWorkPm\Response\Model | ||
* @throws \TeamWorkPm\Exception | ||
*/ | ||
public function getAllForColumn($columnId) | ||
{ | ||
$columnId = (int) $columnId; | ||
if ($columnId <= 0) { | ||
throw new Exception('Invalid param columnId'); | ||
} | ||
|
||
return $this->rest->get("portfolio/columns/$columnId/cards"); | ||
} | ||
|
||
/** | ||
* Adds a project to the given board | ||
* | ||
* @param array $data | ||
* | ||
* @return int | ||
*/ | ||
public function insert(array $data) | ||
{ | ||
$columnId = empty($data['columnId']) ? 0 : (int) $data['columnId']; | ||
if ($columnId <= 0) { | ||
throw new Exception('Required field columnId'); | ||
} | ||
unset($data['columnId']); | ||
|
||
if (empty($data['projectId'])) { | ||
throw new Exception('Required field projectId'); | ||
} | ||
|
||
return $this->rest->post("portfolio/columns/$columnId/cards", $data); | ||
} | ||
|
||
/** | ||
* Moves the given card from one board to another | ||
* | ||
* @param array $data | ||
* | ||
* @return bool | ||
* @throws \TeamWorkPm\Exception | ||
*/ | ||
public function update(array $data) | ||
{ | ||
$cardId = empty($data['id']) ? 0: (int) $data['id']; | ||
if ($cardId <= 0) { | ||
throw new Exception('Required field id'); | ||
} | ||
$data['cardId'] = $data['id']; | ||
unset($data['id']); | ||
|
||
if (empty($data['columnId'])) { | ||
throw new Exception('Required field columnId'); | ||
} | ||
|
||
if (empty($data['oldColumnId'])) { | ||
throw new Exception('Required field oldColumnId'); | ||
} | ||
|
||
return $this->rest->put("$this->action/$cardId/move", $data); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace TeamWorkPm\Portfolio; | ||
|
||
use TeamWorkPm\Exception; | ||
use TeamWorkPm\Model; | ||
|
||
class Column extends Model | ||
{ | ||
public function init() | ||
{ | ||
$this->parent = 'column'; | ||
$this->action = 'portfolio/columns'; | ||
|
||
$this->fields = [ | ||
'name' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'displayOrder' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'sortOrder' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'deletedDate' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'dateUpdated' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'hasTriggers' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'boolean'], | ||
], | ||
|
||
'sort' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'canEdit' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'boolean'], | ||
], | ||
|
||
'id' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'dateCreated' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'color' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'string'], | ||
], | ||
|
||
'deleted' => [ | ||
'required' => false, | ||
'attributes' => ['type' => 'boolean'], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Get all the Columns for a Portfolio Board | ||
* GET /portfolio/boards/{boardId}/columns | ||
* | ||
* @param int $boardId | ||
* | ||
* @return \TeamWorkPm\Response\Model | ||
* @throws \TeamWorkPm\Exception | ||
*/ | ||
public function getAllForBoard($boardId) | ||
{ | ||
$boardId = (int) $boardId; | ||
if ($boardId <= 0) { | ||
throw new Exception('Invalid param boardId'); | ||
} | ||
|
||
return $this->rest->get("portfolio/boards/$boardId/columns"); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return int | ||
*/ | ||
public function insert(array $data) | ||
{ | ||
$boardId = empty($data['board_id']) ? 0 : (int) $data['board_id']; | ||
if ($boardId <= 0) { | ||
throw new Exception('Required field board_id'); | ||
} | ||
unset($data['board_id']); | ||
|
||
return $this->rest->post("portfolio/boards/$boardId/columns", $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.