moismailzai/clockify

为Clockify API提供粗糙的PHP绑定。我创建这个的主要原因是Clockify内置的报告中没有一个允许将具有重复标题的时间条目进行汇总。

dev-master 2021-01-07 02:33 UTC

This package is auto-updated.

Last update: 2024-09-07 10:42:32 UTC


README

请通过https://github.com/jdecool/clockify-api进行检查。

摘要

为Clockify API提供粗糙的PHP绑定。由于Clockify的网页报告无法汇总具有重复标题的时间条目,因此构建。

安装

通过Composer安装

composer require moismailzai/clockify dev-master

然后在您的PHP代码中包含它

require_once './vendor/autoload.php';

use MoIsmailzai\Clockify;

使用方法

通过使用您的API密钥和您想要生成报告的工作空间创建一个新的Clockify对象来使用它

$clockify = new Clockify( "<< YOUR API KEY >>", "<< YOUR WORKSPACE NAME >>" );

执行任意API调用

要将此作为API的PHP包装器使用,只需将API路径传递给apiRequest方法

$clockify->apiRequest( 'workspaces/' . $clockify->workspaceId . '/projects/' )

您还可以通过包含一个JSON编码的有效负载来执行POST请求

$clockify->apiRequest( 'workspaces/' . $clockify->workspaceId . '/reports/summary/',
    json_encode( array(
        "archived" => "Active",
        "billable" => "BOTH",
        "clientIds" => [],
        "description" => "",
        "endDate" => "2018-10-01T23:59:59.999Z",
        "firstTime" => true,
        "includeTimeEntries" => true,
        "me" => false,
        "name" => "",
        "projectIds" => [],
        "startDate" => "2018-10-01T00:00:00.000Z",
        "tagIds" => [],
        "taskIds" => [],
        "userGroupIds" => [],
        "userIds" => [],
        "zoomLevel" => "week"
    ) )
)

生成每日报告

要生成每日报告,将日期传递给getReportByDay方法

$report = $clockify->getReportByDay( '2018-10-01' );

它将返回一个类似的对象

array(3) {
  ["total"]=>
  string(31) "0 hours, 12 minutes, 38 seconds"
  ["date"]=>
  string(10) "2018-10-01"
  ["projects"]=>
  array(1) {
    ["Project Name"]=>
    array(2) {
      ["time"]=>
      string(31) "3 hours, 38 minutes, 43 seconds"
      ["entries"]=>
      array(1) {
        ["First Entry"]=>
        array(3) {
          ["intervals"]=>
          array(1) {
            [0]=>
            object(stdClass)#1 (3) {
              ["start"]=>
              string(20) "2018-10-01T16:10:00Z"
              ["end"]=>
              string(20) "2018-10-01T16:22:38Z"
              ["duration"]=>
              string(8) "PT12M38S"
            }
          }
          ["total"]=>
          string(9) "PT12M38S"
          ["totalString"]=>
          string(31) "0 hours, 12 minutes, 38 seconds"
        }
      }
    }
  }
}

然后您可以自行格式化或将其传递给内置格式化器

$clockify->formatReport( $report )

它将返回类似的内容


---------------------------------------------------------
 Report for 2018-10-01 (0 hours, 12 minutes, 38 seconds)
---------------------------------------------------------

First Project (0 hours, 12 minutes, 38 seconds): 

• First Entry (0 hours, 12 minutes, 38 seconds)