Search:

CWIS Developers Documentation

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

Message.php

Go to the documentation of this file.
00001 <?PHP
00002 #
00003 #   FILE:  Message.php
00004 #
00005 #   FUNCTIONS PROVIDED:
00006 #       Message->Message($MessageId)
00007 #           - constructor
00008 #       Message->MessageId()
00009 #       Message->ParentId()
00010 #       Message->ParentyType()
00011 #       Message->DatePosted()
00012 #       Message->PosterId()
00013 #       Message->Subject()
00014 #       Message->Body()
00015 #           - methods to retrieve resource attributes
00016 #
00017 #   Part of the Scout Portal Toolkit
00018 #   Copyright 2002 Internet Scout Project
00019 #   http://scout.cs.wisc.edu
00020 #
00021 
00027 class Message {
00028 
00029     # ---- PUBLIC INTERFACE --------------------------------------------------
00030 
00031     const OK = 0;
00032     const NONEXISTENT = 1;
00033 
00034     const PARENTTYPE_TOPIC = 1;
00035     const PARENTTYPE_RESOURCE = 2;
00036 
00039 
00047     function Message($MessageId = NULL)
00048     {
00049         $this->ErrorStatus = self::NONEXISTENT;
00050         $this->DB = new Database();
00051 
00052         # no ID supplied
00053         if (is_null($MessageId))
00054         {
00055             # add record to database with that ID
00056             $this->DB->Query("INSERT INTO Messages (MessageId) VALUES (NULL)");
00057             $this->DB->Query("SELECT LAST_INSERT_ID() AS Id FROM Messages");
00058 
00059             if ($this->DB->NumRowsSelected())
00060             {
00061                 $this->MessageId = intval($this->DB->FetchField("Id"));
00062                 $this->ErrorStatus = self::OK;
00063             }
00064         }
00065 
00066         # ID supplied
00067         else
00068         {
00069             $this->DB->Query("
00070                 SELECT * FROM Messages
00071                 WHERE MessageId = '".intval($MessageId)."'");
00072 
00073             if ($this->DB->NumRowsSelected())
00074             {
00075                 # set attributes to values returned by database
00076                 $this->DBFields = $this->DB->FetchRow();
00077                 $this->MessageId = intval($this->DBFields["MessageId"]);
00078                 $this->ErrorStatus = Message::OK;
00079             }
00080         }
00081     }
00082 
00086     function Delete()
00087     {
00088         if ($this->ErrorStatus == Message::OK)
00089         {
00090             $this->DB->Query("DELETE FROM Messages WHERE MessageId = ".$this->MessageId);
00091         }
00092     }
00093 
00098 
00103     function MessageId()    {  return $this->MessageId;  }
00104 
00109     function PosterName()
00110     {
00111         $PosterName = new User($this->DB, (int)$this->PosterId());
00112         return $PosterName->Get("UserName");
00113     }
00114 
00119     function PosterEmail()
00120     {
00121         $PosterName = new User($this->DB, (int)$this->PosterId());
00122         return $PosterName->Get("EMail");
00123     }
00124 
00132     function ParentId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ParentId", $NewValue);  }
00133 
00141     function ParentType($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ParentType", $NewValue);  }
00142 
00148     function DatePosted($NewValue = DB_NOVALUE) {  return $this->UpdateValue("DatePosted", $NewValue);  }
00149 
00155     function PosterId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("PosterId", $NewValue);  }
00156 
00162     function Subject($NewValue = DB_NOVALUE) {  return $this->UpdateValue("Subject", $NewValue);  }
00163 
00169     function Body($NewValue = DB_NOVALUE) {  return $this->UpdateValue("Body", $NewValue);  }
00170 
00175     function GetErrorStatus() { return $this->ErrorStatus; }
00176 
00179     # ---- PRIVATE INTERFACE -------------------------------------------------
00180 
00181     private $MessageId;
00182     private $DB;
00183     private $DBFields;
00184     private $ErrorStatus;
00185 
00186     # convenience function to supply parameters to Database->UpdateValue()
00187     private function UpdateValue($FieldName, $NewValue)
00188     {
00189         if ($this->ErrorStatus == Message::OK)
00190         {
00191             return $this->DB->UpdateValue("Messages", $FieldName, $NewValue,
00192                                           "MessageId = '".$this->MessageId."'", $this->DBFields, TRUE);
00193         }
00194         else
00195         {
00196             return NULL;
00197         }
00198     }
00199 }
00200 
00201 ?>

CWIS logo doxygen
Copyright 2010 Internet Scout