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/FFError.class.php';
27 class ArtifactCanned extends FFError {
30 * The artifact type object.
32 * @var object $ArtifactType.
37 * Array of artifact data.
39 * @var array $data_array.
44 * @param ArtifactType $ArtifactType The Artifact Type object.
45 * @param array|bool $data (all fields from artifact_file_user_vw) OR id from database.
47 function __construct(&$ArtifactType, $data=false) {
48 parent::__construct();
50 // Was ArtifactType legit?
51 if (!$ArtifactType || !is_object($ArtifactType)) {
52 $this->setError('ArtifactCanned: No Valid ArtifactType');
55 // Did ArtifactType have an error?
56 if ($ArtifactType->isError()) {
57 $this->setError('ArtifactCanned: '.$ArtifactType->getErrorMessage());
60 $this->ArtifactType =& $ArtifactType;
63 if (is_array($data)) {
64 $this->data_array =& $data;
66 $this->fetchData($data);
72 * create - create a new item in the database.
74 * @param string $title The item title.
75 * @param string $body The item body.
76 * @return int id on success / false on failure.
78 function create($title, $body) {
82 if (!$title || !$body) {
83 $this->setError(_('Title and Message Body are required'));
86 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
87 $this->setPermissionDeniedError();
90 $result = db_query_params ('INSERT INTO artifact_canned_responses (group_artifact_id,title,body) VALUES ($1,$2,$3)',
91 array ($this->ArtifactType->getID(),
92 htmlspecialchars($title),
93 htmlspecialchars($body))) ;
95 if ($result && db_affected_rows($result) > 0) {
99 $this->setError(db_error());
105 // Now set up our internal data structures
107 if (!$this->fetchData($id)) {
114 * fetchData - re-fetch the data for this ArtifactCanned from the database.
116 * @param int $id The ID number.
117 * @return bool success.
119 function fetchData($id) {
120 $res = db_query_params ('SELECT * FROM artifact_canned_responses WHERE id=$1',
122 if (!$res || db_numrows($res) < 1) {
123 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
126 $this->data_array = db_fetch_array($res);
127 db_free_result($res);
132 * getArtifactType - get the ArtifactType Object this ArtifactCanned message is associated with.
134 * @return ArtifactType.
136 function &getArtifactType() {
137 return $this->ArtifactType;
141 * getID - get this ArtifactCanned message's ID.
143 * @return int The id #.
146 return $this->data_array['id'];
150 * getTitle - get the title.
152 * @return string The title.
154 function getTitle() {
155 return $this->data_array['title'];
159 * getBody - get the body of this message.
161 * @return string The message body.
164 return $this->data_array['body'];
168 * update - update an ArtifactCanned message.
170 * @param string $title Title of the message.
171 * @param string $body Body of the message.
172 * @return bool success.
174 function update($title,$body) {
175 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
176 $this->setPermissionDeniedError();
179 if (!$title || !$body) {
180 $this->setMissingParamsError();
184 $result = db_query_params ('UPDATE artifact_canned_responses
186 WHERE group_artifact_id=$3 AND id=$4',
187 array (htmlspecialchars($title),
188 htmlspecialchars($body),
189 $this->ArtifactType->getID(),
192 if ($result && db_affected_rows($result) > 0) {
195 $this->setError(db_error());
201 * delete - delete an ArtifactCanned message.
203 * @return bool success.
206 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
207 $this->setPermissionDeniedError();
210 if (!$this->getID()) {
211 $this->setError('Internal error: No ID given');
215 $result = db_query_params('DELETE FROM artifact_canned_responses WHERE ID=$1',
216 array ($this->getID()));
218 if ($result && db_affected_rows($result) > 0) {
221 $this->setError(db_error());
229 // c-file-style: "bsd"