Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional methods to services #1

Merged
merged 2 commits into from
Oct 31, 2018
Merged
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
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);
}
}
}