1 | <?php |
---|
2 | |
---|
3 | function getKeywordCategory($id) |
---|
4 | { |
---|
5 | GLOBAL $db; |
---|
6 | |
---|
7 | if (!is_numeric($id)) |
---|
8 | die ("invalid id"); |
---|
9 | |
---|
10 | $queryStr = "SELECT * FROM phpgw_mydms_KeywordCategories WHERE id = " . $id; |
---|
11 | $resArr = $db->getResultArray($queryStr); |
---|
12 | if ((is_bool($resArr) && !$resArr) || (count($resArr) != 1)) |
---|
13 | return false; |
---|
14 | |
---|
15 | $resArr = $resArr[0]; |
---|
16 | return new Keywordcategory($resArr["id"], $resArr["owner"], $resArr["name"]); |
---|
17 | } |
---|
18 | |
---|
19 | function getAllKeywordCategories($userID = -1) |
---|
20 | { |
---|
21 | GLOBAL $db, $settings; |
---|
22 | |
---|
23 | $queryStr = "SELECT * FROM phpgw_mydms_KeywordCategories"; |
---|
24 | if ($userID != -1) |
---|
25 | $queryStr .= " WHERE owner = $userID OR owner = " . $settings->_adminID; |
---|
26 | |
---|
27 | $resArr = $db->getResultArray($queryStr); |
---|
28 | if (is_bool($resArr) && !$resArr) |
---|
29 | return false; |
---|
30 | |
---|
31 | $categories = array(); |
---|
32 | foreach ($resArr as $row) |
---|
33 | array_push($categories, new KeywordCategory($row["id"], $row["owner"], $row["name"])); |
---|
34 | |
---|
35 | return $categories; |
---|
36 | } |
---|
37 | |
---|
38 | function addKeywordCategory($owner, $name) |
---|
39 | { |
---|
40 | GLOBAL $db; |
---|
41 | |
---|
42 | $queryStr = "INSERT INTO phpgw_mydms_KeywordCategories (owner, name) VALUES ($owner, '$name')"; |
---|
43 | if (!$db->getResult($queryStr)) |
---|
44 | return false; |
---|
45 | |
---|
46 | return getKeywordCategory($db->getInsertID('phpgw_mydms_KeywordCategories','id')); |
---|
47 | } |
---|
48 | |
---|
49 | //---------------------------------------------------------------------------------------------- |
---|
50 | class KeywordCategory |
---|
51 | { |
---|
52 | var $_id; |
---|
53 | var $_ownerID; |
---|
54 | var $_name; |
---|
55 | |
---|
56 | function KeywordCategory($id, $ownerID, $name) |
---|
57 | { |
---|
58 | $this->_id = $id; |
---|
59 | $this->_name = $name; |
---|
60 | $this->_ownerID = $ownerID; |
---|
61 | } |
---|
62 | |
---|
63 | function getID() { return $this->_id; } |
---|
64 | |
---|
65 | function getName() { return $this->_name; } |
---|
66 | |
---|
67 | function getOwner() { |
---|
68 | if (!isset($this->_owner)) |
---|
69 | $this->_owner = getUser($this->_ownerID); |
---|
70 | return $this->_owner; |
---|
71 | } |
---|
72 | |
---|
73 | function setName($newName) |
---|
74 | { |
---|
75 | GLOBAL $db; |
---|
76 | |
---|
77 | $queryStr = "UPDATE phpgw_mydms_KeywordCategories SET name = '$newName' WHERE id = ". $this->_id; |
---|
78 | if (!$db->getResult($queryStr)) |
---|
79 | return false; |
---|
80 | |
---|
81 | $this->_name = $newName; |
---|
82 | return true; |
---|
83 | } |
---|
84 | |
---|
85 | function setOwner($user) { |
---|
86 | GLOBAL $db; |
---|
87 | |
---|
88 | $queryStr = "UPDATE phpgw_mydms_KeywordCategories SET owner = " . $user->getID() . " WHERE id " . $this->_id; |
---|
89 | if (!$db->getResult($queryStr)) |
---|
90 | return false; |
---|
91 | |
---|
92 | $this->_ownerID = $user->getID(); |
---|
93 | $this->_owner = $user; |
---|
94 | return true; |
---|
95 | } |
---|
96 | |
---|
97 | function getKeywordLists() { |
---|
98 | GLOBAL $db; |
---|
99 | |
---|
100 | $queryStr = "SELECT * FROM phpgw_mydms_Keywords WHERE category = " . $this->_id; |
---|
101 | return $db->getResultArray($queryStr); |
---|
102 | } |
---|
103 | |
---|
104 | function editKeywordList($listID, $keywords) { |
---|
105 | GLOBAL $db; |
---|
106 | |
---|
107 | $queryStr = "UPDATE phpgw_mydms_Keywords SET keywords = '$keywords' WHERE id = $listID"; |
---|
108 | return $db->getResult($queryStr); |
---|
109 | } |
---|
110 | |
---|
111 | function addKeywordList($keywords) { |
---|
112 | GLOBAL $db; |
---|
113 | |
---|
114 | $queryStr = "INSERT INTO phpgw_mydms_Keywords (category, keywords) VALUES (" . $this->_id . ", '$keywords')"; |
---|
115 | return $db->getResult($queryStr); |
---|
116 | } |
---|
117 | |
---|
118 | function removeKeywordList($listID) { |
---|
119 | GLOBAL $db; |
---|
120 | |
---|
121 | $queryStr = "DELETE FROM phpgw_mydms_Keywords WHERE id = $listID"; |
---|
122 | return $db->getResult($queryStr); |
---|
123 | } |
---|
124 | |
---|
125 | function remove() |
---|
126 | { |
---|
127 | GLOBAL $db; |
---|
128 | |
---|
129 | $queryStr = "DELETE FROM phpgw_mydms_Keywords WHERE category = " . $this->_id; |
---|
130 | if (!$db->getResult($queryStr)) |
---|
131 | return false; |
---|
132 | |
---|
133 | $queryStr = "DELETE FROM phpgw_mydms_KeywordCategories WHERE id = " . $this->_id; |
---|
134 | if (!$db->getResult($queryStr)) |
---|
135 | return false; |
---|
136 | |
---|
137 | return true; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | ?> |
---|