Skip to content

Commit cc602d3

Browse files
committed
feat: added User Report Settings Templates support (#208)
1 parent 8e24d5c commit cc602d3

14 files changed

+1363
-42
lines changed

src/CrowdinApiClient/Api/UserApi.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use CrowdinApiClient\Model\ProjectMember;
66
use CrowdinApiClient\Model\ProjectMemberAddedStatistics;
77
use CrowdinApiClient\Model\User;
8+
use CrowdinApiClient\Model\UserReportSettingsTemplate;
89
use CrowdinApiClient\ModelCollection;
910

1011
/**
@@ -138,4 +139,95 @@ public function deleteMemberFromProject(int $projectId, int $memberId): void
138139
{
139140
$this->_delete(sprintf('projects/%d/members/%s', $projectId, $memberId));
140141
}
142+
143+
/**
144+
* List User Report Settings Templates
145+
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.settings-templates.getMany API Documentation
146+
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.reports.settings-templates.getMany API Documentation Enterprise
147+
*
148+
* @param int $userId
149+
* @param array $params
150+
* integer $params[limit]<br>
151+
* integer $params[offset]
152+
* @return ModelCollection
153+
*/
154+
public function listReportSettingsTemplates(int $userId, array $params = []): ModelCollection
155+
{
156+
return $this->_list(
157+
sprintf('users/%d/reports/settings-templates', $userId),
158+
UserReportSettingsTemplate::class,
159+
$params
160+
);
161+
}
162+
163+
/**
164+
* Create User Report Settings Template
165+
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.settings-templates.post API Documentation
166+
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.reports.settings-templates.post API Documentation Enterprise
167+
*
168+
* @param int $userId
169+
* @param array $data
170+
* string $data[name] required<br>
171+
* string $data[currency] required<br>
172+
* string $data[unit] required<br>
173+
* array $data[config] required
174+
* @return UserReportSettingsTemplate|null
175+
*/
176+
public function createReportSettingsTemplate(int $userId, array $data): ?UserReportSettingsTemplate
177+
{
178+
return $this->_create(
179+
sprintf('users/%d/reports/settings-templates', $userId),
180+
UserReportSettingsTemplate::class,
181+
$data
182+
);
183+
}
184+
185+
/**
186+
* Get User Report Settings Template
187+
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.settings-templates.get API Documentation
188+
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.reports.settings-templates.get API Documentation Enterprise
189+
*
190+
* @param int $userId
191+
* @param int $reportSettingsTemplateId
192+
* @return UserReportSettingsTemplate|null
193+
*/
194+
public function getReportSettingsTemplate(int $userId, int $reportSettingsTemplateId): ?UserReportSettingsTemplate
195+
{
196+
return $this->_get(
197+
sprintf('users/%d/reports/settings-templates/%d', $userId, $reportSettingsTemplateId),
198+
UserReportSettingsTemplate::class
199+
);
200+
}
201+
202+
/**
203+
* Delete User Report Settings Template
204+
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.settings-templates.delete API Documentation
205+
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.reports.settings-templates.delete API Documentation Enterprise
206+
*
207+
* @param int $userId
208+
* @param int $reportSettingsTemplateId
209+
*/
210+
public function deleteReportSettingsTemplate(int $userId, int $reportSettingsTemplateId): void
211+
{
212+
$this->_delete(sprintf('users/%d/reports/settings-templates/%d', $userId, $reportSettingsTemplateId));
213+
}
214+
215+
/**
216+
* Update User Report Settings Template
217+
* @link https://developer.crowdin.com/api/v2/#operation/api.users.reports.settings-templates.patch API Documentation
218+
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.reports.settings-templates.patch API Documentation Enterprise
219+
*
220+
* @param int $userId
221+
* @param UserReportSettingsTemplate $reportSettingsTemplate
222+
* @return UserReportSettingsTemplate|null
223+
*/
224+
public function updateReportSettingsTemplate(
225+
int $userId,
226+
UserReportSettingsTemplate $reportSettingsTemplate
227+
): ?UserReportSettingsTemplate {
228+
return $this->_update(
229+
sprintf('users/%d/reports/settings-templates/%d', $userId, $reportSettingsTemplate->getId()),
230+
$reportSettingsTemplate
231+
);
232+
}
141233
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CrowdinApiClient\Model;
6+
7+
/**
8+
* @package Crowdin\Model
9+
*/
10+
class HourlyBaseRates extends BaseModel
11+
{
12+
/**
13+
* @var float
14+
*/
15+
protected $hourly;
16+
17+
public function __construct(array $data = [])
18+
{
19+
parent::__construct($data);
20+
21+
$this->hourly = (float)$this->getDataProperty('hourly');
22+
}
23+
24+
public function getHourly(): float
25+
{
26+
return $this->hourly;
27+
}
28+
29+
public function setHourly(float $hourly): void
30+
{
31+
$this->hourly = $hourly;
32+
}
33+
34+
public function toArray(): array
35+
{
36+
return [
37+
'hourly' => $this->hourly,
38+
];
39+
}
40+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CrowdinApiClient\Model;
6+
7+
use InvalidArgumentException;
8+
9+
/**
10+
* @package Crowdin\Model
11+
*/
12+
class HourlyIndividualRates extends BaseModel
13+
{
14+
/**
15+
* @var string[]
16+
*/
17+
protected $languageIds;
18+
19+
/**
20+
* @var int[]
21+
*/
22+
protected $userIds;
23+
24+
/**
25+
* @var float
26+
*/
27+
protected $hourly;
28+
29+
public function __construct(array $data = [])
30+
{
31+
parent::__construct($data);
32+
33+
$this->languageIds = array_map(static function ($languageId): string {
34+
return (string)$languageId;
35+
}, $this->getDataProperty('languageIds') ?? []);
36+
$this->userIds = array_map(static function ($userId): int {
37+
return (int)$userId;
38+
}, $this->getDataProperty('userIds') ?? []);
39+
$this->hourly = (float)$this->getDataProperty('hourly');
40+
}
41+
42+
/**
43+
* @return string[]
44+
*/
45+
public function getLanguageIds(): array
46+
{
47+
return $this->languageIds;
48+
}
49+
50+
/**
51+
* @param array $languageIds
52+
*/
53+
public function setLanguageIds(array $languageIds): void
54+
{
55+
if ($languageIds === []) {
56+
throw new InvalidArgumentException('Argument "languageIds" cannot be empty');
57+
}
58+
59+
foreach ($languageIds as $languageId) {
60+
if (!is_string($languageId)) {
61+
throw new InvalidArgumentException('Argument "languageIds" must be an array of strings');
62+
}
63+
}
64+
65+
$this->languageIds = $languageIds;
66+
}
67+
68+
/**
69+
* @return int[]
70+
*/
71+
public function getUserIds(): array
72+
{
73+
return $this->userIds;
74+
}
75+
76+
/**
77+
* @param int[] $userIds
78+
*/
79+
public function setUserIds(array $userIds): void
80+
{
81+
if ($userIds === []) {
82+
throw new InvalidArgumentException('Argument "userIds" cannot be empty');
83+
}
84+
85+
foreach ($userIds as $userId) {
86+
if (!is_int($userId)) {
87+
throw new InvalidArgumentException('Argument "userIds" must be an array of integers');
88+
}
89+
}
90+
91+
$this->userIds = $userIds;
92+
}
93+
94+
public function getHourly(): float
95+
{
96+
return $this->hourly;
97+
}
98+
99+
public function setHourly(float $hourly): void
100+
{
101+
$this->hourly = $hourly;
102+
}
103+
104+
public function toArray(): array
105+
{
106+
return [
107+
'languageIds' => $this->languageIds,
108+
'userIds' => $this->userIds,
109+
'hourly' => $this->hourly,
110+
];
111+
}
112+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CrowdinApiClient\Model;
6+
7+
use InvalidArgumentException;
8+
9+
/**
10+
* @package Crowdin\Model
11+
*/
12+
class HourlyReportSettingsTemplateConfig extends BaseModel
13+
{
14+
/**
15+
* @var HourlyBaseRates
16+
*/
17+
protected $baseRates;
18+
19+
/**
20+
* @var HourlyIndividualRates[]
21+
*/
22+
protected $individualRates;
23+
24+
public function __construct(array $data = [])
25+
{
26+
parent::__construct($data);
27+
28+
$this->baseRates = new HourlyBaseRates($this->getDataProperty('baseRates') ?? []);
29+
$this->individualRates = array_map(static function (array $individualRates): HourlyIndividualRates {
30+
return new HourlyIndividualRates($individualRates);
31+
}, $this->getDataProperty('individualRates') ?? []);
32+
}
33+
34+
public function getBaseRates(): HourlyBaseRates
35+
{
36+
return $this->baseRates;
37+
}
38+
39+
public function setBaseRates(HourlyBaseRates $baseRates): void
40+
{
41+
$this->baseRates = $baseRates;
42+
}
43+
44+
/**
45+
* @return HourlyIndividualRates[]
46+
*/
47+
public function getIndividualRates(): array
48+
{
49+
return $this->individualRates;
50+
}
51+
52+
/**
53+
* @param HourlyIndividualRates[] $individualRates
54+
*/
55+
public function setIndividualRates(array $individualRates): void
56+
{
57+
if ($individualRates === []) {
58+
throw new InvalidArgumentException('Argument "individualRates" cannot be empty');
59+
}
60+
61+
foreach ($individualRates as $individualRate) {
62+
if (!$individualRate instanceof HourlyIndividualRates) {
63+
throw new InvalidArgumentException(
64+
'Argument "individualRates" must contain only IndividualRates objects'
65+
);
66+
}
67+
}
68+
69+
$this->individualRates = $individualRates;
70+
}
71+
72+
public function toArray(): array
73+
{
74+
return [
75+
'baseRates' => $this->baseRates->toArray(),
76+
'individualRates' => array_map(static function (HourlyIndividualRates $individualRate): array {
77+
return $individualRate->toArray();
78+
}, $this->individualRates),
79+
];
80+
}
81+
}

src/CrowdinApiClient/Model/Report.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ class Report extends BaseModel
6161
public const UNIT_WORDS = 'words';
6262
public const UNIT_CHARS = 'chars';
6363
public const UNIT_CHARS_WITH_SPACES = 'chars_with_spaces';
64+
public const UNIT_HOURS = 'hours';
6465

6566
public const UNITS = [
6667
self::UNIT_STRINGS,
6768
self::UNIT_WORDS,
6869
self::UNIT_CHARS,
6970
self::UNIT_CHARS_WITH_SPACES,
71+
self::UNIT_HOURS,
7072
];
7173

7274
/**

0 commit comments

Comments
 (0)