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 ProjectGroup $ProjectGroup.
34 var $ProjectGroup; //object
39 * @var array $data_array.
44 * ProjectCategory - constructor.
46 * @param object $ProjectGroup ProjectGroup object.
47 * @param array|bool $data (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)) {
84 * create - create a new item in the database.
86 * @param string $name Item name.
87 * @return boolean success.
89 function create($name) {
94 $this->setError(_('ProjectCategory: name and assignee are Required'));
98 if (!forge_check_perm ('pm_admin', $this->ProjectGroup->Group->getID())) {
99 $this->setPermissionDeniedError();
102 $result = db_query_params ('INSERT INTO project_category (group_project_id,category_name) VALUES ($1,$2)',
103 array ($this->ProjectGroup->getID(),
104 htmlspecialchars($name))) ;
106 if ($result && db_affected_rows($result) > 0) {
109 $id=db_insertid($result,'project_category','category_id');
112 // Now set up our internal data structures
114 if (!$this->fetchData($id)) {
120 $this->setError(db_error());
126 * fetchData() - re-fetch the data for this ProjectCategory from the database.
128 * @param int $id ID of the category.
129 * @return boolean success.
131 function fetchData($id) {
132 $res = db_query_params ('SELECT * FROM project_category WHERE category_id=$1',
134 if (!$res || db_numrows($res) < 1) {
135 $this->setError('ProjectCategory: Invalid ProjectCategory ID');
138 $this->data_array = db_fetch_array($res);
139 db_free_result($res);
144 * getProjectGroup - get the ProjectGroup Object this ProjectCategory is associated with.
146 * @return object ProjectGroup.
148 function &getProjectGroup() {
149 return $this->ProjectGroup;
153 * getID - get this ProjectCategory's ID.
155 * @return int The id #.
158 return $this->data_array['category_id'];
162 * getName - get the name.
164 * @return string The name.
167 return $this->data_array['category_name'];
171 * update - update a ProjectCategory.
173 * @param string $name Name of the category.
174 * @return boolean success.
176 function update($name) {
177 if (!forge_check_perm ('pm_admin', $this->ProjectGroup->Group->getID())) {
178 $this->setPermissionDeniedError();
182 $this->setMissingParamsError();
185 $result = db_query_params ('UPDATE project_category SET category_name=$1
186 WHERE category_id=$2 AND group_project_id=$3',
187 array (htmlspecialchars($name),
189 $this->ProjectGroup->getID())) ;
190 if ($result && db_affected_rows($result) > 0) {
193 $this->setError(db_error());
201 // c-file-style: "bsd"