3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/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 ProjectCategory extends Error {
30 * The ProjectGroup object.
32 * @var object $ProjectGroup.
34 var $ProjectGroup; //object
39 * @var array $data_array.
44 * ProjectCategory - constructor.
46 * @param object ProjectGroup object.
47 * @param array (all fields from project_category) OR category_id from database.
48 * @return boolean success.
50 function ProjectCategory(&$ProjectGroup, $data=false) {
53 //was ProjectGroup legit?
54 if (!$ProjectGroup || !is_object($ProjectGroup)) {
55 $this->setError('ProjectCategory: No Valid ProjectGroup');
58 //did ProjectGroup have an error?
59 if ($ProjectGroup->isError()) {
60 $this->setError('ProjectCategory: '.$ProjectGroup->getErrorMessage());
63 $this->ProjectGroup =& $ProjectGroup;
66 if (is_array($data)) {
67 $this->data_array =& $data;
69 // should verify group_project_id
73 if (!$this->fetchData($data)) {
83 * create - create a new item in the database.
85 * @param string Item name.
86 * @return boolean success.
88 function create($name) {
93 $this->setError(_('ProjectCategory: name and assignee are Required'));
97 if (!forge_check_perm ('pm_admin', $this->ProjectGroup->Group->getID())) {
98 $this->setPermissionDeniedError();
101 $result = db_query_params ('INSERT INTO project_category (group_project_id,category_name) VALUES ($1,$2)',
102 array ($this->ProjectGroup->getID(),
103 htmlspecialchars($name))) ;
105 if ($result && db_affected_rows($result) > 0) {
108 $id=db_insertid($result,'project_category','category_id');
111 // Now set up our internal data structures
113 if (!$this->fetchData($id)) {
119 $this->setError(db_error());
125 * fetchData() - re-fetch the data for this ProjectCategory from the database.
127 * @param int ID of the category.
128 * @return boolean success.
130 function fetchData($id) {
131 $res = db_query_params ('SELECT * FROM project_category WHERE category_id=$1',
133 if (!$res || db_numrows($res) < 1) {
134 $this->setError('ProjectCategory: Invalid ProjectCategory ID');
137 $this->data_array = db_fetch_array($res);
138 db_free_result($res);
143 * getProjectGroup - get the ProjectGroup Object this ProjectCategory is associated with.
145 * @return object ProjectGroup.
147 function &getProjectGroup() {
148 return $this->ProjectGroup;
152 * getID - get this ProjectCategory's ID.
154 * @return int The id #.
157 return $this->data_array['category_id'];
161 * getName - get the name.
163 * @return string The name.
166 return $this->data_array['category_name'];
170 * update - update a ProjectCategory.
172 * @param string Name of the category.
173 * @return boolean success.
175 function update($name) {
176 if (!forge_check_perm ('pm_admin', $this->ProjectGroup->Group->getID())) {
177 $this->setPermissionDeniedError();
181 $this->setMissingParamsError();
184 $result = db_query_params ('UPDATE project_category SET category_name=$1
185 WHERE category_id=$2 AND group_project_id=$3',
186 array (htmlspecialchars($name),
188 $this->ProjectGroup->getID())) ;
189 if ($result && db_affected_rows($result) > 0) {
192 $this->setError(db_error());
200 // c-file-style: "bsd"