Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TruckersMP\APIClient\Models;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use TruckersMP\APIClient\Client;

class Company extends Model
Expand Down Expand Up @@ -110,6 +111,13 @@ class Company extends Model
*/
protected Game $games;

/**
* The required DLCs of the company.
*
* @var Collection
*/
protected Collection $dlcs;

/**
* The number of members in the company.
*
Expand Down Expand Up @@ -190,6 +198,9 @@ public function __construct(Client $client, array $company)
$this->getValue('games.ets'),
);

$this->dlcs = (new Collection($this->getValue('dlcs', [])))
->map(fn (string $name, $id) => new Dlc($id, $name));

$this->membersCount = $this->getValue('members_count');
$this->recruitment = $this->getValue('recruitment');
$this->language = $this->getValue('language');
Expand Down Expand Up @@ -338,6 +349,16 @@ public function getGames(): Game
return $this->games;
}

/**
* Get the required DLCs of the company.
*
* @return Collection
*/
public function getDlcs(): Collection
{
return $this->dlcs;
}

/**
* Get the number of members that are part of the company.
*
Expand Down
40 changes: 40 additions & 0 deletions src/Models/CompanyMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace TruckersMP\APIClient\Models;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use TruckersMP\APIClient\Client;

class CompanyMember extends Model
Expand All @@ -28,13 +29,27 @@ class CompanyMember extends Model
*/
protected string $username;

/**
* URL to the avatar used on the website.
*
* @var string
*/
protected string $avatar;

/**
* The player's Steam ID.
*
* @var string
*/
protected string $steamId;

/**
* The player's roles within the company.
*
* @var Collection
*/
protected Collection $roles;

/**
* The player's role ID within the company.
*
Expand Down Expand Up @@ -77,7 +92,12 @@ public function __construct(Client $client, array $member)
$this->id = $this->getValue('id');
$this->userId = $this->getValue('user_id');
$this->username = $this->getValue('username');
$this->avatar = $this->getValue('avatar');
$this->steamId = (string) $this->getValue('steam_id');

$roles = new Collection($this->getValue('roles', []));
$this->roles = $roles->map(fn (array $role) => new CompanyRole($client, $role));

$this->roleId = $this->getValue('role_id');
$this->role = $this->getValue('role');
$this->owner = $this->getValue('is_owner', false);
Expand Down Expand Up @@ -114,6 +134,16 @@ public function getUsername(): string
return $this->username;
}

/**
* Get the URL of the member's avatar.
*
* @return string
*/
public function getAvatar(): string
{
return $this->avatar;
}

/**
* Get the Steam ID of the member.
*
Expand All @@ -124,6 +154,16 @@ public function getSteamId(): string
return $this->steamId;
}

/**
* Get the roles of the member within the company.
*
* @return Collection
*/
public function getRoles(): Collection
{
return $this->roles;
}

/**
* Get the Role ID of the member.
*
Expand Down
130 changes: 130 additions & 0 deletions src/Models/CompanyPartnership.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace TruckersMP\APIClient\Models;

use Carbon\Carbon;
use TruckersMP\APIClient\Client;

class CompanyPartnership extends Model
{
/**
* The ID of the company partnership.
*
* @var int
*/
protected int $id;

/**
* The status of the company partnership.
*
* @var string
*/
protected string $status;

/**
* The date and time the partnership was first requested at by the sender.
*
* @var Carbon
*/
protected Carbon $createdAt;

/**
* The date and time the partnership was last updated at.
*
* @var Carbon
*/
protected Carbon $updatedAt;

/**
* The company that sent the partnership request.
*
* @var Company
*/
protected Company $sender;

/**
* The company that received the partnership request.
*
* @var Company
*/
protected Company $receiver;

/**
* Create a new CompanyPartnership instance.
*
* @param Client $client
* @param array $partnership
* @return void
*/
public function __construct(Client $client, array $partnership)
{
parent::__construct($client, $partnership);

$this->id = $this->getValue('id');
$this->status = $this->getValue('status');
$this->createdAt = new Carbon($this->getValue('created_at'), 'UTC');
$this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC');
$this->sender = new Company($client, $this->getValue('sender'));
$this->receiver = new Company($client, $this->getValue('receiver'));
}

/**
* Get the ID of the partnership.
*
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* Get the status of the partnership. The API only returns accepted partnerships.
*
* @return string
*/
public function getStatus(): string
{
return $this->status;
}

/**
* Get the date which the partnership was first requested at by the sender.
*
* @return Carbon
*/
public function getCreatedAt(): Carbon
{
return $this->createdAt;
}

/**
* Get the date which the partnership was last updated at due to the status changing.
*
* @return Carbon
*/
public function getUpdatedAt(): Carbon
{
return $this->updatedAt;
}

/**
* Get the company that sent the partnership request.
*
* @return Company
*/
public function getSender(): Company
{
return $this->sender;
}

/**
* Get the company that received the partnership request.
*
* @return Company
*/
public function getReceiver(): Company
{
return $this->receiver;
}
}
58 changes: 58 additions & 0 deletions src/Models/CompanyPartnershipIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace TruckersMP\APIClient\Models;

use Illuminate\Support\Collection;
use TruckersMP\APIClient\Client;

class CompanyPartnershipIndex
{
/**
* The accepted partnerships of the company.
*
* @var Collection
*/
protected Collection $partners;

/**
* The number of pending partnership requests involving the company.
*
* @var int
*/
protected int $pendingRequestsCount;

/**
* Create a new CompanyPartnershipIndex instance.
*
* @param Client $client
* @param array $response
* @return void
*/
public function __construct(Client $client, array $response)
{
$this->partners = (new Collection($response['partners']))
->map(fn (array $partnership) => new CompanyPartnership($client, $partnership));

$this->pendingRequestsCount = $response['pending_requests_count'] ?? 0;
}

/**
* Get the collection of accepted company partnerships.
*
* @return Collection
*/
public function getPartners(): Collection
{
return $this->partners;
}

/**
* Get the number of pending partnership requests involving the company.
*
* @return int
*/
public function getPendingRequestsCount(): int
{
return $this->pendingRequestsCount;
}
}
18 changes: 18 additions & 0 deletions src/Models/CompanyRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class CompanyRole extends Model
*/
protected int $order;

/**
* The color of the role.
*
* @var string
*/
protected string $color;

/**
* The owner of the company.
*
Expand Down Expand Up @@ -63,6 +70,7 @@ public function __construct(Client $client, array $role)
$this->id = $this->getValue('id');
$this->name = $this->getValue('name');
$this->order = $this->getValue('order');
$this->color = $this->getValue('color');
$this->owner = $this->getValue('owner', false);
$this->createdAt = new Carbon($this->getValue('created_at'), 'UTC');
$this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC');
Expand Down Expand Up @@ -98,6 +106,16 @@ public function getOrder(): int
return $this->order;
}

/**
* Get the color of the role.
*
* @return string
*/
public function getColor(): string
{
return $this->color;
}

/**
* Check if the role is the role of the company owner.
*
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ public function __construct(Client $client, array $event)

$this->attendance = new EventAttendance($client, $this->getValue('attendances', []));

$this->dlcs = (new Collection($this->getValue('dlcs', [])))->mapInto(Dlc::class);
$this->dlcs = (new Collection($this->getValue('dlcs', [])))
->map(fn (string $name, $id) => new Dlc($id, $name));

$this->createdAt = new Carbon($this->getValue('created_at'), 'UTC');
$this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC');
Expand Down
Loading