Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- Search for |

- File List
- File Members

# Message.php

Go to the documentation of this file.

    00001 <?PHP
    00002
    00003 #
    00004 #   FILE:  SPT--Message.php
    00005 #
    00006 #   FUNCTIONS PROVIDED:
    00007 #       Message->Message($MessageId)
    00008 #           - constructor
    00009 #       Message->MessageId()
    00010 #       Message->ParentId()
    00011 #       Message->ParentyType()
    00012 #       Message->DatePosted()
    00013 #       Message->PosterId()
    00014 #       Message->Subject()
    00015 #       Message->Body()
    00016 #           - methods to retrieve resource attributes
    00017 #
    00018 #   Part of the Scout Portal Toolkit
    00019 #   Copyright 2002 Internet Scout Project
    00020 #   http://scout.cs.wisc.edu
    00021 #
    00022
    00028 class Message {
    00029
    00030     # ---- PUBLIC INTERFACE --------------------------------------------------
    00031
    00032     const OK = 0;
    00033     const NONEXISTENT = 1;
    00034
    00037
    00045     function Message($MessageId = NULL)
    00046     {
    00047         $this->ErrorStatus = Message::OK;
    00048         # locate class in database
    00049         $this->DB = new SPTDatabase();
    00050         $DB =& $this->DB;
    00051         # if ID supplied
    00052         if ($MessageId !== NULL)
    00053         {
    00054             $this->MessageId = intval($MessageId);
    00055             $DB->Query("SELECT * FROM Messages WHERE MessageId = ".$this->MessageId);
    00056
    00057             # if row was loaded
    00058             if ($DB->NumRowsSelected() > 0)
    00059             {
    00060                 # set attributes to values returned by database
    00061                 $this->DBFields = $DB->FetchRow();
    00062             }
    00063             else
    00064             {
    00065                 $this->ErrorStatus = Message::NONEXISTENT;
    00066             }
    00067         }
    00068         else
    00069         {
    00070             # add record to database with that ID
    00071             $DB->Query("INSERT INTO Messages (MessageId) VALUES (NULL)");
    00072             $this->MessageId = $DB->Query("SELECT LAST_INSERT_ID()"
    00073                     ." AS MessageId FROM Messages", "MessageId");
    00074         }
    00075     }
    00076
    00080     function Delete()
    00081     {
    00082         if ($this->ErrorStatus == Message::OK)
    00083         {
    00084             $this->DB->Query("DELETE FROM Messages WHERE MessageId = ".$this->MessageId);
    00085         }
    00086     }
    00087
    00092
    00097     function MessageId()    {  return $this->MessageId;  }
    00098
    00103     function PosterName()
    00104     {
    00105         $PosterName = new User($this->DB, (int)$this->PosterId());
    00106         return $PosterName->Get("UserName");
    00107     }
    00108
    00113     function PosterEmail()
    00114     {
    00115         $PosterName = new User($this->DB, (int)$this->PosterId());
    00116         return $PosterName->Get("EMail");
    00117     }
    00118
    00126     function ParentId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ParentId", $NewValue);  }
    00127
    00135     function ParentType($NewValue = DB_NOVALUE) {  return $this->UpdateValue("ParentType", $NewValue);  }
    00136
    00142     function DatePosted($NewValue = DB_NOVALUE) {  return $this->UpdateValue("DatePosted", $NewValue);  }
    00143
    00149     function PosterId($NewValue = DB_NOVALUE) {  return $this->UpdateValue("PosterId", $NewValue);  }
    00150
    00156     function Subject($NewValue = DB_NOVALUE) {  return $this->UpdateValue("Subject", $NewValue);  }
    00157
    00163     function Body($NewValue = DB_NOVALUE) {  return $this->UpdateValue("Body", $NewValue);  }
    00164
    00169     function GetErrorStatus() { return $this->ErrorStatus; }
    00170
    00173     # ---- PRIVATE INTERFACE -------------------------------------------------
    00174
    00175     private $MessageId;
    00176     private $DB;
    00177     private $DBFields;
    00178     private $ErrorStatus;
    00179
    00180     # convenience function to supply parameters to Database->UpdateValue()
    00181     private function UpdateValue($FieldName, $NewValue)
    00182     {
    00183         if ($this->ErrorStatus == Message::OK)
    00184         {
    00185             return $this->DB->UpdateValue("Messages", $FieldName, $NewValue,
    00186                                           "MessageId = '".$this->MessageId."'", $this->DBFields, TRUE);
    00187         }
    00188         else
    00189         {
    00190             return NULL;
    00191         }
    00192     }
    00193 }
    00194
    00195 ?>