CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

Message.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: Message.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2012-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis
8 #
9
15 class Message {
16
17 # ---- PUBLIC INTERFACE --------------------------------------------------
18
19 const OK = 0;
20 const NONEXISTENT = 1;
21
22 const PARENTTYPE_TOPIC = 1;
23 const PARENTTYPE_RESOURCE = 2;
24
27
35 function Message($MessageId = NULL)
36 {
37 $this->ErrorStatus = self::NONEXISTENT;
38 $this->DB = new Database();
39
40 # no ID supplied
41 if (is_null($MessageId))
42 {
43 # add record to database with that ID
44 $this->DB->Query("INSERT INTO Messages (MessageId) VALUES (NULL)");
45 $this->DB->Query("SELECT LAST_INSERT_ID() AS Id FROM Messages");
46
47 if ($this->DB->NumRowsSelected())
48 {
49 $this->MessageId = intval($this->DB->FetchField("Id"));
50 $this->ErrorStatus = self::OK;
51 }
52 }
53
54 # ID supplied
55 else
56 {
57 $this->DB->Query("
58 SELECT * FROM Messages
59 WHERE MessageId = '".intval($MessageId)."'");
60
61 if ($this->DB->NumRowsSelected())
62 {
63 # set attributes to values returned by database
64 $this->DBFields = $this->DB->FetchRow();
65 $this->MessageId = intval($this->DBFields["MessageId"]);
66 $this->ErrorStatus = Message::OK;
67 }
68 }
69 }
70
74 function Delete()
75 {
76 if ($this->ErrorStatus == Message::OK)
77 {
78 $this->DB->Query("DELETE FROM Messages WHERE MessageId = ".$this->MessageId);
79 }
80 }
81
86
91 function MessageId() { return $this->MessageId; }
92
97 function PosterName()
98 {
99 $PosterName = new CWUser((int)$this->PosterId());
100 return $PosterName->Get("UserName");
101 }
102
107 function PosterEmail()
108 {
109 $PosterName = new CWUser((int)$this->PosterId());
110 return $PosterName->Get("EMail");
111 }
112
117 function EditorId($NewValue = DB_NOVALUE) { return $this->UpdateValue("EditorId", $NewValue); }
118
126 function ParentId($NewValue = DB_NOVALUE) { return $this->UpdateValue("ParentId", $NewValue); }
127
135 function ParentType($NewValue = DB_NOVALUE) { return $this->UpdateValue("ParentType", $NewValue); }
136
142 function DatePosted($NewValue = DB_NOVALUE) { return $this->UpdateValue("DatePosted", $NewValue); }
143
149 function DateEdited($NewValue = DB_NOVALUE) { return $this->UpdateValue("DateEdited", $NewValue); }
150
156 function PosterId($NewValue = DB_NOVALUE) { return $this->UpdateValue("PosterId", $NewValue); }
157
163 function Subject($NewValue = DB_NOVALUE) { return $this->UpdateValue("Subject", $NewValue); }
164
170 function Body($NewValue = DB_NOVALUE) { return $this->UpdateValue("Body", $NewValue); }
171
176 function GetErrorStatus() { return $this->ErrorStatus; }
177
180 # ---- PRIVATE INTERFACE -------------------------------------------------
181
182 private $MessageId;
183 private $DB;
184 private $DBFields;
185 private $ErrorStatus;
186
194 private function UpdateValue($FieldName, $NewValue)
195 {
196 if ($this->ErrorStatus == Message::OK)
197 {
198 return $this->DB->UpdateValue("Messages", $FieldName, $NewValue,
199 "MessageId = '".$this->MessageId."'", $this->DBFields, TRUE);
200 }
201 else
202 {
203 return NULL;
204 }
205 }
206 }
Message\Message
Message($MessageId=NULL)
Object constructor.
Definition: Message.php:35
Message\DateEdited
DateEdited($NewValue=DB_NOVALUE)
Get or set the date the message was last edited.
Definition: Message.php:149
Message\MessageId
MessageId()
Get this message&#39;s messageId.
Definition: Message.php:91
Message
Abstraction for forum messages and resource comments.
Definition: Message.php:15
Message\GetErrorStatus
GetErrorStatus()
Retrieve the error status.
Definition: Message.php:176
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
Message\PARENTTYPE_TOPIC
const PARENTTYPE_TOPIC
Definition: Message.php:22
DB_NOVALUE
const DB_NOVALUE
Definition: Axis--Database.php:1180
Message\PARENTTYPE_RESOURCE
const PARENTTYPE_RESOURCE
Definition: Message.php:23
Message\Subject
Subject($NewValue=DB_NOVALUE)
Get or set the message subject.
Definition: Message.php:163
Message\PosterEmail
PosterEmail()
Get the email address of the most recent poster.
Definition: Message.php:107
Message\NONEXISTENT
const NONEXISTENT
Definition: Message.php:20
Message\OK
const OK
Definition: Message.php:19
PHP
PHP
Definition: OAIClient.php:39
Message\Body
Body($NewValue=DB_NOVALUE)
Get or set the message body.
Definition: Message.php:170
Message\PosterName
PosterName()
Get the CWIS username of the most recent poster.
Definition: Message.php:97
Message\EditorId
EditorId($NewValue=DB_NOVALUE)
Get the CWIS user ID of the most recent editor.
Definition: Message.php:117
Message\DatePosted
DatePosted($NewValue=DB_NOVALUE)
Get or set the date posted.
Definition: Message.php:142
Message\Delete
Delete()
Delete this message from the underlying database.
Definition: Message.php:74
Message\ParentId
ParentId($NewValue=DB_NOVALUE)
Get or set the ParentId.
Definition: Message.php:126
CWUser
CWIS-specific user class.
Definition: CWUser.php:13
Message\PosterId
PosterId($NewValue=DB_NOVALUE)
Get or set the poster id (e.g., the author) for this message.
Definition: Message.php:156
Message\ParentType
ParentType($NewValue=DB_NOVALUE)
Get or set the ParentType.
Definition: Message.php:135