6 * Copyright 2004 (c) Guillaume Smet
7 * http://fusionforge.org/
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.
26 CREATE TABLE trove_category_labels (
28 category_id int REFERENCES trove_cat ON UPDATE CASCADE ON DELETE CASCADE,
29 language_id int REFERENCES supported_languages ON UPDATE CASCADE ON DELETE CASCADE,
31 PRIMARY KEY(label_id));
34 class TroveCategoryLabel extends Error {
38 var $dataArray = false;
40 function TroveCategoryLabel(& $category, $labelId = false, $dataArray = false) {
42 if (!$category || !is_object($category)) {
45 if ($category->isError()) {
46 //$this->setError('MailingList:: '.$Group->getErrorMessage());
49 $this->category =& $category;
52 $this->labelId = $labelId;
53 if (!$dataArray || !is_array($dataArray)) {
54 if (!$this->fetchData($labelId)) {
58 $this->dataArray =& $dataArray;
59 if ($this->dataArray['category_id'] != $this->category->getId()) {
60 $this->dataArray = null;
69 function create($label, $languageId) {
70 if(strlen($label) == 0) {
76 $result = db_query_params("INSERT INTO trove_category_labels
77 (category_id, label, language_id) VALUES ($1, $2, $3)",
78 array($this->category->getId(), $label, $languageId));
84 $this->labelId = db_insertid($result, 'trove_category_labels', 'label_id');
85 $this->fetchData($this->labelId);
93 function fetchData($labelId) {
94 $res=db_query_params("SELECT trove_category_labels.*, supported_languages.name AS language_name FROM trove_category_labels, supported_languages "
95 . "WHERE trove_category_labels.label_id=$1 "
96 . "AND trove_category_labels.category_id=$2 "
97 . "AND supported_languages.language_id=trove_category_labels.language_id",
98 array($labelId, $this->category->getId()));
100 if (!$res || db_numrows($res) < 1) {
103 $this->dataArray =& db_fetch_array($res);
104 db_free_result($res);
110 $res = db_query_params("DELETE FROM trove_category_labels WHERE label_id=$1", array($this->labelId));
111 if(!$res || db_affected_rows($res) != 1) {
112 // $this->setError();
122 return $this->labelId;
125 function getLabel() {
126 return $this->dataArray['label'];
129 function getLanguageId() {
130 return $this->dataArray['language_id'];
133 function getLanguageName() {
134 return $this->dataArray['language_name'];