3 * FusionForge trove categories
5 * Copyright 2013, Olivier Berger and Institut Mines-Telecom
6 * Copyright 2013, 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.
25 * TODO: FusionForge Trove Categories
28 class TroveCat extends Error {
33 * TroveCat() - CONSTRUCTOR.
35 * @param bool|int $cat_id The cat_id.
37 function TroveCat($cat_id = false) {
40 //setting up an empty object
41 //probably going to call create()
44 return $this->fetchData($cat_id);
48 * fetchData - May need to refresh database fields.
50 * If an update occurred and you need to access the updated info.
52 * @return bool success;
54 function fetchData($cat_id, &$res = false) {
56 unset($this->data_array);
59 $res = db_query_params('SELECT * FROM trove_cat WHERE trove_cat_id=$1',
61 if (!$res || db_numrows($res) < 1) {
62 $this->setError('TroveCat::fetchData()::'.db_error());
66 $row = db_fetch_array($res);
68 $this->data_array = $row;
77 return $this->data_array['trove_cat_id'];
80 function getShortName() {
81 return $this->data_array['shortname'];
84 function getFullName() {
85 return $this->data_array['fullname'];
88 function getParentId() {
89 return $this->data_array['parent'];
92 function getRootCatId() {
93 return $this->data_array['root_parent'];
96 function getIdsFullPath() {
97 return $this->data_array['fullpath_ids'];
101 function getDescription() {
102 return $this->data_array['description'];
106 function listSubTree() {
107 return TroveCat::getSubtree($this->data_array['trove_cat_id']);
110 static function getAllRoots() {
113 $res = db_query_params ('
117 AND trove_cat_id!=0',
121 $trovecat = new TroveCat();
122 $fetched = $trovecat->fetchData(false, $res);
124 $rootcats[] = $trovecat;
131 static function getSubtree($root_cat_id) {
134 $res = db_query_params('
139 array($root_cat_id));
142 $trovecat = new TroveCat();
143 $fetched = $trovecat->fetchData(false, $res);
145 $subcats[] = $trovecat;
152 static function getProjectCats($group_id) {
155 $res = db_query_params ('
156 SELECT trove_cat.trove_cat_id AS trove_cat_id
157 FROM trove_cat,trove_group_link
158 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
159 AND trove_group_link.group_id=$1
160 ORDER BY trove_cat.fullpath',
164 while($row = db_fetch_array($res)) {
165 $catids[] = $row['trove_cat_id'];
168 foreach($catids as $catid) {
169 $cats[] = new TroveCat($catid);
177 // c-file-style: "bsd"