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/FFError.class.php';
26 class ArtifactMessage extends FFError {
29 * The artifact object.
31 * @var object $Artifact.
33 var $Artifact; //object
36 * Array of artifact data.
38 * @var array $data_array.
43 * @param object $Artifact Artifact object.
44 * @param array|bool $data (all fields from artifact_history_user_vw) OR id from database.
46 function __construct(&$Artifact, $data = false) {
47 parent::__construct();
50 if (!$Artifact || !is_object($Artifact)) {
51 $this->setError(_('Invalid Artifact'));
54 //did Artifact have an error?
55 if ($Artifact->isError()) {
56 $this->setError('ArtifactMessage: '.$Artifact->getErrorMessage());
59 $this->Artifact =& $Artifact;
62 if (is_array($data)) {
63 $this->data_array =& $data;
65 $this->fetchData($data);
71 * create - create a new item in the database.
73 * @param string $body Body.
74 * @param string|bool $by Email of submitter (obsolete?).
75 * @return int|bool id on success / false on failure.
77 function create($body, $by = false, $importData = array()) {
79 $this->setMissingParamsError();
83 if(array_key_exists('user', $importData)) {
84 $user_id = $importData['user'];
85 $user = user_get_object($user_id);
86 if (!$user || !is_object($user)) {
87 $this->setError('Error: Logged In User But Could Not Get User Object');
90 $by = $user->getEmail();
92 if (session_loggedin()) {
93 $user_id = user_getid();
94 $user = user_get_object($user_id);
95 if (!$user || !is_object($user)) {
96 $this->setError('Error: Logged In User But Could Not Get User Object');
99 // we'll store this email even though it will likely never be used -
100 // since we have their correct user_id, we can join the USERS table to get email
101 $by = $user->getEmail();
104 if (!$by || !validate_email($by)) {
105 $this->setMissingParamsError();
110 if(array_key_exists('time', $importData)){
111 $time = $importData['time'];
116 $res = db_query_params ('INSERT INTO artifact_message (artifact_id, submitted_by, from_email, adddate, body)
117 VALUES ($1, $2, $3, $4, $5)',
118 array ($this->Artifact->getID(),
122 htmlspecialchars($body))) ;
124 $this->setError(db_error());
127 $id = db_insertid($res,'artifact_message','id');
131 // Now set up our internal data structures
133 if (!$this->fetchData($id)) {
140 * fetchData - re-fetch the data for this ArtifactMessage from the database.
142 * @param int $id ID of the category.
143 * @return boolean success.
145 function fetchData($id) {
146 $res = db_query_params ('SELECT * FROM artifact_message_user_vw WHERE id=$1',
148 if (!$res || db_numrows($res) < 1) {
149 $this->setError(_('Invalid ArtifactMessage ID'));
152 $this->data_array = db_fetch_array($res);
153 db_free_result($res);
158 * getArtifact - get the Artifact Object this ArtifactMessage is associated with.
160 * @return object Artifact.
162 function &getArtifact() {
163 return $this->Artifact;
167 * getID - get this ArtifactMessage's ID.
169 * @return int The id #.
172 return $this->data_array['id'];
176 * getBody - get the message body.
178 * @return string The message body.
181 return $this->data_array['body'];
185 * getAddDate - get the date this message was added.
187 * @return int adddate.
189 function getAddDate() {
190 return $this->data_array['adddate'];
194 * getUserID - get the ID of the person who posted this.
196 * @return int user_id.
198 function getUserID() {
199 return $this->data_array['user_id'];
206 // c-file-style: "bsd"