2023-02-12 18:36:33 -05:00
|
|
|
<?php
|
|
|
|
|
2023-02-14 17:35:16 -05:00
|
|
|
|
2024-10-02 00:18:12 -04:00
|
|
|
namespace TgBotLib\Objects;
|
2023-02-12 18:36:33 -05:00
|
|
|
|
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
|
|
|
|
|
|
|
class ProximityAlertTriggered implements ObjectTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
private $traveler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
private $watcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $distance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User that triggered the alert
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function getTraveler(): User
|
|
|
|
{
|
|
|
|
return $this->traveler;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User that set the alert
|
|
|
|
*
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function getWatcher(): User
|
|
|
|
{
|
|
|
|
return $this->watcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The distance between the users
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getDistance(): int
|
|
|
|
{
|
|
|
|
return $this->distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array representation of the object.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'traveler' => ($this->traveler instanceof ObjectTypeInterface) ? $this->traveler->toArray() : $this->traveler,
|
|
|
|
'watcher' => ($this->watcher instanceof ObjectTypeInterface) ? $this->watcher->toArray() : $this->watcher,
|
|
|
|
'distance' => $this->distance,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the object from an array representation.
|
|
|
|
*
|
|
|
|
* @param array $data
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return ProximityAlertTriggered
|
2023-02-12 18:36:33 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-12 18:36:33 -05:00
|
|
|
{
|
|
|
|
$object = new self();
|
2023-02-14 17:35:16 -05:00
|
|
|
$object->traveler = isset($data['traveler']) && is_array($data['traveler']) ? User::fromArray($data['traveler']) : $data['traveler'];
|
|
|
|
$object->watcher = isset($data['watcher']) && is_array($data['watcher']) ? User::fromArray($data['watcher']) : $data['watcher'];
|
2023-02-12 18:36:33 -05:00
|
|
|
$object->distance = $data['distance'];
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|