Exemplo n.º 1
0
 *      - Click on "Company Settings" in the menu bar on the left
 *      - Click on "Add-ons"
 *      - Locate the "API" add-on and either install it or open the preferences
 *      - Create or edit an application and your access token will be provided
 */
require_once '../tsheets.inc.php';
// Enter your credentials here if you don't want to be prompted each time
$access_token = NULL;
if (!isset($access_token)) {
    $access_token = readline('Enter your access token: ');
}
$tsheets = new TSheetsRestClient(1, $access_token);
//////////////////////////////////////////////////////////////////////////////////
readline('Press enter to get a list of users:');
// Get a list of users
$users = $tsheets->get(ObjectType::Users);
print "TSheets Users\n";
print "-------------\n";
foreach ($users['results']['users'] as $user) {
    print "User: {$user['first_name']} {$user['last_name']}\n";
}
//////////////////////////////////////////////////////////////////////////////////
readline('Press enter to create two new timesheets:');
// Get jobcodes
$jobcodes = $tsheets->get(ObjectType::Jobcodes, array('type' => 'regular'));
// Pick a first user and jobcode to work on
$user = reset($users['results']['users']);
$jobcode = reset($jobcodes['results']['jobcodes']);
// Create two timesheets with a single api call
$request = array();
$request[] = array('user_id' => $user['id'], 'jobcode_id' => $jobcode['id'], 'type' => 'regular', 'start' => '2014-01-18T15:19:21-07:00', 'end' => '2014-01-18T16:19:21-07:00');
 *      - Click on "Company Settings" in the menu bar on the left
 *      - Click on "Add-ons"
 *      - Locate the "API" add-on and either install it or open the preferences
 *      - Create or edit an application and your access token will be provided
 */
require_once '../tsheets.inc.php';
// Enter your credentials here if you don't want to be prompted each time
$access_token = NULL;
if (!isset($access_token)) {
    $access_token = readline('Enter your access token: ');
}
$tsheets = new TSheetsRestClient(1, $access_token);
//////////////////////////////////////////////////////////////////////////////////
readline('Press enter to get a list of reminders:');
// Get a list of users
$reminders = $tsheets->get(ObjectType::Reminders);
print "TSheets Users\n";
print "-------------\n";
foreach ($reminders['results']['reminders'] as $reminders) {
    print "Active: {$reminders['id']} {$reminders['reminder_type']}\n";
    // If User ID is 0, that means it is a global (company wide) reminder
    print "User ID: {$reminders['user_id']}\n";
    print "Reminder: {$reminders['active']} {$reminders['enabled']}\n";
}
//////////////////////////////////////////////////////////////////////////////////
readline('Press enter to add a reminder:');
// Create a clock-in and a clock-out reminder with a single api call
$request = array();
$request[] = array('user_id' => '0', 'reminder_type' => 'clock-in', 'due_time' => '06:00:00', 'due_days_of_week' => 'Mon,Tue,Wed,Thu,Fri', 'distribution_methods' => 'Push', 'active' => 'true', 'enabled' => 'true');
$request[] = array('user_id' => '0', 'reminder_type' => 'clock-out', 'due_time' => '20:00:00', 'due_days_of_week' => 'Mon,Tue,Wed,Thu,Fri', 'distribution_methods' => 'Push', 'active' => 'true', 'enabled' => 'true');
$result = $tsheets->add(ObjectType::Reminders, $request);
Exemplo n.º 3
0
<?php

include_once 'tsheets_api/tsheets.inc.php';
date_default_timezone_set('America/Denver');
$currentDate = date('Y-m-d');
$hour_ago = strtotime('-1 day');
$time = date('c', $hour_ago);
$tsheets = new TSheetsRestClient(1, 'S.1__077e97bad6c2d4a2f315228fe10c71dda352b774');
//$result = $tsheets->get_report(ReportType::Timesheets,
//    array('start_date' => '2015-9-20',
//            'end_date' => $currentDate));
$timesheetArray = array();
for ($i = 0; $i < 100; $i++) {
    $pageNumber = $i + 1;
    $timesheet = $tsheets->get(ObjectType::Timesheets, array('modified_since' => $time, 'page' => $pageNumber));
    $timesheetDeleted = $tsheets->get(ObjectType::TimesheetsDeleted, array('modified_since' => $time, 'page' => $pageNumber));
    foreach ($timesheetDeleted['results']['timesheets_deleted'] as $deleted) {
        $deleted['deleted'] = "true";
        $deleted['duration'] = 0;
        array_push($timesheet['results']['timesheets'], $deleted);
    }
    if (count($timesheet['results']['timesheets']) == 0) {
        break;
    }
    $array = $timesheet['results']['timesheets'];
    $idsArray = array();
    $jobcodeArray = array();
    foreach ($array as $timesheet) {
        array_push($idsArray, $timesheet['user_id']);
        array_push($jobcodeArray, $timesheet['jobcode_id']);
    }
                $status_output .= $_GET['error'] . "<br/>";
                $status_output .= $_GET['error_description'] . "</br></br>";
                break;
            } else {
                $tsheets = new TSheetsRestClient(1, null, $_SESSION['client_id'], $_SESSION['client_secret']);
                $result = $tsheets->get_access_token($_GET['code'], $redirect_uri);
                $_SESSION['access_token'] = $result['access_token'];
                $_SESSION['refresh_token'] = $result['refresh_token'];
                // redirect back to base uri with no params so refresh will work on this page later
                header("Location: {$redirect_uri}");
                die;
            }
        case 'test_request':
            // Called if the "Test a 'User List' Request" button is clicked. Makes an API call using the access token
            $tsheets = new TSheetsRestClient(1, $_SESSION['access_token']);
            $users = $tsheets->get(ObjectType::Users);
            foreach ($users['results']['users'] as $user) {
                $test_request_html .= "<br/>{$user['first_name']} {$user['last_name']}";
            }
            break;
        case 'clear_session':
            session_destroy();
            header("Location: {$redirect_uri}");
            die;
        default:
            break;
    }
} catch (TSheetsException $e) {
    $status_output .= $e->__toString() . "<br/>";
}
if (isset($_SESSION['access_token'])) {