Skip to content

Commit 82b2f35

Browse files
author
Artur (Seti) Łabudziński
committed
Adding and Removing groups.
Small fix of casesensitive variable name error. Group list and element objects added.
1 parent 022cbb3 commit 82b2f35

File tree

5 files changed

+92
-3
lines changed

5 files changed

+92
-3
lines changed

src/Account/AccountService.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jira\Api\Account;
44

55
use \Jira\Api\Account\Group;
6+
use \Jira\Api\Account\GroupList;
67

78
class AccountService extends \Jira\Api\Client
89
{
@@ -85,6 +86,38 @@ public function getGroup($name)
8586
return $group;
8687
}
8788

89+
public function findGroups($query = '')
90+
{
91+
if (self::$isJIRAUtf8)
92+
$ret = $this->exec($this->uri.'s/picker?maxResults=1&'.($query?('query=' . str_replace(' ', '+', urlencode($query)).'&useUnicode=true&characterEncoding=unicode'):''));
93+
else
94+
$ret = $this->exec($this->uri.'s/picker?maxResults=1&'.($query?('query=' . str_replace(' ', '+', urlencode($query))):''));// .'&useUnicode=false&characterEncoding=unicode');
95+
// $ret = $this->exec($this->uri.'?groupname=' . ($this->filterName($name,'+')) .'&useUnicode=true&characterEncoding=UTF8');
96+
// $ret = $this->exec($this->uri, $json, 'POST');
97+
// $ret = $this->exec($this->uri.'/member?groupname=' . $name);
98+
//var_dump($ret);
99+
100+
$groups = $this->json_mapper->map(
101+
json_decode($ret), new GroupList()
102+
);
103+
104+
if (self::$isJIRAUtf8)
105+
$ret = $this->exec($this->uri.'s/picker?maxResults='.$groups->total.'&'.($query?('query=' . str_replace(' ', '+', urlencode($query)).'&useUnicode=true&characterEncoding=unicode'):''));
106+
else
107+
$ret = $this->exec($this->uri.'s/picker?maxResults='.$groups->total.'&'.($query?('query=' . str_replace(' ', '+', urlencode($query))):''));// .'&useUnicode=false&characterEncoding=unicode');
108+
// $ret = $this->exec($this->uri.'?groupname=' . ($this->filterName($name,'+')) .'&useUnicode=true&characterEncoding=UTF8');
109+
// $ret = $this->exec($this->uri, $json, 'POST');
110+
// $ret = $this->exec($this->uri.'/member?groupname=' . $name);
111+
//var_dump($ret);
112+
113+
$groups = $this->json_mapper->map(
114+
json_decode($ret), new GroupList()
115+
);
116+
117+
118+
return $groups;
119+
}
120+
88121
/**
89122
* @return \Jira\Api\Account\Group[]
90123
*/
@@ -135,7 +168,7 @@ public function createGroup($name)
135168
$json = json_encode([
136169
'name' => $this->filterName($name),
137170
]);
138-
var_dump($json);
171+
// var_dump($json);
139172
try {
140173
$ret = $this->exec($this->uri, $json, 'POST');
141174
} catch (\Exception $e) {
@@ -151,4 +184,22 @@ public function createGroup($name)
151184

152185
return $group;
153186
}
187+
188+
public function removeGroup($name)
189+
{
190+
$json = json_encode([
191+
'groupname' => $this->filterName($name),
192+
'name' => $this->filterName($name),
193+
'group' => $this->filterName($name),
194+
]);
195+
$ret = false;
196+
try {
197+
$ret = $this->exec($this->uri . '?groupname='.str_replace(' ', '+', urlencode($name)).'&useUnicode=true&characterEncoding=unicode', null, 'DELETE');
198+
} catch (\Exception $e) {
199+
return false;
200+
// var_dump($e->getMessage());
201+
}
202+
203+
return $ret;
204+
}
154205
}

src/Account/GroupElement.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace Jira\Api\Account;
3+
4+
5+
class GroupElement //implements \JsonSerializable
6+
{
7+
/** @var string */
8+
public $name;
9+
/** @var string */
10+
public $html;
11+
/** @var string[] */
12+
public $labels;
13+
}

src/Account/GroupList.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Jira\Api\Account;
4+
5+
class GroupList implements \JsonSerializable
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public $header;
11+
12+
/* @var integer */
13+
public $total;
14+
15+
/** @var GroupElement[] */
16+
public $groups;
17+
18+
public function jsonSerialize()
19+
{
20+
return array_filter(get_object_vars($this));
21+
}
22+
}

src/Client.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public function exec($context, $post_data = null, $custom_request = null, $tries
181181
}
182182
if (!is_null($custom_request) && $custom_request == 'DELETE') {
183183
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
184+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
184185
} else {
185186
curl_setopt($ch, CURLOPT_POST, true);
186187
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
@@ -195,9 +196,11 @@ public function exec($context, $post_data = null, $custom_request = null, $tries
195196
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
196197
curl_setopt($ch, CURLOPT_USERAGENT, self::$UserAgent . ($this->getConfiguration()->getUserAgent() ? ' ['.$this->getConfiguration()->getUserAgent().']' : ''));
197198
curl_setopt($ch, CURLOPT_HTTPHEADER,
198-
array('Accept: */*', 'Content-Type: application/json'));
199+
array('Accept: */*', 'Content-Type: application/json')
200+
);
199201
curl_setopt($ch, CURLOPT_VERBOSE, $this->getConfiguration()->isCurlOptVerbose());
200202
$this->log->addDebug("Curl [".($custom_request ? $custom_request : 'GET')."] exec=".$url);
203+
// echo "Curl [".($custom_request ? $custom_request : 'GET')."] exec=".$url;
201204

202205
if ($context === 'issue' && strtolower($custom_request) === 'delete') {
203206
$url .= '/'.$post_data;

src/Issue/IssueField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function getIssueType()
190190
public $progress;
191191

192192
/** @var TimeTracking */
193-
public $timeTracking;
193+
public $timetracking;
194194

195195
/** @var IssueType */
196196
public $issuetype;

0 commit comments

Comments
 (0)