Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

base-forum-thread.inc.php

Go to the documentation of this file.
00001 <?
00009 class BaseForumThread extends MyObject
00010 {
00014     public $LastPost = null;
00015 
00019     public $ThreadCommentClass = 'ThreadComment';
00020 
00024     public $Forum = null;
00025 
00029     public $ForumClass = 'Forum';
00030 
00034     public function __construct($data = null, $table = 'threads')
00035     {
00036         $this->commentsEnabled = true;
00037 
00038         parent::__construct($data, $table);
00039 
00040         $this->english = 'thread';
00041         
00042         $this->fullTextFields[] = 'subject';
00043     }
00044     
00048     public function getName($link = false)
00049     {
00050         return parent::getName($link, $this->subject);
00051     }
00052 
00056     public function drawHeaderRow()
00057     {
00058 ?>
00059     <tr>
00060         <th>Subject</th>
00061         <th>Posts</th>
00062         <th>Last Post</th>
00063         <th>Creator</th>
00064     </tr>
00065 <?  
00066     }
00067     
00071     public function drawRow()
00072     {
00073 ?>
00074     <tr>
00075         <th><?=$this->getName(true)?></th>
00076         <td><?=$this->comment_count?>
00077         <td>
00078             <?=$this->LastPost->creator->getName(true)?> 
00079             <?=Time::formatRelative($this->LastPost->add_date)?>
00080         </td>
00081         <td>
00082             <?=$this->creator->getName(true)?>
00083         </td>
00084     </tr>
00085 <?
00086     }
00087 
00091     public function canView()
00092     {
00093         return true;
00094     }
00095 
00099     public function canEdit()
00100     {
00101         global $me;
00102 
00103         return $me->isAdmin();
00104     }
00105 
00109     public function canDelete()
00110     {
00111         return $this->canEdit();
00112     }
00113 
00117     public function editFormAddFields($form)
00118     {
00119         $form->add('TextField', 'subject', array(
00120             'required' => true,
00121             'width' => '100%'
00122         ));
00123 
00124         $form->addSubmit('Update Thread');
00125     }
00126 
00130     public function delete()
00131     {
00132         parent::delete();
00133         
00134         //save our forum
00135         $this->Forum->save();
00136     }
00137 
00141     public function deletePost()
00142     {
00143         parent::deletePost($this->Forum->getUrl(".view?id=$this->forum_id"));
00144     }
00145 
00149     public function getRssItem()
00150     {
00151         $item = parent::getRssItem();
00152 
00153         $item->title = $this->subject;
00154         $item->description = "$this->comment_count posts";
00155 
00156         return $item;
00157     }
00158 
00162     public function getPublicData()
00163     {
00164         $item = parent::getPublicData();
00165 
00166         $item['name'] = $this->subject;
00167         $item['forum_id'] = $this->forum_id;
00168         $item['last_post_id'] = $this->last_post_id;
00169 
00170         return $item;
00171     }
00172 
00176     public function initViewPage()
00177     {
00178         parent::initViewPage();
00179         
00180         $this->addFeed($this->comments->getUrl(".search?output=rss&content_id=$this->id"), $this->getName() . " Thread RSS Feed");
00181     }
00182 
00186     public function drawViewPage()
00187     {
00188         //our linkatude
00189         $links[] = $this->Forum->getLink(".view?id={$this->Forum->id}", "Back to " . $this->Forum->getName());
00190         $links[] = $this->comments->getLink(".search?output=rss&content_id=$this->id", "Thread RSS Feed");
00191         
00192         echo "<p>";
00193         echo implode(" | ", $links);
00194         echo "</p>";
00195         //draw our thread
00196         $this->comments->drawComments();
00197         
00198         //do we want rss?
00199         if ($this->useRss)
00200             echo $this->getRssLink(".search?output=rss&content_id=$this->contentId", "Subscribe to thread RSS feed.");
00201         
00202     }
00203 
00207     public function save()
00208     {
00209         //our counts and stuff..
00210         if ($this->id)
00211         {
00212             //update our last post..
00213             $ar = dbFetchAssoc(dbQuery("
00214                 SELECT id
00215                 FROM comments_thread
00216                 WHERE content_id = $this->id
00217                 ORDER BY add_date DESC
00218                 LIMIT 1
00219             "));
00220             $this->last_post_id = $ar['id'];
00221         }
00222 
00223         //save our parent forum.
00224         $this->LastPost = new $this->ThreadCommentClass($this->last_post_id);
00225         $this->Forum = new $this->ForumClass($this->forum_id);
00226 
00227         //save ourself.
00228         parent::save();
00229         
00230         //save our forum
00231         $this->Forum->save();
00232     }
00233 
00237     protected function lookupData($deep = true)
00238     {
00239         parent::lookupData($deep);
00240 
00241         $this->LastPost = new $this->ThreadCommentClass();
00242         $this->LastPost->load($this->last_post_id);
00243         
00244         $this->Forum = new $this->ForumClass();
00245         $this->Forum->load($this->forum_id, false);
00246     } 
00247     
00248     protected function getDataToCache($deep = true)
00249     {
00250         $data = parent::getDataToCache($deep);
00251 
00252         $data['lastpost'] = $this->LastPost->getDataToCache();
00253         $data['forum'] = $this->Forum->getDataToCache(false);
00254 
00255         return $data;
00256     }
00257 
00258     protected function setDataFromCache($data, $deep = true)
00259     {
00260         parent::setDataFromCache($data);
00261 
00262         //load our image back in.
00263         $this->LastPost = new $this->ThreadCommentClass();
00264         $this->LastPost->load($data['lastpost']);
00265         
00266         $this->Forum = new $this->ForumClass();
00267         $this->Forum->load($data['forum'], false);
00268     }
00269 
00273     public function getCreateFieldsArray()
00274     {
00275         $arr = parent::getCreateFieldsArray();
00276 
00277         $arr['subject'] = "subject varchar(255) default '' not null";
00278         $arr['forum_id'] = "forum_id int(11) default 0 not null";
00279         $arr['last_post_id'] = "last_post_id int(11) default 0 not null";
00280 
00281         return $arr;
00282     }
00283 
00287     public function getCreateIndexesArray()
00288     {
00289         $arr = parent::getCreateIndexesArray();
00290 
00291         $arr['forum_id'] = "key(forum_id)";
00292         $arr['last_post_id'] = "key(last_post_id)";
00293 
00294         return $arr;
00295     }
00296 }
00297 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1