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
53 changes: 50 additions & 3 deletions Mite/Mite.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,17 @@ public function addService(Array $data)
* Start tracking
*
* @param int $id
* @return MiteTracker
*/
public function startTracking($id)
{
//PATCH /tracker/:id.json
try
{

$response = $this->Resty->patch('/tracker/'.$id.'.json');
$response = $this->Resty->patch('tracker/'.$id.'.json');

if ($this->Resty->getInfo('http_code') == '200') {
return $response;
return MiteTracker::fromResponse($response);
}
}
catch(\Exception $e)
Expand All @@ -316,6 +316,53 @@ public function startTracking($id)

return false;
}

/**
* get tracking information as either MiteTracker entity if tracker is running, or null if no time entry is currently tracked
* @return MiteTracker|null
*/
public function getTracking()
{
//GET /tracker.json
try
{
$response = $this->Resty->get('tracker.json');

if ($this->Resty->getInfo('http_code') == '200') {
return MiteTracker::fromResponse($response);
}
}
catch(\Exception $e)
{
throw new MiteException('Tracking couldn\'t not be fetched ('.$e->getMessage().').');
}

return null;
}

/**
* Delete tracking and returns the deleted MiteTracker entity
*
* @param int $id
* @return MiteTracker|null
*/
public function stopTracking($id)
{
try
{
$response = $this->Resty->delete('tracker/'.$id.'.json');
if ($this->Resty->getInfo('http_code') == '200')
{
return MiteTracker::fromResponse($response);
}
}
catch (\Exception $e)
{
throw new MiteException('Entity deletion failed "tracker" ('.$e->getMessage().').');
}

return null;
}

/**
* Add entity
Expand Down
44 changes: 44 additions & 0 deletions Mite/MiteTracker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Mite;

/**
* Represents the mite tracker object of the current active time entry
*
* @author Thomas Lauria <[email protected]>
*/
class MiteTracker extends MiteEntity
{
/**
* ID to the current active time entry (MiteTime)
* @var integer
*/
public $id = null;

/**
* The duration of the current time entry in minutes
* @var integer
*/
public $minutes = null;

/**
* The start time of the current time entry in DATE_RFC3339 format
* @var string
*/
public $since = null;

/**
* factory for MiteTracker entities, out of a response object
* @param \stdClass $response
* @return MiteTracker|null
*/
public static function fromResponse(\stdClass $response) {
if(!empty($response->tracker->stopped_time_entry)) {
return new self($response->tracker->stopped_time_entry);
}
if(!empty($response->tracker->tracking_time_entry)) {
return new self($response->tracker->tracking_time_entry);
}
return null;
}
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ $newtime = $mite->addTime(
);
```

Start and stop the current running time:
```php
<?php
// get the current running time tracker
$tracker = $mite->getTracking();

// stop the tracker, where $tracker->id is the id of the corresponding time entry
$mite->stopTracking($tracker->id);

// and start it again:
$mite->startTracking($tracker->id);

```

Look into the code `Mite/Mite.php` for a complete list of methods this library provides.

Contact
Expand Down