forked from rkeplin/zf1-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Post.php
66 lines (55 loc) · 1.43 KB
/
Post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class Model_Post extends Keplin_Model_Abstract
{
public $id;
public $title;
public $content;
public $date_added;
public $date_modified;
public $is_published = 0;
public $user; //Model_User
public $category; //Model_Category
public $comments; //Model_CommentCollection
public function setUser(Model_User $user)
{
$this->user = $user;
}
public function setCategory($category)
{
if(is_string($category))
{
$cat = new Model_Category();
$cat->name = $category;
}
else if(is_object($category))
{
$cat = $category;
}
else
{
throw new Exception('The category must be an object, or a string.');
}
$this->category = $cat;
}
public function setComments(Model_CommentsCollection $comments)
{
$this->comments = $comments;
}
public function toArray()
{
$array = parent::toArray();
if(isset($this->category->id) && $this->category->id)
{
$array['category_id'] = $this->category->id;
}
if(isset($this->user) && $this->user->id)
{
$array['user_id'] = $this->user->id;
}
if(!$this->is_published)
{
$array['is_published'] = 0;
}
return $array;
}
}