/**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('api.toggl', function () {
         $apiKey = env('TOGGL_API_KEY');
         $description = ServiceDescription::factory($this->app->basePath() . '/vendor/ajt/guzzle-toggl/src/AJT/Toggl/services_v8.json');
         $client = TogglClient::factory(['api_key' => $apiKey, 'debug' => true]);
         $client->setDescription($description);
         return $client;
     });
     $this->app->bind(TogglServiceInterface::class, function () {
         return new TogglService($this->app->make('api.toggl'));
     });
 }
Ejemplo n.º 2
0
/**
 * Save acf metadata when post is saved
 * @param type $post_id
 * @return type
 */
function my_acf_save_post($post_id)
{
    // bail early if no ACF data
    if (empty($_POST['fields']) || empty($_POST['fields']['field_546304dab92d4']) || empty($_POST['fields']['field_546304dab93c8']) || empty($_POST['fields']['field_546613dab92d4'])) {
        return;
    }
    // array of field values
    $fields = $_POST['fields'];
    if (!is_valid_time($fields['field_546304dab92d4']) || !is_valid_time($fields['field_546304dab93c8'])) {
        return;
    }
    // if you want to see what is happening, add debug => true to the factory call
    $toggl_client = TogglClient::factory(array('api_key' => $GLOBALS['Toggl_Helper']->toggl_api_key, 'debug' => false));
    $today = $_POST['fields']['field_546613dab92d4'];
    //calculate duration of the toggl time entries
    $time_entries = get_time_entries($toggl_client, $today);
    if (!empty($time_entries)) {
        $time_entries_duration = 0;
        foreach ($time_entries as $entry) {
            $time_entries_duration += $entry['duration'];
        }
    } else {
        $time_entries_duration = 0;
    }
    $break_time = (double) $_POST['fields']['field_654304dab93c8'];
    if (is_float($break_time)) {
        $workday_in_seconds = get_workday_in_seconds($today) - $break_time * 60 * 60;
        //Lets minus the breaks
    } else {
        $workday_in_seconds = get_workday_in_seconds($today);
    }
    $other_works = $workday_in_seconds - $time_entries_duration;
    $_POST['fields']['field_546304ceb92d3'] = gmdate("H:i:s", $workday_in_seconds);
    if ($GLOBALS['Toggl_Helper']->other_works_id > 0 && $other_works > 0 && is_numeric($other_works)) {
        $toggl_client->CreateTimeEntry(array('time_entry' => array('description' => $GLOBALS['Toggl_Helper']->description, 'pid' => $GLOBALS['Toggl_Helper']->other_works_id, 'created_with' => 'Wordpress-plugin', 'duration' => (int) $other_works, 'start' => $today . 'T17:00:00+00:00')));
    }
    $total = $GLOBALS['Toggl_Helper']->workhours * 60 * 60 - $workday_in_seconds;
    $pre = '-';
    if ($total < 0) {
        $total = -1 * $total;
        $pre = '+';
    }
    $_POST['fields']['field_546304dab94d3'] = $pre . gmdate("H:i:s", $total);
}
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get our necessary arguments from the input.
     $redmineURL = $input->getArgument('redmineURL');
     $redmineAPIKey = $input->getArgument('redmineAPIKey');
     $togglAPIKey = $input->getArgument('togglAPIKey');
     // Init toggl.
     $this->togglClient = TogglClient::factory(array('api_key' => $togglAPIKey));
     $this->togglCurrentUser = $this->togglClient->getCurrentUser();
     $this->togglWorkspaceID = $this->getWorkspaceID();
     if (empty($this->togglWorkspaceID)) {
         $this->output->writeln('<error>No Workspace given</error>');
         return;
     }
     // Init redmine.
     $this->redmineClient = new \Redmine\Client($redmineURL, $redmineAPIKey);
     $from = $input->getOption('fromDate');
     $to = $input->getOption('toDate');
     // Before we handle dates, we need to make sure, a default timezone is set.
     $this->fixTimezone();
     $global_from = new \DateTime($from);
     $global_to = new \DateTime($to);
     // Interval to add 1 second to a time.
     $interval_second = new \DateInterval('PT1S');
     $day_from = clone $global_from;
     // Run each day.
     while ($day_from < $global_to) {
         // Prepare the day to object. We go to the end of the from day, but not
         // any further than the global_to.
         $day_to = clone $day_from;
         $day_to->setTime(23, 59, 59);
         if ($day_to > $global_to) {
             $day_to = clone $global_to;
         }
         $output->writeln(sprintf('Time entries for %s to %s', $day_from->format('D d.m.Y H:i'), $day_to->format('H:i')));
         $entries = $this->getTimeEntries($day_from, $day_to);
         if (empty($entries)) {
             $output->writeln('<comment>No entries given.</comment>');
         } else {
             $output->writeln(sprintf('<info>%d entries given.</info>', count($entries)));
             $this->fixTimeEntries($entries);
             $this->processTimeEntries($entries);
         }
         // The next day to start from.
         $day_from = $day_to->add($interval_second);
     }
     $output->writeln('Finished.');
 }
Ejemplo n.º 4
0
 public function createTimeEntry(array $entry)
 {
     return $this->client->createTimeEntry($entry);
 }
Ejemplo n.º 5
0
<?php

require dirname(__FILE__) . '/../apikey.php';
require dirname(__FILE__) . '/../vendor/autoload.php';
use AJT\Toggl\TogglClient;
// Get the toggl client with your toggl api key
$toggl_client = TogglClient::factory(array('api_key' => $toggl_api_key, 'apiVersion' => $toggl_api_version));
// Get all workspaces
print "getWorkspaces\n";
$workspaces = $toggl_client->getWorkspaces(array());
foreach ($workspaces as $workspace) {
    $id = $workspace['id'];
    print $id . " - " . $workspace['name'] . "\n";
    // Get all users in this workspace
    $users = $toggl_client->getWorkspaceUsers(array('id' => $id));
    print "This workspace has " . count($users) . " users\n";
    foreach ($users as $user) {
        print $user['id'] . ' - ' . $user['fullname'] . "\n";
    }
    print "\n";
}
Ejemplo n.º 6
0
<?php

require dirname(__FILE__) . '/../apikey.php';
require dirname(__FILE__) . '/../vendor/autoload.php';
use AJT\Toggl\TogglClient;
// Get the toggl client with your toggl api key
$toggl_client = TogglClient::factory(array('api_key' => $toggl_api_key, 'apiVersion' => $toggl_api_version, 'debug' => true));
// Create a client
print "createClient\n";
// manually populate variables to create test client
$client_name = "My Toggl Test client";
$wid = 807286;
// Retrieve this with the get-workspaces.php file and update
$client_notes = "11";
echo "What should post is: {$client_name} - {$wid} - {$client_notes}";
$clientdata = array('client' => array('name' => $client_name, 'wid' => $wid, 'notes' => $client_notes));
$response = $toggl_client->createClient($clientdata);
<?php

require dirname(__FILE__) . '/../apikey.php';
require dirname(__FILE__) . '/../vendor/autoload.php';
use AJT\Toggl\TogglClient;
// Get the toggl client with your toggl username and password
$toggl_client = TogglClient::factory(array('username' => $username, 'password' => $password, 'apiVersion' => $toggl_api_version, 'debug' => true));
// Get the current user
$currentUser = $toggl_client->GetCurrentUser();
var_dump($currentUser);
 private function getTogglApi()
 {
     $tokens = $this->_config['toggl_token'];
     if (is_array($tokens)) {
         $question = new ChoiceQuestion('<question>For which team member do you want to invoice time entries?</question>', $tokens);
         $question->setAutocompleterValues(array_keys($tokens));
         $question->setErrorMessage('Answer is invalid.');
         $answer = $this->_questionHelper->ask($this->_input, $this->_output, $question);
         $token = $tokens[$answer];
     } else {
         $token = $tokens;
     }
     return TogglClient::factory(array('api_key' => $token, 'debug' => self::DEBUG_MODE));
 }