-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.php
71 lines (62 loc) · 1.56 KB
/
helpers.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
66
67
68
69
70
71
<?php
/*
* @author Kostadin Bashev | Webcode Ltd.
* @copyright Copyright (c) 2023 Webcode Ltd. (https://webcode.bg/)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
/**
* Paginate results same as gitlab.
*
* @param $data
* @param $page
* @param $perPage
* @return array
*/
function paginate($data, $page, $perPage): array
{
$offset = ($page - 1)*$perPage;
return array_slice($data, $offset, $perPage, true);
}
/**
* Workaround for long int ids.
*
* @param $value
* @return int
*/
function convertToInt($value): int
{
return $value > 2147483647 ? - (int)substr($value, 0, 9) : $value;
}
/**
* Convert Unixtimestamp to Gitlab format
*
* @param $timestamp
* @return string
*/
function convertToDate($timestamp): string
{
return date("Y-m-d\TH:i:s.u\Z", round($timestamp/1000));
}
/**
* Get Original Task IDs from local text storage.
*
* Task IDs need to be int, but in clickup they are string and we need to convert them.
*/
function getTaskIds($space): array
{
// Make storage this if not exists.
if (!is_dir(STORAGE_DIR)) {
mkdir(STORAGE_DIR);
}
$storagePath = STORAGE_DIR . DIRECTORY_SEPARATOR . $space;
// Create file is not exists.
if (!file_exists($storagePath)) {
file_put_contents($storagePath, '');
}
// Read current storage.
$storage = file_get_contents($storagePath);
// Make an array with current entries.
$taskIds = explode("\n", $storage);
// Filter empty rows and return data.
return array_filter($taskIds);
}