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         elseif (func_num_args()==0)
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         else
00075         {
00076             $this->ErrorStatus = Forum::NONEXISTENT;
00077         }
00078 
00079     }
00080 
00084     function Delete()
00085     {
00086         if ($this->ErrorStatus == Forum::OK)
00087         {
00088             $this->DB->Query("Select * from Topics where ForumId = ".
00089                              $this->ForumId." ORDER BY DateCreated Desc");
00090 
00091             # get list of topics for this forum
00092             while ($Entry = $this->DB->FetchRow())
00093             {
00094                 $Topic = new Topic($Entry["TopicId"]);
00095                 $Topic->Delete();
00096             }
00097             # delete record from database
00098             $this->DB->Query("DELETE FROM Forums WHERE ForumId = ".$this->ForumId);
00099         }
00100     }
00105 
00110     function ForumId()          {  return $this->ForumId;  }
00111 
00116     function LastMessageDate()
00117     {
00118         $Message = GetLastMessage($this->ForumId());
00119         if (isset($Message))
00120             return $Message->DatePosted()." by ";
00121         else
00122             return "None";
00123     }
00124 
00129     function LastMessagePoster()
00130     {
00131         $Message = GetLastMessage($this->ForumId());
00132         if (isset($Message))
00133             return $Message->PosterName();
00134     }
00135 
00140     function LastMessagePosterEmail()
00141     {
00142         $Message = GetLastMessage($this->ForumId());
00143         if (isset($Message))
00144             return $Message->PosterEmail();
00145     }
00146 
00151     function ModeratorName()
00152     {
00153         $ModeratorName = new User($this->DB, (int)$this->ModeratorId());
00154         return $ModeratorName->Get("UserName");
00155     }
00156 
00161     function ModeratorEmail()
00162     {
00163         $ModeratorName = new User($this->DB, (int)$this->ModeratorId());
00164         return $ModeratorName->Get("EMail");
00165     }
00166 
00171     function GetTopicList()
00172     {
00173         $Topics = array();
00174 
00175         $this->DB->Query("Select * from Topics where ForumId = ".
00176                     $this->ForumId." ORDER BY DateCreated Desc");
00177 
00178         # get list of topics for this forum
00179         while ($Entry = $this->DB->FetchRow())
00180         {
00181             $Topics[$Entry["TopicId"]] = new Topic($Entry["TopicId"]);
00182         }
00183         return $Topics;
00184     }
00185 
00191    function ForumName($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ForumName", $NewValue);  }
00192 
00198    function ForumDescription($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ForumDescription", $NewValue);  }
00199 
00205    function TopicCount($NewValue = DB_NOVALUE) {  return $this->UpdateValue("TopicCount", $NewValue);  }
00206 
00212    function MessageCount($NewValue = DB_NOVALUE) {  return $this->UpdateValue("MessageCount", $NewValue);  }
00213 
00219    function ModeratorId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ModeratorId", $NewValue);  }
00220 
00225    function GetErrorStatus() { return $this->ErrorStatus; }
00226 
00229     # ---- PRIVATE INTERFACE -------------------------------------------------
00230 
00231    private $ForumId;
00232    private $DB;
00233    private $DBFields;
00234    private $ErrorStatus;
00235 
00236    # convenience function to supply parameters to Database->UpdateValue()
00237    private function UpdateValue($FieldName, $NewValue)
00238    {
00239        if ($this->ErrorStatus==Forum::OK)
00240        {
00241            return $this->DB->UpdateValue("Forums", $FieldName, $NewValue,
00242                                          "ForumId = '".$this->ForumId."'", $this->DBFields, TRUE);
00243        }
00244        else
00245        {
00246            return NULL;
00247        }
00248    }
00249 }
00250 
00251 function GetLastMessage($ForumId)
00252 {
00253     $DB = new SPTDatabase();
00254     $Query = "SELECT * FROM Topics WHERE ForumId = ".intval($ForumId);
00255     $DB->Query($Query);
00256     $LastMessage = NULL;
00257 
00258     $MostRecent = "0001/01/01 00:00:00";
00259     while ($Entry = $DB->FetchRow())
00260     {
00261         $DB1 = new SPTDatabase();
00262         $Query = "SELECT * from Messages where ParentId = ".
00263             intval($Entry["TopicId"]).
00264             " AND ParentType = 1 ORDER BY DatePosted DESC Limit 1";
00265         $DB1->Query($Query);
00266         if ($DB1->NumRowsSelected() > 0)
00267         {
00268             $Record = $DB1->FetchRow();
00269             $Message = new Message($Record["MessageId"]);
00270             if ($Message->DatePosted() > $MostRecent)
00271             {
00272                 $LastMessage = $Message;
00273                 $MostRecent = $Message->DatePosted();
00274             }
00275         }
00276     }
00277     return $LastMessage;
00278 }
00279 
00280 ?>

CWIS logo doxygen
Copyright 2010 Internet Scout