3 * ArtifactExtraField.class.php - Class to handle user defined artifacts
5 * Copyright 2004 (c) Anthony J. Pugliese
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
25 require_once $gfcommon.'include/Error.class.php';
27 class ArtifactExtraFieldElement extends Error {
30 * The artifact type object.
32 * @var object $ArtifactExtraField.
34 var $ArtifactExtraField; //object
37 * Array of artifact data.
39 * @var array $data_array.
43 * ArtifactExtraFieldElement - Constructer
45 * @param object ArtifactExtraField object.
46 * @param array (all fields from artifact_file_user_vw) OR id from database.
47 * @return boolean success.
49 function ArtifactExtraFieldElement(&$ArtifactExtraField,$data=false) {
52 //was ArtifactExtraField legit?
53 if (!$ArtifactExtraField || !is_object($ArtifactExtraField)) {
54 $this->setError('ArtifactExtraField: No Valid ArtifactExtraField');
57 //did ArtifactExtraField have an error?
58 if ($ArtifactExtraField->isError()) {
59 $this->setError('ArtifactExtraField: '.$ArtifactExtraField->getErrorMessage());
62 $this->ArtifactExtraField =& $ArtifactExtraField;
64 if (is_array($data)) {
65 //TODO validate that data actually belongs in this ArtifactExtraField
66 $this->data_array =& $data;
69 if (!$this->fetchData($data)) {
79 * create - create a new row in the table used to store the
80 * choices for selection boxes. This function is only used for
81 * extra fields and boxes configured by the admin
83 * @param string Name of the choice
84 * @param int Id the box that contains the choice.
85 * @param int status_id - optional for status box - maps to either open/closed.
86 * @return true on success / false on failure.
89 function create($name,$status_id=0) {
93 if (trim($name) == '') {
94 $this->setError(_('an element name is required'));
105 if (!$this->ArtifactExtraField->ArtifactType->userIsAdmin()) {
106 $this->setPermissionDeniedError();
109 $sql="INSERT INTO artifact_extra_field_elements (extra_field_id,element_name,status_id)
110 VALUES ('".$this->ArtifactExtraField->getID()."','".htmlspecialchars($name)."','$status_id')";
112 $result=db_query($sql);
113 if ($result && db_affected_rows($result) > 0) {
115 $id=db_insertid($result,'artifact_extra_field_elements','element_id');
117 // Now set up our internal data structures
119 if (!$this->fetchData($id)) {
127 $this->setError(db_error());
135 * fetchData - re-fetch the data for this ArtifactExtraFieldElement from the database.
137 * @param int ID of the Box.
138 * @return boolean success.
140 function fetchData($id) {
141 $res=db_query("SELECT * FROM artifact_extra_field_elements WHERE element_id='$id'");
142 if (!$res || db_numrows($res) < 1) {
143 $this->setError('ArtifactExtraField: Invalid ArtifactExtraFieldElement ID');
146 $this->data_array =& db_fetch_array($res);
147 db_free_result($res);
152 * getArtifactExtraField - get the ArtifactExtraField Object this ArtifactExtraField is associated with.
154 * @return object ArtifactExtraField.
156 function &getArtifactExtraField() {
157 return $this->ArtifactExtraField;
161 * getID - get this ArtifactExtraField ID.
163 * @return int The id #.
166 return $this->data_array['element_id'];
170 * getBoxID - get this artifact box id.
172 * @return int The id #.
174 function getBoxID() {
175 return $this->data_array['extra_field_id'];
179 * getName - get the name.
181 * @return string The name.
184 return $this->data_array['element_name'];
188 * getStatus - the status equivalent of this field (open or closed).
190 * @return int status.
192 function getStatusID() {
193 return $this->data_array['status_id'];
197 * update - update rows in the table used to store the choices
198 * for a selection box. This function is used only for extra
199 * boxes and fields configured by the admin
201 * @param string Name of the choice in a box.
202 * @param int status_id - optional for status box - maps to either open/closed.
203 * @return boolean success.
205 function update($name,$status_id=0) {
206 if (!$this->ArtifactExtraField->ArtifactType->userIsAdmin()) {
207 $this->setPermissionDeniedError();
211 $this->setMissingParamsError();
222 $sql="UPDATE artifact_extra_field_elements
223 SET element_name='".htmlspecialchars($name)."',
224 status_id='$status_id'
225 WHERE element_id='".$this->getID()."'";
226 $result=db_query($sql);
227 if ($result && db_affected_rows($result) > 0) {
230 $this->setError(db_error());
238 // c-file-style: "bsd"