Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
77.59% |
45 / 58 |
|
61.54% |
8 / 13 |
CRAP | |
0.00% |
0 / 1 |
SeedDMS_Core_KeywordCategory | |
77.59% |
45 / 58 |
|
61.54% |
8 / 13 |
28.96 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
setDMS | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getID | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOwner | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
setName | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
setOwner | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |||
getKeywordLists | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
countKeywordLists | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
editKeywordList | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
addKeywordList | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
removeKeywordList | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
remove | |
66.67% |
8 / 12 |
|
0.00% |
0 / 1 |
3.33 |
1 | <?php |
2 | declare(strict_types=1); |
3 | |
4 | /** |
5 | * Implementation of keyword categories in the document management system |
6 | * |
7 | * @category DMS |
8 | * @package SeedDMS_Core |
9 | * @license GPL 2 |
10 | * @version @version@ |
11 | * @author Uwe Steinmann <uwe@steinmann.cx> |
12 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
13 | * 2010-2024 Uwe Steinmann |
14 | * @version Release: @package_version@ |
15 | */ |
16 | |
17 | /** |
18 | * Class to represent a keyword category in the document management system |
19 | * |
20 | * @category DMS |
21 | * @package SeedDMS_Core |
22 | * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx> |
23 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
24 | * 2010-2024 Uwe Steinmann |
25 | * @version Release: @package_version@ |
26 | */ |
27 | class SeedDMS_Core_KeywordCategory { /* {{{ */ |
28 | /** |
29 | * @var integer $_id id of keyword category |
30 | * @access protected |
31 | */ |
32 | protected $_id; |
33 | |
34 | /** |
35 | * @var integer $_ownerID id of user who is the owner |
36 | * @access protected |
37 | */ |
38 | protected $_ownerID; |
39 | |
40 | /** |
41 | * @var string $_name name of category |
42 | * @access protected |
43 | */ |
44 | protected $_name; |
45 | |
46 | /** |
47 | * @var SeedDMS_Core_DMS $_dms reference to dms this category belongs to |
48 | * @access protected |
49 | */ |
50 | protected $_dms; |
51 | |
52 | /** |
53 | * SeedDMS_Core_KeywordCategory constructor. |
54 | * |
55 | * @param $id |
56 | * @param $ownerID |
57 | * @param $name |
58 | */ |
59 | public function __construct($id, $ownerID, $name) { /* {{{ */ |
60 | $this->_id = $id; |
61 | $this->_name = $name; |
62 | $this->_ownerID = $ownerID; |
63 | $this->_dms = null; |
64 | } /* }}} */ |
65 | |
66 | /** |
67 | * @param SeedDMS_Core_DMS $dms |
68 | */ |
69 | public function setDMS($dms) { /* {{{ */ |
70 | $this->_dms = $dms; |
71 | } /* }}} */ |
72 | |
73 | /** |
74 | * Return internal id of keyword category |
75 | * |
76 | * @return int |
77 | */ |
78 | public function getID() { return $this->_id; } |
79 | |
80 | /** |
81 | * Return name of keyword category |
82 | * |
83 | * @return string |
84 | */ |
85 | public function getName() { return $this->_name; } |
86 | |
87 | /** |
88 | * Return owner of keyword category |
89 | * |
90 | * @return bool|SeedDMS_Core_User |
91 | */ |
92 | public function getOwner() { /* {{{ */ |
93 | if (!isset($this->_owner)) |
94 | $this->_owner = $this->_dms->getUser($this->_ownerID); |
95 | return $this->_owner; |
96 | } /* }}} */ |
97 | |
98 | /** |
99 | * Set name of keyword category |
100 | * |
101 | * @param $newName |
102 | * @return bool |
103 | */ |
104 | public function setName($newName) { /* {{{ */ |
105 | $newName = trim($newName); |
106 | if(!$newName) |
107 | return false; |
108 | |
109 | $db = $this->_dms->getDB(); |
110 | |
111 | $queryStr = "UPDATE `tblKeywordCategories` SET `name` = ".$db->qstr($newName)." WHERE `id` = ". $this->_id; |
112 | if (!$db->getResult($queryStr)) |
113 | return false; |
114 | |
115 | $this->_name = $newName; |
116 | return true; |
117 | } /* }}} */ |
118 | |
119 | /** |
120 | * Set owner of keyword category |
121 | * |
122 | * @param SeedDMS_Core_User $user |
123 | * @return bool |
124 | */ |
125 | public function setOwner($user) { /* {{{ */ |
126 | if(!$user || !$user->isType('user')) |
127 | return false; |
128 | |
129 | $db = $this->_dms->getDB(); |
130 | |
131 | $queryStr = "UPDATE `tblKeywordCategories` SET `owner` = " . $user->getID() . " WHERE `id` = " . $this->_id; |
132 | if (!$db->getResult($queryStr)) |
133 | return false; |
134 | |
135 | $this->_ownerID = $user->getID(); |
136 | $this->_owner = $user; |
137 | return true; |
138 | } /* }}} */ |
139 | |
140 | /** |
141 | * Get list of keywords in category |
142 | * |
143 | * @return array keywords of category |
144 | */ |
145 | public function getKeywordLists() { /* {{{ */ |
146 | $db = $this->_dms->getDB(); |
147 | |
148 | $queryStr = "SELECT * FROM `tblKeywords` WHERE `category` = " . $this->_id . " order by `keywords`"; |
149 | return $db->getResultArray($queryStr); |
150 | } |
151 | |
152 | /** |
153 | * Return number of keywords in category |
154 | * |
155 | * @return integer number of keywords in this list |
156 | */ |
157 | public function countKeywordLists() { /* {{{ */ |
158 | $db = $this->_dms->getDB(); |
159 | |
160 | $queryStr = "SELECT COUNT(*) as `c` FROM `tblKeywords` where `category`=".$this->_id; |
161 | $resArr = $db->getResultArray($queryStr); |
162 | if (is_bool($resArr) && !$resArr) |
163 | return false; |
164 | |
165 | return $resArr[0]['c']; |
166 | } /* }}} */ |
167 | |
168 | /** |
169 | * Change a keyword |
170 | * |
171 | * This method identifies the keyword by its id and also ensures that |
172 | * the keyword belongs to the category, though the keyword id would be |
173 | * sufficient to uniquely identify the keyword. |
174 | * |
175 | * @param $kid |
176 | * @param $keywords |
177 | * @return bool |
178 | */ |
179 | public function editKeywordList($kid, $keywords) { /* {{{ */ |
180 | $db = $this->_dms->getDB(); |
181 | |
182 | $queryStr = "UPDATE `tblKeywords` SET `keywords` = ".$db->qstr($keywords)." WHERE `id` = ".(int) $kid." AND `category`=".$this->_id; |
183 | return $db->getResult($queryStr); |
184 | } /* }}} */ |
185 | |
186 | /** |
187 | * Add a new keyword to category |
188 | * |
189 | * @param $keywords new keyword |
190 | * @return bool |
191 | */ |
192 | public function addKeywordList($keywords) { /* {{{ */ |
193 | $db = $this->_dms->getDB(); |
194 | |
195 | $queryStr = "INSERT INTO `tblKeywords` (`category`, `keywords`) VALUES (" . $this->_id . ", ".$db->qstr($keywords).")"; |
196 | return $db->getResult($queryStr); |
197 | } /* }}} */ |
198 | |
199 | /** |
200 | * Remove keyword |
201 | * |
202 | * This method identifies the keyword by its id and also ensures that |
203 | * the keyword belongs to the category, though the keyword id would be |
204 | * sufficient to uniquely identify the keyword. |
205 | * |
206 | * @param $kid |
207 | * @return bool |
208 | */ |
209 | public function removeKeywordList($kid) { /* {{{ */ |
210 | $db = $this->_dms->getDB(); |
211 | |
212 | $queryStr = "DELETE FROM `tblKeywords` WHERE `id` = ".(int) $kid." AND `category`=".$this->_id; |
213 | return $db->getResult($queryStr); |
214 | } /* }}} */ |
215 | |
216 | /** |
217 | * Delete all keywords of category and category itself |
218 | * |
219 | * @return bool |
220 | */ |
221 | public function remove() { /* {{{ */ |
222 | $db = $this->_dms->getDB(); |
223 | |
224 | $db->startTransaction(); |
225 | $queryStr = "DELETE FROM `tblKeywords` WHERE `category` = " . $this->_id; |
226 | if (!$db->getResult($queryStr)) { |
227 | $db->rollbackTransaction(); |
228 | return false; |
229 | } |
230 | |
231 | $queryStr = "DELETE FROM `tblKeywordCategories` WHERE `id` = " . $this->_id; |
232 | if (!$db->getResult($queryStr)) { |
233 | $db->rollbackTransaction(); |
234 | return false; |
235 | } |
236 | |
237 | $db->commitTransaction(); |
238 | return true; |
239 | } /* }}} */ |
240 | } /* }}} */ |