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) {
109 $this->setError(db_error());
115 // Now set up our internal data structures
117 if (!$this->fetchData($id)) {
124 * fetchData() - re-fetch the data for this ProjectCategory from the database.
126 * @param int ID of the category.
127 * @return boolean success.
129 function fetchData($id) {
130 $res = db_query_params ('SELECT * FROM project_category WHERE category_id=$1',
132 if (!$res || db_numrows($res) < 1) {
133 $this->setError('ProjectCategory: Invalid ProjectCategory ID');
136 $this->data_array = db_fetch_array($res);
137 db_free_result($res);
142 * getProjectGroup - get the ProjectGroup Object this ProjectCategory is associated with.
144 * @return object ProjectGroup.
146 function &getProjectGroup() {
147 return $this->ProjectGroup;
151 * getID - get this ProjectCategory's ID.
153 * @return int The id #.
156 return $this->data_array['category_id'];
160 * getName - get the name.
162 * @return string The name.
165 return $this->data_array['category_name'];
169 * update - update a ProjectCategory.
171 * @param string Name of the category.
172 * @return boolean success.
174 function update($name) {
175 if (!forge_check_perm ('pm_admin', $this->ProjectGroup->Group->getID())) {
176 $this->setPermissionDeniedError();
180 $this->setMissingParamsError();
183 $result = db_query_params ('UPDATE project_category SET category_name=$1
184 WHERE category_id=$2 AND group_project_id=$3',
185 array (htmlspecialchars($name),
187 $this->ProjectGroup->getID())) ;
188 if ($result && db_affected_rows($result) > 0) {
191 $this->setError(db_error());
199 // c-file-style: "bsd"