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 * ArtifactMessage - constructor.
45 * @param object Artifact object.
46 * @param array (all fields from artifact_history_user_vw) OR id from database.
47 * @return boolean success.
49 function __construct(&$Artifact, $data=false) {
53 if (!$Artifact || !is_object($Artifact)) {
54 $this->setError('ArtifactMessage: No Valid Artifact');
57 //did Artifact have an error?
58 if ($Artifact->isError()) {
59 $this->setError('ArtifactMessage: '.$Artifact->getErrorMessage());
62 $this->Artifact =& $Artifact;
65 if (is_array($data)) {
66 $this->data_array =& $data;
69 if (!$this->fetchData($data)) {
79 * create - create a new item in the database.
82 * @param string email of submitter (obsolete?).
83 * @return id on success / false on failure.
85 function create($body,$by=false) {
87 $this->setMissingParamsError();
91 if (session_loggedin()) {
92 $user_id=user_getid();
93 $user =& user_get_object($user_id);
94 if (!$user || !is_object($user)) {
95 $this->setError('ERROR - Logged In User Bug Could Not Get User Object');
98 $body=_('Logged In: YES')." \nuser_id=$user_id\n\n".$body;
100 // we'll store this email even though it will likely never be used -
101 // since we have their correct user_id, we can join the USERS table to get email
102 $by=$user->getEmail();
104 $body=_('Logged In: NO')." \n\n".$body;
106 if (!$by || !validate_email($by)) {
107 $this->setMissingParamsError();
112 $res = db_query_params ('INSERT INTO artifact_message (artifact_id,submitted_by,from_email,adddate,body)
113 VALUES ($1,$2,$3,$4,$5)',
114 array ($this->Artifact->getID(),
118 htmlspecialchars($body))) ;
120 $this->setError(db_error());
123 $id=db_insertid($res,'artifact_message','id');
127 // Now set up our internal data structures
129 if (!$this->fetchData($id)) {
136 * fetchData - re-fetch the data for this ArtifactMessage from the database.
138 * @param int ID of the category.
139 * @return boolean success.
141 function fetchData($id) {
142 $res = db_query_params ('SELECT * FROM artifact_message_user_vw WHERE id=$1',
144 if (!$res || db_numrows($res) < 1) {
145 $this->setError('ArtifactMessage: Invalid ArtifactMessage ID');
148 $this->data_array = db_fetch_array($res);
149 db_free_result($res);
154 * getArtifact - get the Artifact Object this ArtifactMessage is associated with.
156 * @return object Artifact.
158 function &getArtifact() {
159 return $this->Artifact;
163 * getID - get this ArtifactMessage's ID.
165 * @return int The id #.
168 return $this->data_array['id'];
172 * getBody - get the message body.
174 * @return string The message body.
177 return $this->data_array['body'];
181 * getAddDate - get the date this message was added.
183 * @return int adddate.
185 function getAddDate() {
186 return $this->data_array['addate'];
190 * getUserID - get the ID of the person who posted this.
192 * @return int user_id.
194 function getUserID() {
195 return $this->data_array['user_id'];
202 // c-file-style: "bsd"