Skip to content

Commit f7e1fba

Browse files
committed
add support for new custom fields api (introduced in redmine 2.4)
1 parent cb29a29 commit f7e1fba

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

README.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Uses [Redmine API](http://www.redmine.org/projects/redmine/wiki/Rest_api/).
1010
* API entry points implementation state :
1111
* OK Attachments
1212
* *NOK Groups - only partially implemented*
13+
* OK Custom Fields
1314
* OK Issues
1415
* OK Issue Categories
1516
* OK Issue Priorities

example.php

+31
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,34 @@
277277
'version' => null,
278278
));
279279
$client->api('wiki')->remove('testProject', 'about');
280+
281+
282+
// ----------------------------
283+
// Issues' stats (see https://github.com/kbsali/php-redmine-api/issues/44)
284+
$issues['all'] = $client->api('issue')->all([
285+
'limit' => 1,
286+
'tracker_id' => 1,
287+
'status_id' => '*',
288+
])['total_count'];
289+
290+
$issues['opened'] = $client->api('issue')->all([
291+
'limit' => 1,
292+
'tracker_id' => 1,
293+
'status_id' => 'open',
294+
])['total_count'];
295+
296+
$issues['closed'] = $client->api('issue')->all([
297+
'limit' => 1,
298+
'tracker_id' => 1,
299+
'status_id' => 'closed',
300+
])['total_count'];
301+
302+
print_r($issues);
303+
/*
304+
Array
305+
(
306+
[all] => 8
307+
[opened] => 7
308+
[closed] => 1
309+
)
310+
*/

lib/Redmine/Api/CustomField.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Redmine\Api;
4+
5+
/**
6+
* Listing custom fields
7+
*
8+
* @link http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields
9+
* @author Kevin Saliou <kevin at saliou dot name>
10+
*/
11+
class CustomField extends AbstractApi
12+
{
13+
private $customFields = array();
14+
15+
/**
16+
* List custom fields
17+
* @link http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields#GET
18+
*
19+
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
20+
* @return array list of custom fields found
21+
*/
22+
public function all(array $params = array())
23+
{
24+
$this->customFields = $this->retrieveAll('/custom_fields.json', $params);
25+
26+
return $this->customFields;
27+
}
28+
29+
/**
30+
* Returns an array of custom fields with name/id pairs
31+
*
32+
* @param boolean $forceUpdate to force the update of the custom fields var
33+
* @return array list of custom fields (id => name)
34+
*/
35+
public function listing($forceUpdate = false)
36+
{
37+
if (empty($this->customFields)) {
38+
$this->all();
39+
}
40+
$ret = array();
41+
foreach ($this->customFields['custom_fields'] as $e) {
42+
$ret[$e['name']] = (int) $e['id'];
43+
}
44+
45+
return $ret;
46+
}
47+
48+
/**
49+
* Get a tracket id given its name
50+
*
51+
* @param string|int $name customer field name
52+
* @return int|false
53+
*/
54+
public function getIdByName($name)
55+
{
56+
$arr = $this->listing();
57+
if (!isset($arr[$name])) {
58+
return false;
59+
}
60+
61+
return $arr[(string) $name];
62+
}
63+
}

lib/Redmine/Client.php

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public function api($name)
9393
case 'group':
9494
$api = new Api\Group($this);
9595
break;
96+
case 'custom_fields':
97+
$api = new Api\CustomField($this);
98+
break;
9699
case 'issue':
97100
$api = new Api\Issue($this);
98101
break;

0 commit comments

Comments
 (0)