5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
7 * Copyright 2009, Roland Mas
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/Error.class.php';
27 class ArtifactCanned extends Error {
30 * The artifact type object.
32 * @var object $ArtifactType.
37 * Array of artifact data.
39 * @var array $data_array.
44 * __construct - constructor.
46 * @param ArtifactType $ArtifactType The Artifact Type object.
47 * @param array|bool $data (all fields from artifact_file_user_vw) OR id from database.
48 * @return ArtifactCanned success.
50 function __construct(&$ArtifactType, $data=false) {
53 // Was ArtifactType legit?
54 if (!$ArtifactType || !is_object($ArtifactType)) {
55 $this->setError('ArtifactCanned: No Valid ArtifactType');
58 // Did ArtifactType have an error?
59 if ($ArtifactType->isError()) {
60 $this->setError('ArtifactCanned: '.$ArtifactType->getErrorMessage());
63 $this->ArtifactType =& $ArtifactType;
66 if (is_array($data)) {
67 $this->data_array =& $data;
69 $this->fetchData($data);
75 * create - create a new item in the database.
77 * @param string $title The item title.
78 * @param string $body The item body.
79 * @return int id on success / false on failure.
81 function create($title, $body) {
85 if (!$title || !$body) {
86 $this->setError(_('Title and Message Body are required'));
89 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
90 $this->setPermissionDeniedError();
93 $result = db_query_params ('INSERT INTO artifact_canned_responses (group_artifact_id,title,body) VALUES ($1,$2,$3)',
94 array ($this->ArtifactType->getID(),
95 htmlspecialchars($title),
96 htmlspecialchars($body))) ;
98 if ($result && db_affected_rows($result) > 0) {
102 $this->setError(db_error());
108 // Now set up our internal data structures
110 if (!$this->fetchData($id)) {
117 * fetchData - re-fetch the data for this ArtifactCanned from the database.
119 * @param int $id The ID number.
120 * @return boolean success.
122 function fetchData($id) {
123 $res = db_query_params ('SELECT * FROM artifact_canned_responses WHERE id=$1',
125 if (!$res || db_numrows($res) < 1) {
126 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
129 $this->data_array = db_fetch_array($res);
130 db_free_result($res);
135 * getArtifactType - get the ArtifactType Object this ArtifactCanned message is associated with.
137 * @return ArtifactType.
139 function &getArtifactType() {
140 return $this->ArtifactType;
144 * getID - get this ArtifactCanned message's ID.
146 * @return int The id #.
149 return $this->data_array['id'];
153 * getTitle - get the title.
155 * @return string The title.
157 function getTitle() {
158 return $this->data_array['title'];
162 * getBody - get the body of this message.
164 * @return string The message body.
167 return $this->data_array['body'];
171 * update - update an ArtifactCanned message.
173 * @param string $title Title of the message.
174 * @param string $body Body of the message.
175 * @return boolean success.
177 function update($title,$body) {
178 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
179 $this->setPermissionDeniedError();
182 if (!$title || !$body) {
183 $this->setMissingParamsError();
187 $result = db_query_params ('UPDATE artifact_canned_responses
189 WHERE group_artifact_id=$3 AND id=$4',
190 array (htmlspecialchars($title),
191 htmlspecialchars($body),
192 $this->ArtifactType->getID(),
195 if ($result && db_affected_rows($result) > 0) {
198 $this->setError(db_error());
204 * delete - delete an ArtifactCanned message.
206 * @return boolean success.
209 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
210 $this->setPermissionDeniedError();
213 if (!$this->getID()) {
214 $this->setError('Internal error: No ID given');
218 $result = db_query_params('DELETE FROM artifact_canned_responses WHERE ID=$1',
219 array ($this->getID()));
221 if ($result && db_affected_rows($result) > 0) {
224 $this->setError(db_error());
232 // c-file-style: "bsd"