mmi-dao-ex/Article.php

127 lines
1.8 KiB
PHP

<?php
/**
* Class Article
* @author Simon Vieille <simon@deblan.fr>
*/
class Article
{
/**
* @var integer
*/
protected $id;
/**
* @var integer
*/
protected $title;
/**
* @var integer
*/
protected $content;
/**
* @var array $votes;
*/
protected $votes = [];
/**
* @param int $id
* @return Article
*/
public function setId($id)
{
$this->id = (int) $id;
return $this;
}
/**
* @return int $id
*/
public function getId()
{
return $this->id;
}
/**
* @param string $title
* @return Article
*/
public function setTitle($title)
{
$this->title = (string) $title;
return $this;
}
/**
* @return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $content
* @return Article
*/
public function setContent($content)
{
$this->content = (string) $content;
return $this;
}
/**
* @return string $content
*/
public function getContent()
{
return $this->content;
}
/**
* @param Vote $vote
* @return Article
*/
public function addVote(Vote $vote)
{
$this->votes[] = $vote;
return $this;
}
/**
* @param array $votes
* @return Article
*/
public function setVotes(array $votes)
{
foreach ($votes as $vote) {
$vote->setArticle($this);
}
$this->votes = $votes;
return $this;
}
/**
* @return array $votes
*/
public function getVotes()
{
if (empty($this->votes)) {
$this->votes = VoteDao::create()->findByArticle($this);
}
return $this->votes;
}
}