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
    00036
    00044     function Message($MessageId = NULL)
    00045     {
    00046         $this->ErrorStatus = self::NONEXISTENT;
    00047         $this->DB = new Database();
    00048
    00049         # no ID supplied
    00050         if (is_null($MessageId))
    00051         {
    00052             # add record to database with that ID
    00053             $this->DB->Query("INSERT INTO Messages (MessageId) VALUES (NULL)");
    00054             $this->DB->Query("SELECT LAST_INSERT_ID() AS Id FROM Messages");
    00055
    00056             if ($this->DB->NumRowsSelected())
    00057             {
    00058                 $this->MessageId = intval($this->DB->FetchField("Id"));
    00059                 $this->ErrorStatus = self::OK;
    00060             }
    00061         }
    00062
    00063         # ID supplied
    00064         else
    00065         {
    00066             $this->DB->Query("
    00067                 SELECT * FROM Messages
    00068                 WHERE MessageId = '".intval($MessageId)."'");
    00069
    00070             if ($this->DB->NumRowsSelected())
    00071             {
    00072                 # set attributes to values returned by database
    00073                 $this->DBFields = $this->DB->FetchRow();
    00074                 $this->MessageId = intval($this->DBFields["MessageId"]);
    00075                 $this->ErrorStatus = Message::OK;
    00076             }
    00077         }
    00078     }
    00079
    00083     function Delete()
    00084     {
    00085         if ($this->ErrorStatus == Message::OK)
    00086         {
    00087             $this->DB->Query("DELETE FROM Messages WHERE MessageId = ".$this->MessageId);
    00088         }
    00089     }
    00090
    00095
    00100     function MessageId()    {  return $this->MessageId;  }
    00101
    00106     function PosterName()
    00107     {
    00108         $PosterName = new User($this->DB, (int)$this->PosterId());
    00109         return $PosterName->Get("UserName");
    00110     }
    00111
    00116     function PosterEmail()
    00117     {
    00118         $PosterName = new User($this->DB, (int)$this->PosterId());
    00119         return $PosterName->Get("EMail");
    00120     }
    00121
    00129     function ParentId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ParentId", $NewValue);  }
    00130
    00138     function ParentType($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ParentType", $NewValue);  }
    00139
    00145     function DatePosted($NewValue = DB_NOVALUE) {  return $this->UpdateValue("DatePosted", $NewValue);  }
    00146
    00152     function PosterId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("PosterId", $NewValue);  }
    00153
    00159     function Subject($NewValue = DB_NOVALUE) {  return $this->UpdateValue("Subject", $NewValue);  }
    00160
    00166     function Body($NewValue = DB_NOVALUE) {  return $this->UpdateValue("Body", $NewValue);  }
    00167
    00172     function GetErrorStatus() { return $this->ErrorStatus; }
    00173
    00176     # ---- PRIVATE INTERFACE -------------------------------------------------
    00177
    00178     private $MessageId;
    00179     private $DB;
    00180     private $DBFields;
    00181     private $ErrorStatus;
    00182
    00183     # convenience function to supply parameters to Database->UpdateValue()
    00184     private function UpdateValue($FieldName, $NewValue)
    00185     {
    00186         if ($this->ErrorStatus == Message::OK)
    00187         {
    00188             return $this->DB->UpdateValue("Messages", $FieldName, $NewValue,
    00189                                           "MessageId = '".$this->MessageId."'", $this->DBFields, TRUE);
    00190         }
    00191         else
    00192         {
    00193             return NULL;
    00194         }
    00195     }
    00196 }
    00197
    00198 ?>