Updated Poll
This commit is contained in:
parent
b19ed2f36d
commit
d0b4a7cf5c
1 changed files with 23 additions and 87 deletions
|
@ -7,70 +7,25 @@
|
||||||
|
|
||||||
class Poll implements ObjectTypeInterface
|
class Poll implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
private string $id;
|
||||||
* @var string
|
private string $question;
|
||||||
*/
|
|
||||||
private $id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $question;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PollOption[]
|
* @var PollOption[]
|
||||||
*/
|
*/
|
||||||
private $options;
|
private array $options;
|
||||||
|
private int $total_voter_count;
|
||||||
/**
|
private bool $is_closed;
|
||||||
* @var int
|
private bool $is_anonymous;
|
||||||
*/
|
private string $type;
|
||||||
private $total_voter_count;
|
private bool $allow_multiple_answers;
|
||||||
|
private ?int $correct_option_id;
|
||||||
/**
|
private string $explanation;
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $is_closed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $is_anonymous;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $allow_multiple_answers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $correct_option_id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $explanation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
private $explanation_entities;
|
private ?array $explanation_entities;
|
||||||
|
private ?int $open_period;
|
||||||
/**
|
private ?int $close_date;
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $open_period;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $close_date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique poll identifier
|
* Unique poll identifier
|
||||||
|
@ -205,9 +160,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
|
@ -235,15 +188,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs object from array representation
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return Poll
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): self
|
public static function fromArray(?array $data): ?Poll
|
||||||
{
|
{
|
||||||
$object = new self();
|
if($data === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new self();
|
||||||
$object->id = $data['id'] ?? null;
|
$object->id = $data['id'] ?? null;
|
||||||
$object->question = $data['question'] ?? null;
|
$object->question = $data['question'] ?? null;
|
||||||
$object->total_voter_count = $data['total_voter_count'] ?? null;
|
$object->total_voter_count = $data['total_voter_count'] ?? null;
|
||||||
|
@ -255,26 +209,8 @@
|
||||||
$object->explanation = $data['explanation'] ?? null;
|
$object->explanation = $data['explanation'] ?? null;
|
||||||
$object->open_period = $data['open_period'] ?? null;
|
$object->open_period = $data['open_period'] ?? null;
|
||||||
$object->close_date = $data['close_date'] ?? null;
|
$object->close_date = $data['close_date'] ?? null;
|
||||||
|
$object->explanation_entities = isset($data['explanation_entities']) ? array_map(fn($explanation_entity) => MessageEntity::fromArray($explanation_entity), $data['explanation_entities']) : null;
|
||||||
$object->explanation_entities = null;
|
$object->options = isset($data['options']) ? array_map(fn($option) => PollOption::fromArray($option), $data['options']) : null;
|
||||||
if(isset($data['explanation_entities']) && is_array($data['explanation_entities']))
|
|
||||||
{
|
|
||||||
$object->explanation_entities = [];
|
|
||||||
foreach($data['explanation_entities'] as $explanation_entity)
|
|
||||||
{
|
|
||||||
$object->explanation_entities[] = MessageEntity::fromArray($explanation_entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$object->options = null;
|
|
||||||
if(isset($data['options']) && is_array($data['options']))
|
|
||||||
{
|
|
||||||
$object->options = [];
|
|
||||||
foreach($data['options'] as $option)
|
|
||||||
{
|
|
||||||
$object->options[] = PollOption::fromArray($option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue