Search:

CWIS Developers Documentation

  • Main Page
  • Classes
  • Files
  • File List
  • File Members

Forum.php

Go to the documentation of this file.
00001 <?PHP
00002 #
00003 #   FILE:  SPT--Forum.php
00004 #
00005 #   FUNCTIONS PROVIDED:
00006 #       Forum->Forum($ForumId)
00007 #           - constructor
00008 #       Forum->ForumId()
00009 #       Forum->ForumName()
00010 #       Forum->ForumDescription()
00011 #       Forum->TopicCount()
00012 #       Forum->MessageCount()
00013 #       Forum->ModeratorId()
00014 #           - methods to retrieve resource attributes
00015 #
00016 #   Part of the Scout Portal Toolkit
00017 #   Copyright 2002 Internet Scout Project
00018 #   http://scout.cs.wisc.edu
00019 #
00020 
00026 class Forum {
00027 
00028     # ---- PUBLIC INTERFACE --------------------------------------------------
00029 
00030     # Error codes for the forum object
00031     const OK = 0;
00032     const NONEXISTENT = 1;
00033 
00036 
00043     function Forum($ForumId = NULL)
00044     {
00045         $this->ErrorStatus = Forum::OK;
00046         # locate class in database
00047         $this->DB = new SPTDatabase();
00048         $DB =& $this->DB;
00049         # if ID supplied
00050         if ($ForumId !== NULL)
00051         {
00052             $this->ForumId = intval($ForumId);
00053             $DB->Query("SELECT * FROM Forums WHERE ForumId = "
00054                     .$this->ForumId);
00055 
00056             # if row was loaded
00057             if ($DB->NumRowsSelected() > 0)
00058             {
00059                 # set attributes to values returned by database
00060                 $this->DBFields = $DB->FetchRow();
00061             }
00062             else
00063             {
00064                 $this->ErrorStatus = Forum::NONEXISTENT;
00065             }
00066         }
00067         else
00068         {
00069             # add record to database with that ID
00070             $DB->Query("INSERT INTO Forums (ForumId) VALUES (NULL)");
00071             $this->ForumId = $DB->Query("SELECT LAST_INSERT_ID() AS ForumId"
00072                     ." FROM Forums", "ForumId");
00073         }
00074 
00075     }
00076 
00080     function Delete()
00081     {
00082         if ($this->ErrorStatus == Forum::OK)
00083         {
00084             $this->DB->Query("Select * from Topics where ForumId = ".
00085                              $this->ForumId." ORDER BY DateCreated Desc");
00086 
00087             # get list of topics for this forum
00088             while ($Entry = $this->DB->FetchRow())
00089             {
00090                 $Topic = new Topic($Entry["TopicId"]);
00091                 $Topic->Delete();
00092             }
00093             # delete record from database
00094             $this->DB->Query("DELETE FROM Forums WHERE ForumId = ".$this->ForumId);
00095         }
00096     }
00101 
00106     function ForumId()          {  return $this->ForumId;  }
00107 
00112     function LastMessageDate()
00113     {
00114         $Message = GetLastMessage($this->ForumId());
00115         if (isset($Message))
00116             return $Message->DatePosted()." by ";
00117         else
00118             return "None";
00119     }
00120 
00125     function LastMessagePoster()
00126     {
00127         $Message = GetLastMessage($this->ForumId());
00128         if (isset($Message))
00129             return $Message->PosterName();
00130     }
00131 
00136     function LastMessagePosterEmail()
00137     {
00138         $Message = GetLastMessage($this->ForumId());
00139         if (isset($Message))
00140             return $Message->PosterEmail();
00141     }
00142 
00147     function ModeratorName()
00148     {
00149         $ModeratorName = new User($this->DB, (int)$this->ModeratorId());
00150         return $ModeratorName->Get("UserName");
00151     }
00152 
00157     function ModeratorEmail()
00158     {
00159         $ModeratorName = new User($this->DB, (int)$this->ModeratorId());
00160         return $ModeratorName->Get("EMail");
00161     }
00162 
00167     function GetTopicList()
00168     {
00169         $Topics = array();
00170 
00171         $this->DB->Query("Select * from Topics where ForumId = ".
00172                     $this->ForumId." ORDER BY DateCreated Desc");
00173 
00174         # get list of topics for this forum
00175         while ($Entry = $this->DB->FetchRow())
00176         {
00177             $Topics[$Entry["TopicId"]] = new Topic($Entry["TopicId"]);
00178         }
00179         return $Topics;
00180     }
00181 
00187    function ForumName($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ForumName", $NewValue);  }
00188 
00194    function ForumDescription($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ForumDescription", $NewValue);  }
00195 
00201    function TopicCount($NewValue = DB_NOVALUE) {  return $this->UpdateValue("TopicCount", $NewValue);  }
00202 
00208    function MessageCount($NewValue = DB_NOVALUE) {  return $this->UpdateValue("MessageCount", $NewValue);  }
00209 
00215    function ModeratorId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ModeratorId", $NewValue);  }
00216 
00221    function GetErrorStatus() { return $this->ErrorStatus; }
00222 
00225     # ---- PRIVATE INTERFACE -------------------------------------------------
00226 
00227    private $ForumId;
00228    private $DB;
00229    private $DBFields;
00230    private $ErrorStatus;
00231 
00232    # convenience function to supply parameters to Database->UpdateValue()
00233    private function UpdateValue($FieldName, $NewValue)
00234    {
00235        if ($this->ErrorStatus==Forum::OK)
00236        {
00237            return $this->DB->UpdateValue("Forums", $FieldName, $NewValue,
00238                                          "ForumId = '".$this->ForumId."'", $this->DBFields, TRUE);
00239        }
00240        else
00241        {
00242            return NULL;
00243        }
00244    }
00245 }
00246 
00247 function GetLastMessage($ForumId)
00248 {
00249     $DB = new SPTDatabase();
00250     $Query = "SELECT * FROM Topics WHERE ForumId = ".intval($ForumId);
00251     $DB->Query($Query);
00252     $LastMessage = NULL;
00253 
00254     $MostRecent = "0001/01/01 00:00:00";
00255     while ($Entry = $DB->FetchRow())
00256     {
00257         $DB1 = new SPTDatabase();
00258         $Query = "SELECT * from Messages where ParentId = ".
00259             intval($Entry["TopicId"]).
00260             " AND ParentType = 1 ORDER BY DatePosted DESC Limit 1";
00261         $DB1->Query($Query);
00262         if ($DB1->NumRowsSelected() > 0)
00263         {
00264             $Record = $DB1->FetchRow();
00265             $Message = new Message($Record["MessageId"]);
00266             if ($Message->DatePosted() > $MostRecent)
00267             {
00268                 $LastMessage = $Message;
00269                 $MostRecent = $Message->DatePosted();
00270             }
00271         }
00272     }
00273     return $LastMessage;
00274 }
00275 
00276 ?>
CWIS logo doxygen
Copyright 2009 Internet Scout