5 * Copyright 2004, GForge, LLC
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/Error.class.php';
26 class ArtifactMessage extends Error {
29 * The artifact object.
31 * @var object $Artifact.
33 var $Artifact; //object
36 * Array of artifact data.
38 * @var array $data_array.
43 * __construct - ArtifactMessage constructor.
45 * @param object $Artifact Artifact object.
46 * @param array|bool $data (all fields from artifact_history_user_vw) OR id from database.
48 function __construct(&$Artifact, $data=false) {
52 if (!$Artifact || !is_object($Artifact)) {
53 $this->setError('ArtifactMessage: No Valid Artifact');
56 //did Artifact have an error?
57 if ($Artifact->isError()) {
58 $this->setError('ArtifactMessage: '.$Artifact->getErrorMessage());
61 $this->Artifact =& $Artifact;
64 if (is_array($data)) {
65 $this->data_array =& $data;
67 $this->fetchData($data);
73 * create - create a new item in the database.
75 * @param string $body Body.
76 * @param string|bool $by Email of submitter (obsolete?).
77 * @return int|bool id on success / false on failure.
79 function create($body,$by=false) {
81 $this->setMissingParamsError();
85 if (session_loggedin()) {
86 $user_id=user_getid();
87 $user =& user_get_object($user_id);
88 if (!$user || !is_object($user)) {
89 $this->setError('ERROR - Logged In User Bug Could Not Get User Object');
92 $body=_('Logged In: YES')." \nuser_id=$user_id\n\n".$body;
94 // we'll store this email even though it will likely never be used -
95 // since we have their correct user_id, we can join the USERS table to get email
96 $by=$user->getEmail();
98 $body=_('Logged In: NO')." \n\n".$body;
100 if (!$by || !validate_email($by)) {
101 $this->setMissingParamsError();
106 $res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body)
107 VALUES ($1,$2,$3,$4,$5)',
108 array ($this->Artifact->getID(),
112 htmlspecialchars($body))) ;
114 $this->setError(db_error());
117 $id=db_insertid($res,'artifact_message','id');
121 // Now set up our internal data structures
123 if (!$this->fetchData($id)) {
130 * fetchData - re-fetch the data for this ArtifactMessage from the database.
132 * @param int $id ID of the category.
133 * @return boolean success.
135 function fetchData($id) {
136 $res = db_query_params ('SELECT * FROM artifact_message_user_vw WHERE id=$1',
138 if (!$res || db_numrows($res) < 1) {
139 $this->setError('ArtifactMessage: Invalid ArtifactMessage ID');
142 $this->data_array = db_fetch_array($res);
143 db_free_result($res);
148 * getArtifact - get the Artifact Object this ArtifactMessage is associated with.
150 * @return object Artifact.
152 function &getArtifact() {
153 return $this->Artifact;
157 * getID - get this ArtifactMessage's ID.
159 * @return int The id #.
162 return $this->data_array['id'];
166 * getBody - get the message body.
168 * @return string The message body.
171 return $this->data_array['body'];
175 * getAddDate - get the date this message was added.
177 * @return int adddate.
179 function getAddDate() {
180 return $this->data_array['addate'];
184 * getUserID - get the ID of the person who posted this.
186 * @return int user_id.
188 function getUserID() {
189 return $this->data_array['user_id'];
196 // c-file-style: "bsd"