mirror of
https://github.com/standardebooks/web.git
synced 2025-07-05 14:20:29 -04:00
56 lines
1 KiB
PHP
56 lines
1 KiB
PHP
<?
|
|
/**
|
|
* @property int $VoteCount
|
|
* @property Poll $Poll
|
|
*/
|
|
class PollItem{
|
|
use Traits\Accessor;
|
|
|
|
public int $PollItemId;
|
|
public int $PollId;
|
|
public string $Name;
|
|
public ?string $Description;
|
|
|
|
protected int $_VoteCount;
|
|
protected Poll $_Poll;
|
|
|
|
|
|
// *******
|
|
// GETTERS
|
|
// *******
|
|
|
|
protected function GetVoteCount(): int{
|
|
if(!isset($this->_VoteCount)){
|
|
$this->_VoteCount = Db::QueryInt('
|
|
SELECT count(*)
|
|
from PollVotes pv
|
|
inner join PollItems pi using (PollItemId)
|
|
where pi.PollItemId = ?
|
|
', [$this->PollItemId]);
|
|
}
|
|
|
|
return $this->_VoteCount;
|
|
}
|
|
|
|
|
|
// ***********
|
|
// ORM METHODS
|
|
// ***********
|
|
|
|
/**
|
|
* @throws Exceptions\PollItemNotFoundException
|
|
*/
|
|
public static function Get(?int $pollItemId): PollItem{
|
|
if($pollItemId === null ){
|
|
throw new Exceptions\PollItemNotFoundException();
|
|
}
|
|
|
|
$result = Db::Query('
|
|
SELECT *
|
|
from PollItems
|
|
where PollItemId = ?
|
|
', [$pollItemId], PollItem::class);
|
|
|
|
return $result[0] ?? throw new Exceptions\PollItemNotFoundException();
|
|
}
|
|
}
|