Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/application/models/BlogPost.php
2010-10-03 01:38:06 +02:00

129 lines
No EOL
2.7 KiB
PHP

<?php
class BlogPost extends Fiktiv_Model_Abstract
{
protected $_data = array();
protected $_default = array(
'id' => 0,
'title' => null,
'content' => null,
'pubDate' => null,
'author' => null,
'isPublished' => false,
'tags' => array(),
);
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;
case 'tags':
$this->setTags($value);
break;
}
}
}
public function setId($id)
{
if (is_numeric($id))
$this->_data['id'] = $id;
}
public function setTitle($title)
{
if (is_string($title) && null == $title[30]) {
$this->_data['title'] = $title;
return true;
}
return false;
}
public function setContent($content)
{
if (is_string($content)) {
$this->_data['content'] = $content;
return true;
}
return false;
}
public function setAuthor($author)
{
if ($author instanceof User) {
$this->_data['author'] = $author;
return true;
}
return false;
}
public function addTag($tag)
{
if (is_string($tag)) {
$this->_data['tags'][] = $tag;
return true;
}
return false;
}
public function setTags(array $tags)
{
// make sure the all elements are strings
foreach ($tags as $tag) {
if (!is_string($tag))
return false;
}
$this->_data['tags'] = $tags;
return true;
}
public function setPubDate($date)
{
if (Fiktiv_Date::isDate($date)) {
$this->_data['pubDate'] = new Fiktiv_Date($date);
} else if ($date instanceof Zend_Date) {
$this->_data['pubDate'] = $date;
} else {
return false;
}
return true;
}
public function isPublished($flag = null)
{
if (null === $flag) {
return $this->_data['isPublished'];
}
$this->_data['isPublished'] = (boolean)$flag;
}
}