132 lines
No EOL
2.4 KiB
PHP
132 lines
No EOL
2.4 KiB
PHP
<?php
|
|
|
|
class BlogPost extends Fiktiv_Model_Abstract
|
|
{
|
|
protected $_id;
|
|
protected $_title;
|
|
protected $_content;
|
|
protected $_author;
|
|
protected $_pubDate;
|
|
protected $_isPublished = false;
|
|
|
|
public function __construct(array $data = array())
|
|
{
|
|
$this->setAttribs($data);
|
|
}
|
|
|
|
public function setAttribs(array $data) {
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
switch(strtolower($key)) {
|
|
case 'title':
|
|
$this->setTitle($value);
|
|
break;
|
|
case 'content':
|
|
$this->setContent($value);
|
|
break;
|
|
case 'author':
|
|
$this->setAuthor($value);
|
|
break;
|
|
case 'pubdate':
|
|
$this->setPubDate(new Zend_Date($value));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getId()
|
|
{
|
|
return $this->_id;
|
|
}
|
|
|
|
public function setId($id)
|
|
{
|
|
if (is_numeric($id))
|
|
$this->_id = $id;
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return $this->_title;
|
|
}
|
|
|
|
public function setTitle($title)
|
|
{
|
|
if (is_string($title) && null == $title[30]) {
|
|
|
|
$this->_title = $title;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public function getContent()
|
|
{
|
|
return $this->_content;
|
|
}
|
|
|
|
public function setContent($content)
|
|
{
|
|
if (is_string($content)) {
|
|
|
|
$this->_content = $content;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public function getAuthor()
|
|
{
|
|
return $this->_author;
|
|
}
|
|
|
|
public function setAuthor($author)
|
|
{
|
|
if ($author instanceof User) {
|
|
|
|
$this->_author = $author;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public function getPubDate()
|
|
{
|
|
return $this->_pubDate;
|
|
}
|
|
|
|
public function setPubDate($date)
|
|
{
|
|
|
|
if (Fiktiv_Date::isDate($date)) {
|
|
|
|
$this->_pubDate = new Fiktiv_Date($date);
|
|
|
|
} else if ($date instanceof Zend_Date) {
|
|
|
|
$this->_pubDate = $date;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function isPublished($flag = null)
|
|
{
|
|
if (null === $flag) {
|
|
return $this->_isPublished;
|
|
}
|
|
|
|
$this->_isPublished = (boolean)$flag;
|
|
}
|
|
} |