Skip to content

Commit

Permalink
Merge pull request #1 from RandomWeasel/RandomWeasel-additional-methods
Browse files Browse the repository at this point in the history
Add additional methods to services
  • Loading branch information
djam90 authored Oct 31, 2018
2 parents 4d631ac + 7a7319e commit 70d33b1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/Services/TaskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ public function getPage($page, $perPage = null)
{
return $this->get(null, null, $page, $perPage);
}

/**
* Get all tasks
*
* @param boolean|null $isActive Pass true to only return active tasks and false to return inactive tasks.
* @param mixed|null $updatedSince Only return tasks that have been updated since the given date and time.
*
* @return mixed
*/
public function getAll(
$isActive = null,
$updatedSince = null
)
{
$batch = $this->get($isActive, $updatedSince);
$items = $batch->{$this->path};
$totalPages = $batch->total_pages;

if ($totalPages > 1) {
while (!is_null($batch->next_page)) {
$batch = $this->getPage($isActive, $updatedSince, $batch->next_page);
$items = $items->merge($batch->{$this->path});
}
}
return $this->transformResult($items);
}

/**
* Retrieve a task.
Expand Down Expand Up @@ -175,4 +201,4 @@ public function delete($taskId)

return $this->api->delete($uri);
}
}
}
20 changes: 17 additions & 3 deletions src/Services/TimeEntryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,29 @@ public function getLastPage($userId = null, $clientId = null, $projectId = null)
* @param int|null $userId
* @param int|null $clientId
* @param int|null $projectId
* @param boolean|null $isBilled Pass true to only return time entries that have been invoiced and false to return time entries that have not been invoiced.
* @param boolean|null $isRunning Pass true to only return running time entries and false to return non-running time entries.
* @param mixed|null $updatedSince Only return time entries that have been updated since the given date and time.
* @param mixed|null $from Only return time entries with a spent_date on or after the given date.
* @param mixed|null $to Only return time entries with a spent_date on or before the given date.
* @return \Djam90\Harvest\Objects\PaginatedCollection|mixed|static
*/
public function getAll($userId = null, $clientId = null, $projectId = null)
public function getAll(
$userId = null,
$clientId = null,
$projectId = null,
$isBilled = null,
$isRunning = null,
$updatedSince = null,
$from = null,
$to = null
)
{
if (is_null($userId) && is_null($clientId) && is_null($projectId)) {
throw new \InvalidArgumentException("TimeEntryService does not support getAll without a user ID, client ID or project ID provided.");
}

$batch = $this->get($userId, $clientId, $projectId);
$batch = $this->get($userId, $clientId, $projectId, $isBilled, $isRunning, $updatedSince, $from, $to);
$items = $batch->{$this->path};
$totalPages = $batch->total_pages;

Expand Down Expand Up @@ -363,4 +377,4 @@ public function stop($timeEntryId)

return $this->api->patch($uri, $data);
}
}
}

0 comments on commit 70d33b1

Please sign in to comment.