Poll.php 1.75 KB
<?php

namespace FootyRoom\Core\Poll;

use FootyRoom\Core\CoreException;

class Poll
{
    /**
     * @var string
     */
    protected $id;

    /**
     * @var \FootyRoom\Core\Poll\Choice[]
     */
    protected $choices = [];

    /**
     * @var int
     */
    protected $userId;

    /**
     * @var bool
     */
    protected $isPublished = false;

    /**
     * Constructor.
     *
     * @param \FootyRoom\Core\Poll\Choice[] $choices
     * @param int $userId
     */
    public function __construct(array $choices, $userId)
    {
        $this->setChoices($choices);
        $this->userId = $userId;
    }

    /**
     * Gets the value of id.
     *
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Gets the value of choices.
     *
     * @return \FootyRoom\Core\Poll\Choice[]
     */
    public function getChoices()
    {
        return $this->choices;
    }

    /**
     * Gets the value of userId.
     *
     * @return int
     */
    public function getUserId()
    {
        return $this->userId;
    }

    /**
     * Gets the value of isPublished.
     *
     * @return bool
     */
    public function getIsPublished()
    {
        return $this->isPublished;
    }

    /**
     * Edit unpublished poll.
     *
     * @param \FootyRoom\Core\Poll\Choice[] $choices
     */
    public function edit(array $choices)
    {
        if ($this->isPublished) {
            throw new CoreException('Published polls are not allowed to be editted.');
        }

        $this->setChoices($choices);
    }

    /**
     * Set choices of the poll.
     *
     * @param \FootyRoom\Core\Poll\Choice[] $choices
     */
    protected function setChoices(array $choices)
    {
        $this->choices = $choices;
    }
}