From 0c97cc9d89e603b0efd463f1d19bbd4583e15fc5 Mon Sep 17 00:00:00 2001 From: vumik Date: Sat, 10 Oct 2015 13:40:44 +0300 Subject: [PATCH 1/3] Init Worklog --- composer.json | 2 +- src/Issue/IssueService.php | 28 ++++++++++++++++++++++------ src/Issue/Worklog.php | 26 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/Issue/Worklog.php diff --git a/composer.json b/composer.json index a3f6cce7..b2f86cfa 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "lesstif/php-jira-rest-client", "description": "JIRA REST API Client for PHP Users.", "type": "library", - "keywords": ["jira", "jira-php", "jira-rest"], + "keywords": ["jira", "rest", "jira-php", "jira-rest"], "require": { "php": ">=5.4.0", "netresearch/jsonmapper": "~0.5", diff --git a/src/Issue/IssueService.php b/src/Issue/IssueService.php index 20820219..64c55331 100644 --- a/src/Issue/IssueService.php +++ b/src/Issue/IssueService.php @@ -224,8 +224,8 @@ public function search($jql, $startAt=0, $maxResults=15, $fields=[]) /** * get TimeTracking info - * - * @param type $issueIdOrKey + * + * @param type $issueIdOrKey * @return type @TimeTracking */ public function getTimeTracking($issueIdOrKey) @@ -249,7 +249,7 @@ public function getTimeTracking($issueIdOrKey) * @return type @TimeTracking */ public function timeTracking($issueIdOrKey, $timeTracking) - { + { $array = ["update" => [ "timetracking" => [ @@ -263,11 +263,27 @@ public function timeTracking($issueIdOrKey, $timeTracking) $this->log->addDebug("TimeTracking req=$data\n"); // if success, just return HTTP 201. - $ret = $this->exec($this->uri . "/$issueIdOrKey", $data, 'PUT'); + $ret = $this->exec($this->uri . "/$issueIdOrKey", $data, 'PUT'); return $ret; } -} -?> + /** + * get getWorklog + * + * @param mixed $issueIdOrKey + * @return Worklog + */ + public function getWorklog($issueIdOrKey) + { + $ret = $this->exec($this->uri . "/$issueIdOrKey/worklog", null); + $this->log->addDebug("getWorklog res=$ret\n"); + $issue = $this->json_mapper->map( + json_decode($ret), new Issue() + ); + + return $issue->fields->worklog; + } + +} diff --git a/src/Issue/Worklog.php b/src/Issue/Worklog.php new file mode 100644 index 00000000..2027686d --- /dev/null +++ b/src/Issue/Worklog.php @@ -0,0 +1,26 @@ + + * Specify data which should be serialized to JSON + * + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + */ + function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } + +} From e14ae765899df668a2c2a2136f08cdc60fdaa049 Mon Sep 17 00:00:00 2001 From: vumik Date: Sat, 10 Oct 2015 19:23:09 +0300 Subject: [PATCH 2/3] Worklog implemented --- README.md | 23 ++++++++++ src/Issue/IssueService.php | 12 +++--- src/Issue/Worklog.php | 88 ++++++++++++++++++++++++++++++++++---- 3 files changed, 107 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 70a3314d..ad3269a6 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ copy .env.example file to .env on your project root. - [Perform a transition on an issue](#perform-a-transition-on-an-issue) - [Perform an advanced search, using the JQL](#perform-an-advanced-search) - [Issue time tracking](#issue-time-tracking) +- [Issue worklog](#issue-worklog) ## Get Project Info @@ -328,6 +329,28 @@ try { ?> ```` +## Issue worklog + +````php +getWorklog($issue->key)->getWorklogs(); + var_dump($ret); +} catch (JIRAException $e) { + $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage()); +} +?> +```` + # License Apache V2 License diff --git a/src/Issue/IssueService.php b/src/Issue/IssueService.php index 64c55331..664730c1 100644 --- a/src/Issue/IssueService.php +++ b/src/Issue/IssueService.php @@ -272,18 +272,16 @@ public function timeTracking($issueIdOrKey, $timeTracking) * get getWorklog * * @param mixed $issueIdOrKey - * @return Worklog + * @return Worklog Return Worklog object */ public function getWorklog($issueIdOrKey) { - $ret = $this->exec($this->uri . "/$issueIdOrKey/worklog", null); + $ret = $this->exec($this->uri . "/$issueIdOrKey/worklog"); $this->log->addDebug("getWorklog res=$ret\n"); - - $issue = $this->json_mapper->map( - json_decode($ret), new Issue() + $worklog = $this->json_mapper->map( + json_decode($ret), new Worklog() ); - - return $issue->fields->worklog; + return $worklog; } } diff --git a/src/Issue/Worklog.php b/src/Issue/Worklog.php index 2027686d..9d2795ef 100644 --- a/src/Issue/Worklog.php +++ b/src/Issue/Worklog.php @@ -7,20 +7,90 @@ * * @package JiraRestApi\Issue */ -class Worklog implements \JsonSerializable +class Worklog { + /** + * @var int Start at position + */ + protected $startAt; + + /** + * @var int Maximum results + */ + protected $maxResults; + + /** + * @var int Total results + */ + protected $total; + + /** + * @var array Worklogs + */ + protected $worklogs; + + /** + * @return int + */ + public function getStartAt() + { + return $this->startAt; + } + + /** + * @param int $startAt + */ + public function setStartAt($startAt) + { + $this->startAt = $startAt; + } + + /** + * @return int + */ + public function getMaxResults() + { + return $this->maxResults; + } + + /** + * @param int $maxResults + */ + public function setMaxResults($maxResults) + { + $this->maxResults = $maxResults; + } + + /** + * @return int + */ + public function getTotal() + { + return $this->total; + } + + /** + * @param int $total + */ + public function setTotal($total) + { + $this->total = $total; + } + + /** + * @return array Worklogs + */ + public function getWorklogs() + { + return $this->worklogs; + } /** - * (PHP 5 >= 5.4.0)
- * Specify data which should be serialized to JSON - * - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. + * @param array $worklogs Worklogs */ - function jsonSerialize() + public function setWorklogs($worklogs) { - return array_filter(get_object_vars($this)); + $this->worklogs = $worklogs; } } From 570d6c4dc63b1c063506896fcab0b1b4c7bf470e Mon Sep 17 00:00:00 2001 From: vumik Date: Sat, 10 Oct 2015 19:31:34 +0300 Subject: [PATCH 3/3] Fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad3269a6..9a313220 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ try { $issueService = new IssueService(); // get issue's worklog - $worklogs = $issueService->getWorklog($issue->key)->getWorklogs(); + $worklogs = $issueService->getWorklog($issueKey)->getWorklogs(); var_dump($ret); } catch (JIRAException $e) { $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());