CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- 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
14 class Message
15 {
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 public function __construct($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 = self::OK;
67 }
68 }
69 }
70
74 public function Delete()
75 {
76 if ($this->ErrorStatus == self::OK)
77 {
78 $this->DB->Query("DELETE FROM Messages WHERE MessageId = ".$this->MessageId);
79 }
80 }
81
86
91 public function MessageId()
92 {
93 return $this->MessageId;
94 }
95
100 public function PosterName()
101 {
102 $PosterName = new CWUser((int)$this->PosterId());
103 return $PosterName->Get("UserName");
104 }
105
110 public function PosterEmail()
111 {
112 $PosterName = new CWUser((int)$this->PosterId());
113 return $PosterName->Get("EMail");
114 }
115
121 public function EditorId($NewValue = DB_NOVALUE)
122 {
123 return $this->UpdateValue("EditorId", $NewValue);
124 }
125
133 public function ParentId($NewValue = DB_NOVALUE)
134 {
135 return $this->UpdateValue("ParentId", $NewValue);
136 }
137
145 public function ParentType($NewValue = DB_NOVALUE)
146 {
147 return $this->UpdateValue("ParentType", $NewValue);
148 }
149
155 public function DatePosted($NewValue = DB_NOVALUE)
156 {
157 return $this->UpdateValue("DatePosted", $NewValue);
158 }
159
165 public function DateEdited($NewValue = DB_NOVALUE)
166 {
167 return $this->UpdateValue("DateEdited", $NewValue);
168 }
169
175 public function PosterId($NewValue = DB_NOVALUE)
176 {
177 return $this->UpdateValue("PosterId", $NewValue);
178 }
179
185 public function Subject($NewValue = DB_NOVALUE)
186 {
187 return $this->UpdateValue("Subject", $NewValue);
188 }
189
195 public function Body($NewValue = DB_NOVALUE)
196 {
197 return $this->UpdateValue("Body", $NewValue);
198 }
199
204 public function GetErrorStatus()
205 {
206 return $this->ErrorStatus;
207 }
208
211 # ---- PRIVATE INTERFACE -------------------------------------------------
212
213 private $MessageId;
214 private $DB;
215 private $DBFields;
216 private $ErrorStatus;
217
225 private function UpdateValue($FieldName, $NewValue)
226 {
227 if ($this->ErrorStatus == self::OK)
228 {
229 return $this->DB->UpdateValue(
230 "Messages", $FieldName, $NewValue,
231 "MessageId = '".$this->MessageId."'", $this->DBFields, TRUE);
232 }
233 else
234 {
235 return NULL;
236 }
237 }
238 }
Message\DateEdited
DateEdited($NewValue=DB_NOVALUE)
Get or set the date the message was last edited.
Definition: Message.php:165
Message\MessageId
MessageId()
Get this message&#39;s messageId.
Definition: Message.php:91
Message
Abstraction for forum messages and resource comments.
Definition: Message.php:14
Message\GetErrorStatus
GetErrorStatus()
Retrieve the error status.
Definition: Message.php:204
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
Message\PARENTTYPE_TOPIC
const PARENTTYPE_TOPIC
Definition: Message.php:22
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:185
Message\PosterEmail
PosterEmail()
Get the email address of the most recent poster.
Definition: Message.php:110
Message\NONEXISTENT
const NONEXISTENT
Definition: Message.php:20
Message\OK
const OK
Definition: Message.php:19
Message\__construct
__construct($MessageId=NULL)
Object constructor.
Definition: Message.php:35
Message\Body
Body($NewValue=DB_NOVALUE)
Get or set the message body.
Definition: Message.php:195
PHP
PHP
Definition: RSSClient--Test.php:12
Message\PosterName
PosterName()
Get the CWIS username of the most recent poster.
Definition: Message.php:100
DB_NOVALUE
const DB_NOVALUE
Definition: Database.php:1541
Message\EditorId
EditorId($NewValue=DB_NOVALUE)
Get the CWIS user ID of the most recent editor.
Definition: Message.php:121
Message\DatePosted
DatePosted($NewValue=DB_NOVALUE)
Get or set the date posted.
Definition: Message.php:155
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:133
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:175
Message\ParentType
ParentType($NewValue=DB_NOVALUE)
Get or set the ParentType.
Definition: Message.php:145