This repository has been archived by the owner on Feb 17, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
65 lines (54 loc) · 1.87 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
use SpeedyLom\WhenDoYouFinish\HttpRequest\CurlBasicAuthentication;
use SpeedyLom\WhenDoYouFinish\Toggl;
use SpeedyLom\WhenDoYouFinish\Toggl\TrackApi;
use SpeedyLom\WhenDoYouFinish\WebEngine\HtmlTemplate;
use SpeedyLom\WhenDoYouFinish\Workday;
require_once __DIR__ . '/vendor/autoload.php';
$configuration = json_decode(
file_get_contents('configuration.json'),
true
);
if (isset($configuration['environment']) && $configuration['environment'] === 'dev') {
$whoops = new Whoops\Run();
$whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
$whoops->register();
}
$togglReportsApi = new Toggl\ReportsApi(
new CurlBasicAuthentication(
Toggl\ReportsApi::buildWeeklyFiguresUrl(
$configuration['user_agent'],
$configuration['workspace_id']
)
),
$configuration['api_token']
);
$togglReportsApi->requestWeeklyFigures();
$secondsWorkedToday = $togglReportsApi->getTotalSecondsForToday();
$togglTrackApi = new TrackApi(
new CurlBasicAuthentication(
TrackApi::getEndPoint()
),
$configuration['api_token']
);
$togglTrackApi->requestCurrentEntry();
$secondsWorkedToday += $togglTrackApi->getElapsedSecondsForCurrentEntry(time());
$htmlTemplate = new HtmlTemplate(__DIR__ . '/views');
if ($secondsWorkedToday > 0) {
$workday = new Workday(
$configuration['workday_length_in_minutes'] * 60,
$secondsWorkedToday
);
$htmlTemplate->display('current_workday', [
'formattedDate' => date('l jS'),
'formattedCurrentFinishingTime' => $workday->getCurrentFinishingTime(),
'formattedTimeWorked' => $workday->getTimeWorked(),
'percentageWorked' => $workday->getPercentageWorked(),
'title' => 'When Do You Finish?',
]);
} else {
$htmlTemplate->display('nothing_recorded', [
'title' => 'Nothing Recorded',
]);
}