Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions src/Project/PaginatedResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php

namespace JiraCloud\Project;

/**
* Paginated Result object for BoardService.
*/
class PaginatedResult
{
/**
* @var int
*/
public $startAt;

/**
* @var int
*/
public $maxResults;

/**
* @var string
*/
public $nextPage;

/**
* @var string
*/
public $self;

/**
* @var int
*/
public $total;

/**
* @var array
*/
public $values;

/**
* @var bool
*/
public $isLast;

/**
* @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 string
*/
public function getNextPage()
{
return $this->nextPage;
}

/**
* @param string $nextPage
*/
public function setNextPage($nextPage)
{
$this->nextPage = $nextPage;
}

/**
* @return string
*/
public function getSelf()
{
return $this->self;
}

/**
* @param string $self
*/
public function setSelf($self)
{
$this->self = $self;
}

/**
* @return int
*/
public function getTotal()
{
return $this->total;
}

/**
* @param int $total
*/
public function setTotal($total)
{
$this->total = $total;
}

/**
* @return array
*/
public function getValues()
{
return $this->values;
}

/**
* @param array $values
*/
public function setValues($values)
{
$this->values = $values;
}

/**
* @param int $index
*
* @return mixed
*/
public function getValue($index)
{
return $this->values[$index];
}

/**
* @param bool $isLast
*/
public function setIsLast($isLast)
{
$this->isLast = $isLast;
}

/**
* @return bool
*/
public function getIsLast()
{
return $this->isLast;
}
}
29 changes: 29 additions & 0 deletions src/Project/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ public function getAllProjects($paramArray = [])
return $prjs;
}

/**
* get a paginated list of projects.
*
* @param array $paramArray
*
* @throws \JiraCloud\JiraException
*
* @return PaginatedResult
*/
public function getProjectsPaginated($paramArray = []): PaginatedResult
{
$ret = $this->exec($this->uri.'/search'.$this->toHttpQueryParameter($paramArray), null);

$decodedRet = json_decode($ret, false);

$decodedRet->values = $this->json_mapper->mapArray(
$decodedRet->values,
new \ArrayObject(),
Project::class
);

$prjsPag = $this->json_mapper->map(
$decodedRet,
new PaginatedResult()
);

return $prjsPag;
}

/**
* get Project id By Project Key.
* throws HTTPException if the project is not found, or the calling user does not have permission or view it.
Expand Down
26 changes: 26 additions & 0 deletions tests/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ public function get_project_lists() : string

return $projKey;
}

/**
* @test
*
*/
public function get_project_paginated_lists() : string
{
$projKey = 'TEST';
try {
$proj = new ProjectService();

$prjsPag = $proj->getProjectsPaginated();

foreach ($prjsPag->values as $p) {
$this->assertTrue($p instanceof Project);
$this->assertTrue(strlen($p->key) > 0);
$this->assertTrue(!empty($p->id));
$this->assertTrue(strlen($p->name) > 0);
}
} catch (\Exception $e) {
$this->fail('get_project_paginated_lists ' . $e->getMessage());
}

return $projKey;
}

/**
* @test
* @depends get_project_lists
Expand Down