-
Notifications
You must be signed in to change notification settings - Fork 0
/
Posts.php
164 lines (157 loc) · 5.07 KB
/
Posts.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/*
Copyright (C) 2008 Jesse Hogan <jessehogan0@gmail.com>
All rights reserverd
*/
// vim: set et ts=4 sw=4 fdm=marker:
require_once("Business_Objects.php");
require_once("Users.php");
class Posts extends Business_Collection_Base{
function __construct($parent=null){
$this->Business_Collection_Base();
if ($parent != null){
$className = strtolower(get_class($parent));
if ($className == 'movie'){
if (!$parent->IsNew()){
$id = $parent->ID();
$this->LoadWhere("movieID = $id and parentID = 0");
}
}
}
}
}
class Post extends Business_Base {
var $_posts;
function __construct($id=null){
$this->Business_Base($id);
if ($id == null){
$this->DatePosted(time());
}
}
function Text($value=null) {
return $this->SetVar(__FUNCTION__, $value);
}
function AbuseReportCount($value=null) {
return $this->SetVar(__FUNCTION__, $value);
}
function DatePosted($value=null) {
return $this->SetVar(__FUNCTION__, $value);
}
function Username($value=null) {
return $this->SetVar(__FUNCTION__, $value);
}
public function ParentID($value=null){
return $this->SetVar(__FUNCTION__, $value);
}
public function MovieID($value=null){
return $this->SetVar(__FUNCTION__, $value);
}
public function ViewCount($value=null){
return $this->SetVar(__FUNCTION__, $value);
}
public function Subject($value=null){
return $this->SetVar(__FUNCTION__, $value);
}
public function Disabled($value=null){
return $this->SetVar(__FUNCTION__, $value);
}
public function RecursiveDisabled($value=null){
return $this->SetVar(__FUNCTION__, $value);
}
public function EnableRecursivly(){
$this->RecursiveDisabled(false);
$children =& $this->ChildPosts();
foreach($children as $child){
$child->EnableRecursivly();
}
}
public function DisableRecursivly(){
$this->RecursiveDisabled(true);
$children =& $this->ChildPosts();
foreach($children as $child){
$child->DisableRecursivly();
}
}
public function &ChildPosts(){
$posts = new Posts();
$children =& $this->Posts();
foreach($children as $child){
if ($child->ID() == $this->ID()) continue;
$posts->Add($child);
}
return $posts;
}
public function &User(){
return new User($this->Username());
}
public function &Movie(){
return new Movie($this->MovieID());
}
public function &Parent(){
if ($this->IsParent()){
return $this;
}else{
return new Post($this->ParentID());
}
}
public function IsParent(){
return ($this->ParentID() == 0);
}
public function IsTopic(){
return $this->IsParent();
}
public function &Posts(){
if (! isset($this->_posts)) {
$this->_posts = new Posts();
$this->_posts->_collection[] = $this;
if ($this->HasCollection()){
$col =& $this->Collection();
foreach($col as $post){
if ($post->ParentID() == $this->ID()){
$this->_posts->Add($post);
}
}
}else{
$this->_posts->LoadBy('parentID', $this->ID());
}
}
return $this->_posts;
}
public function Update(){
parent::Update();
$children =& $this->ChildPosts();
foreach($children as $child){
$child->Update();
}
}
function DiscoverTableDefinition(){
/*
AddMap( $method, $field, $type, $unsigned,
$not_null, $default, $length, $autoincrement);
*/
$this->AddMap('ID', 'id', 'integer', true, true, 0, 4, 1);
$this->AddMap('Text', 'txt', 'text', null, true, '', 3000, 0);
$this->AddMap('Subject', 'subject', 'text', null, false, '', 255, 0);
$this->AddMap('AbuseReportCount', 'abuseReportCount', 'integer', true, true, 0, 4, 0);
$this->AddTimestampMap('DatePosted', 'datePosted');
$this->AddMap('Username', 'username', 'text', null, true, '', 50, null);
$this->AddIndex('ParentID', 'parentID, asc, 0');
$this->AddMap('ParentID', 'parentID', 'integer', true, true, 0, 4, 0);
$this->AddIndex('MovieID', 'movieID, asc, 0');
$this->AddMap('MovieID', 'movieID', 'integer', true, true, 0, 4, 0);
$this->AddMap('ViewCount', 'viewCount', 'integer', true, true, 0, 4, 0);
$this->AddBooleanMap('Disabled', 'disabled');
$this->AddBooleanMap('RecursiveDisabled', 'recursiveDisabled');
}
function ToString(){
if ($this->IsTopic()){
return "Topic: ". $this->Subject();
}else{
return "Post: " . substr($this->Text(), 0, 15) . '...';
}
}
function Table(){
return "post";
}
}
?>