Skip to content

Commit 29b2006

Browse files
AlanHolmessimonschaufi
authored andcommitted
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)
1 parent 482997b commit 29b2006

File tree

8 files changed

+816
-0
lines changed

8 files changed

+816
-0
lines changed

src/Portfolio/Board.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace TeamWorkPm\Portfolio;
4+
5+
use TeamWorkPm\Model;
6+
7+
class Board extends Model
8+
{
9+
public function init()
10+
{
11+
$this->parent = 'board';
12+
$this->action = 'portfolio/boards';
13+
14+
$this->fields = [
15+
'canEdit' => [
16+
'required' => false,
17+
'attributes' => ['type' => 'boolean'],
18+
],
19+
20+
'name' => [
21+
'required' => false,
22+
'attributes' => ['type' => 'string'],
23+
],
24+
25+
'displayOrder' => [
26+
'required' => false,
27+
'attributes' => ['type' => 'string'],
28+
],
29+
30+
'description' => [
31+
'required' => false,
32+
'attributes' => ['type' => 'string'],
33+
],
34+
35+
'deletedDate' => [
36+
'required' => false,
37+
'attributes' => ['type' => 'string'],
38+
],
39+
40+
'id' => [
41+
'required' => false,
42+
'attributes' => ['type' => 'string'],
43+
],
44+
45+
'dateCreated' => [
46+
'required' => false,
47+
'attributes' => ['type' => 'string'],
48+
],
49+
50+
'color' => [
51+
'required' => false,
52+
'attributes' => ['type' => 'string'],
53+
],
54+
55+
'deleted' => [
56+
'required' => false,
57+
'attributes' => ['type' => 'boolean'],
58+
],
59+
];
60+
}
61+
62+
/**
63+
* Get all the Portfolio Boards
64+
* GET /portfolio/boards
65+
*
66+
* @return \TeamWorkPm\Response\Model
67+
* @throws \TeamWorkPm\Exception
68+
*/
69+
public function getAll()
70+
{
71+
return $this->rest->get("$this->action");
72+
}
73+
}

src/Portfolio/Card.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace TeamWorkPm\Portfolio;
4+
5+
use TeamWorkPm\Exception;
6+
use TeamWorkPm\Model;
7+
8+
class Card extends Model
9+
{
10+
public function init()
11+
{
12+
$this->parent = 'card';
13+
$this->action = 'portfolio/cards';
14+
15+
$this->fields = [
16+
'projectId' => [
17+
'required' => false,
18+
'attributes' => ['type' => 'string'],
19+
],
20+
21+
// These are only used by the update method
22+
'cardId' => [
23+
'required' => false,
24+
'sibling' => true,
25+
'attributes' => ['type' => 'string'],
26+
],
27+
28+
'columnId' => [
29+
'required' => false,
30+
'sibling' => true, // Dont nest under 'Card'
31+
'attributes' => ['type' => 'string'],
32+
],
33+
34+
'oldColumnId' => [
35+
'required' => false,
36+
'sibling' => true, // Dont nest under 'Card'
37+
'attributes' => ['type' => 'string'],
38+
],
39+
40+
'positionAfterId' => [
41+
'required' => false,
42+
'sibling' => true, // Dont nest under 'Card'
43+
'attributes' => ['type' => 'integer'],
44+
],
45+
];
46+
}
47+
48+
/**
49+
* Get all the Columns for a Portfolio Column
50+
* GET /portfolio/columns/{columnId}/cards
51+
*
52+
* @param int $columnId
53+
*
54+
* @return \TeamWorkPm\Response\Model
55+
* @throws \TeamWorkPm\Exception
56+
*/
57+
public function getAllForColumn($columnId)
58+
{
59+
$columnId = (int) $columnId;
60+
if ($columnId <= 0) {
61+
throw new Exception('Invalid param columnId');
62+
}
63+
64+
return $this->rest->get("portfolio/columns/$columnId/cards");
65+
}
66+
67+
/**
68+
* Adds a project to the given board
69+
*
70+
* @param array $data
71+
*
72+
* @return int
73+
*/
74+
public function insert(array $data)
75+
{
76+
$columnId = empty($data['columnId']) ? 0 : (int) $data['columnId'];
77+
if ($columnId <= 0) {
78+
throw new Exception('Required field columnId');
79+
}
80+
unset($data['columnId']);
81+
82+
if (empty($data['projectId'])) {
83+
throw new Exception('Required field projectId');
84+
}
85+
86+
return $this->rest->post("portfolio/columns/$columnId/cards", $data);
87+
}
88+
89+
/**
90+
* Moves the given card from one board to another
91+
*
92+
* @param array $data
93+
*
94+
* @return bool
95+
* @throws \TeamWorkPm\Exception
96+
*/
97+
public function update(array $data)
98+
{
99+
$cardId = empty($data['id']) ? 0: (int) $data['id'];
100+
if ($cardId <= 0) {
101+
throw new Exception('Required field id');
102+
}
103+
$data['cardId'] = $data['id'];
104+
unset($data['id']);
105+
106+
if (empty($data['columnId'])) {
107+
throw new Exception('Required field columnId');
108+
}
109+
110+
if (empty($data['oldColumnId'])) {
111+
throw new Exception('Required field oldColumnId');
112+
}
113+
114+
return $this->rest->put("$this->action/$cardId/move", $data);
115+
}
116+
117+
}

src/Portfolio/Column.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
namespace TeamWorkPm\Portfolio;
4+
5+
use TeamWorkPm\Exception;
6+
use TeamWorkPm\Model;
7+
8+
class Column extends Model
9+
{
10+
public function init()
11+
{
12+
$this->parent = 'column';
13+
$this->action = 'portfolio/columns';
14+
15+
$this->fields = [
16+
'name' => [
17+
'required' => false,
18+
'attributes' => ['type' => 'string'],
19+
],
20+
21+
'displayOrder' => [
22+
'required' => false,
23+
'attributes' => ['type' => 'string'],
24+
],
25+
26+
'sortOrder' => [
27+
'required' => false,
28+
'attributes' => ['type' => 'string'],
29+
],
30+
31+
'deletedDate' => [
32+
'required' => false,
33+
'attributes' => ['type' => 'string'],
34+
],
35+
36+
'dateUpdated' => [
37+
'required' => false,
38+
'attributes' => ['type' => 'string'],
39+
],
40+
41+
'hasTriggers' => [
42+
'required' => false,
43+
'attributes' => ['type' => 'boolean'],
44+
],
45+
46+
'sort' => [
47+
'required' => false,
48+
'attributes' => ['type' => 'string'],
49+
],
50+
51+
'canEdit' => [
52+
'required' => false,
53+
'attributes' => ['type' => 'boolean'],
54+
],
55+
56+
'id' => [
57+
'required' => false,
58+
'attributes' => ['type' => 'string'],
59+
],
60+
61+
'dateCreated' => [
62+
'required' => false,
63+
'attributes' => ['type' => 'string'],
64+
],
65+
66+
'color' => [
67+
'required' => false,
68+
'attributes' => ['type' => 'string'],
69+
],
70+
71+
'deleted' => [
72+
'required' => false,
73+
'attributes' => ['type' => 'boolean'],
74+
],
75+
];
76+
}
77+
78+
/**
79+
* Get all the Columns for a Portfolio Board
80+
* GET /portfolio/boards/{boardId}/columns
81+
*
82+
* @param int $boardId
83+
*
84+
* @return \TeamWorkPm\Response\Model
85+
* @throws \TeamWorkPm\Exception
86+
*/
87+
public function getAllForBoard($boardId)
88+
{
89+
$boardId = (int) $boardId;
90+
if ($boardId <= 0) {
91+
throw new Exception('Invalid param boardId');
92+
}
93+
94+
return $this->rest->get("portfolio/boards/$boardId/columns");
95+
}
96+
97+
/**
98+
* @param array $data
99+
*
100+
* @return int
101+
*/
102+
public function insert(array $data)
103+
{
104+
$boardId = empty($data['board_id']) ? 0 : (int) $data['board_id'];
105+
if ($boardId <= 0) {
106+
throw new Exception('Required field board_id');
107+
}
108+
unset($data['board_id']);
109+
110+
return $this->rest->post("portfolio/boards/$boardId/columns", $data);
111+
}
112+
}

src/Response/JSON.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public function parse($data, array $headers)
7474
preg_match('!projects/(\d+)/notebooks!', $headers['X-Action'])
7575
) {
7676
$source = [];
77+
} elseif (
78+
isset($source->cards) &&
79+
preg_match('!portfolio/columns/(\d+)/cards!', $headers['X-Action'])
80+
) {
81+
$source = $source->cards;
7782
} else {
7883
$source = current($source);
7984
}

0 commit comments

Comments
 (0)