5 * Copyright 2004, Anthony J. Pugliese
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 ArtifactBoxOptions extends Error {
29 * The artifact type object.
31 * @var object $ArtifactType.
33 var $ArtifactType; //object
36 * Array of artifact data.
38 * @var array $data_array.
42 * ArtifactSelectionBox - Constructer
44 * @param object ArtifactType object.
45 * @param array (all fields from artifact_file_user_vw) OR id from database.
46 * @return boolean success.
48 function __construct(&$ArtifactType,$data=false) {
51 //was ArtifactType legit?
52 if (!$ArtifactType || !is_object($ArtifactType)) {
53 $this->setError('ArtifactSelectionBox: No Valid ArtifactType');
56 //did ArtifactType have an error?
57 if ($ArtifactType->isError()) {
58 $this->setError('ArtifactSelectionBox: '.$ArtifactType->getErrorMessage());
61 $this->ArtifactType =& $ArtifactType;
63 if (is_array($data)) {
64 $this->data_array =& $data;
67 if (!$this->fetchData($data)) {
77 * create - create a new row in the table used to store the
78 * choices for selection boxes. This function is only used for
79 * extra fields and boxes configured by the admin
81 * @param string Name of the choice
82 * @param int Id the box that contains the choice.
83 * @return true on success / false on failure.
86 function create($name,$id) {
87 //settype($id,"integer");
92 $this->setError(_('an element name is required'));
95 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
96 $this->setPermissionDeniedError();
99 $result = db_query_params ('INSERT INTO artifact_group_selection_box_options (artifact_box_id,box_options_name) VALUES ($1,$2)',
101 htmlspecialchars($name))) ;
103 if ($result && db_affected_rows($result) > 0) {
107 $this->setError(db_error());
113 // Now set up our internal data structures
115 if (!$this->fetchData($id)) {
123 * fetchData - re-fetch the data for this ArtifactBoxOptions from the database.
125 * @param int ID of the Box.
126 * @return boolean success.
128 function fetchData($id) {
129 $res = db_query_params ('SELECT * FROM artifact_group_selection_box_options WHERE id=$1',
131 if (!$res || db_numrows($res) < 1) {
132 $this->setError('ArtifactSelectionBox: Invalid Artifact ID');
135 $this->data_array = db_fetch_array($res);
136 db_free_result($res);
141 * getArtifactType - get the ArtifactType Object this ArtifactSelectionBox is associated with.
143 * @return object ArtifactType.
145 function &getArtifactType() {
146 return $this->ArtifactType;
150 * getID - get this ArtifactSelectionBox ID.
152 * @return int The id #.
155 return $this->data_array['id'];
159 * getBoxID - get this artifact box id.
161 * @return int The id #.
163 function getBoxID() {
164 return $this->data_array['artifact_box_id'];
168 * getName - get the name.
170 * @return string The name.
173 return $this->data_array['box_options_name'];
178 * update - update rows in the table used to store the choices
179 * for a selection box. This function is used only for extra
180 * boxes and fields configured by the admin
182 * @param string Name of the choice in a box.
183 * @param int Id of the box
184 * @param int id of the row
185 * @return boolean success.
187 function update($name,$boxid,$id) {
188 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
189 $this->setPermissionDeniedError();
193 $this->setMissingParamsError();
196 $result = db_query_params ('UPDATE artifact_group_selection_box_options
197 SET box_options_name=$1
199 array (htmlspecialchars($name),
201 if ($result && db_affected_rows($result) > 0) {
204 $this->setError(db_error());
212 // c-file-style: "bsd"