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 FFError {
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.
54 * @return bool success;
56 function fetchData($cat_id, &$res = false) {
58 unset($this->data_array);
61 $res = db_query_params('SELECT * FROM trove_cat WHERE trove_cat_id=$1',
63 if (!$res || db_numrows($res) < 1) {
64 $this->setError('TroveCat::fetchData()::'.db_error());
68 $row = db_fetch_array($res);
70 $this->data_array = $row;
78 return $this->data_array['trove_cat_id'];
81 function getShortName() {
82 return $this->data_array['shortname'];
85 function getFullName() {
86 return $this->data_array['fullname'];
89 function getParentId() {
90 return $this->data_array['parent'];
93 function getRootCatId() {
94 return $this->data_array['root_parent'];
97 function getIdsFullPath() {
98 return $this->data_array['fullpath_ids'];
102 function getDescription() {
103 return $this->data_array['description'];
107 function listSubTree() {
108 return TroveCat::getSubtree($this->data_array['trove_cat_id']);
111 static function getAllRoots() {
114 $res = db_query_params ('
118 AND trove_cat_id!=0',
122 $trovecat = new TroveCat();
123 $fetched = $trovecat->fetchData(false, $res);
125 $rootcats[] = $trovecat;
132 static function getSubtree($root_cat_id) {
135 $res = db_query_params('
140 array($root_cat_id));
143 $trovecat = new TroveCat();
144 $fetched = $trovecat->fetchData(false, $res);
146 $subcats[] = $trovecat;
153 static function getProjectCats($group_id) {
156 $res = db_query_params ('
157 SELECT trove_cat.trove_cat_id AS trove_cat_id
158 FROM trove_cat,trove_group_link
159 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
160 AND trove_group_link.group_id=$1
161 ORDER BY trove_cat.fullpath',
165 while($row = db_fetch_array($res)) {
166 $catids[] = $row['trove_cat_id'];
169 foreach($catids as $catid) {
170 $cats[] = new TroveCat($catid);
178 // c-file-style: "bsd"