Skip to content

Commit 073a5a0

Browse files
committed
add JQL pagination example.
1 parent 8e08ff8 commit 073a5a0

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,12 @@ try {
523523
} catch (JiraException $e) {
524524
$this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage());
525525
}
526-
527526
```
528527

529528
#### Perform an advanced search
530529

530+
**Simple Query**
531+
531532
```php
532533
<?php
533534
require 'vendor/autoload.php';
@@ -545,9 +546,64 @@ try {
545546
} catch (JiraException $e) {
546547
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
547548
}
549+
```
550+
551+
552+
553+
**JQL with pagination**
554+
555+
```php
556+
<?php
557+
require 'vendor/autoload.php';
558+
559+
use JiraRestApi\Issue\IssueService;
560+
use JiraRestApi\JiraException;
561+
562+
$jql = 'project not in (TEST) and assignee = currentUser() and status in (Resolved, closed)';
563+
564+
try {
565+
$issueService = new IssueService();
548566

567+
$pagination = -1;
568+
569+
$startAt = 0; //the index of the first issue to return (0-based)
570+
$maxResult = 3; // the maximum number of issues to return (defaults to 50).
571+
$totalCount = -1; // the number of issues to return
572+
573+
// first fetch
574+
$ret = $issueService->search($jql, $startAt, $maxResult);
575+
$totalCount = $ret->total;
576+
577+
// do something with fetched data
578+
foreach ($ret->issues as $issue) {
579+
print (sprintf("%s %s \n", $issue->key, $issue->fields->summary));
580+
}
581+
582+
// fetch remained data
583+
$page = $totalCount / $maxResult;
584+
585+
for ($startAt = 1; $startAt < $page; $startAt++)
586+
{
587+
$ret = $issueService->search($jql, $startAt, $maxResult);
588+
589+
print ("\nPaging $startAt\n");
590+
print ("-------------------\n");
591+
foreach ($ret->issues as $issue) {
592+
print (sprintf("%s %s \n", $issue->key, $issue->fields->summary));
593+
}
594+
}
595+
} catch (JiraException $e) {
596+
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
597+
}
549598
```
550599

600+
601+
602+
603+
604+
605+
606+
551607
#### Issue time tracking
552608

553609
```php

0 commit comments

Comments
 (0)