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 | /** |
3 | * Implementation of keyword categories in the document management system |
4 | * |
5 | * @category DMS |
6 | * @package SeedDMS_Core |
7 | * @license GPL 2 |
8 | * @version @version@ |
9 | * @author Uwe Steinmann <uwe@steinmann.cx> |
10 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
11 | * 2010-2023 Uwe Steinmann |
12 | * @version Release: @package_version@ |
13 | */ |
14 | |
15 | /** |
16 | * Class to represent a keyword category in the document management system |
17 | * |
18 | * @category DMS |
19 | * @package SeedDMS_Core |
20 | * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx> |
21 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
22 | * 2010-2023 Uwe Steinmann |
23 | * @version Release: @package_version@ |
24 | */ |
25 | class SeedDMS_Core_KeywordCategory { |
26 | /** |
27 | * @var integer $_id id of keyword category |
28 | * @access protected |
29 | */ |
30 | protected $_id; |
31 | |
32 | /** |
33 | * @var integer $_ownerID id of user who is the owner |
34 | * @access protected |
35 | */ |
36 | protected $_ownerID; |
37 | |
38 | /** |
39 | * @var string $_name name of category |
40 | * @access protected |
41 | */ |
42 | protected $_name; |
43 | |
44 | /** |
45 | * @var SeedDMS_Core_DMS $_dms reference to dms this category belongs to |
46 | * @access protected |
47 | */ |
48 | protected $_dms; |
49 | |
50 | /** |
51 | * SeedDMS_Core_KeywordCategory constructor. |
52 | * @param $id |
53 | * @param $ownerID |
54 | * @param $name |
55 | */ |
56 | function __construct($id, $ownerID, $name) { /* {{{ */ |
57 | $this->_id = $id; |
58 | $this->_name = $name; |
59 | $this->_ownerID = $ownerID; |
60 | $this->_dms = null; |
61 | } /* }}} */ |
62 | |
63 | /** |
64 | * @param SeedDMS_Core_DMS $dms |
65 | */ |
66 | function setDMS($dms) { /* {{{ */ |
67 | $this->_dms = $dms; |
68 | } /* }}} */ |
69 | |
70 | /** |
71 | * @return int |
72 | */ |
73 | function getID() { return $this->_id; } |
74 | |
75 | /** |
76 | * @return string |
77 | */ |
78 | function getName() { return $this->_name; } |
79 | |
80 | /** |
81 | * @return bool|SeedDMS_Core_User |
82 | */ |
83 | function getOwner() { /* {{{ */ |
84 | if (!isset($this->_owner)) |
85 | $this->_owner = $this->_dms->getUser($this->_ownerID); |
86 | return $this->_owner; |
87 | } /* }}} */ |
88 | |
89 | /** |
90 | * @param $newName |
91 | * @return bool |
92 | */ |
93 | function setName($newName) { /* {{{ */ |
94 | $newName = trim($newName); |
95 | if(!$newName) |
96 | return false; |
97 | |
98 | $db = $this->_dms->getDB(); |
99 | |
100 | $queryStr = "UPDATE `tblKeywordCategories` SET `name` = ".$db->qstr($newName)." WHERE `id` = ". $this->_id; |
101 | if (!$db->getResult($queryStr)) |
102 | return false; |
103 | |
104 | $this->_name = $newName; |
105 | return true; |
106 | } /* }}} */ |
107 | |
108 | /** |
109 | * @param SeedDMS_Core_User $user |
110 | * @return bool |
111 | */ |
112 | function setOwner($user) { /* {{{ */ |
113 | if(!$user || !$user->isType('user')) |
114 | return false; |
115 | |
116 | $db = $this->_dms->getDB(); |
117 | |
118 | $queryStr = "UPDATE `tblKeywordCategories` SET `owner` = " . $user->getID() . " WHERE `id` = " . $this->_id; |
119 | if (!$db->getResult($queryStr)) |
120 | return false; |
121 | |
122 | $this->_ownerID = $user->getID(); |
123 | $this->_owner = $user; |
124 | return true; |
125 | } /* }}} */ |
126 | |
127 | /** |
128 | * @return array keywords in this list |
129 | */ |
130 | function getKeywordLists() { /* {{{ */ |
131 | $db = $this->_dms->getDB(); |
132 | |
133 | $queryStr = "SELECT * FROM `tblKeywords` WHERE `category` = " . $this->_id . " order by `keywords`"; |
134 | return $db->getResultArray($queryStr); |
135 | } |
136 | |
137 | /** |
138 | * @return integer number of keywords in this list |
139 | */ |
140 | function countKeywordLists() { /* {{{ */ |
141 | $db = $this->_dms->getDB(); |
142 | |
143 | $queryStr = "SELECT COUNT(*) as `c` FROM `tblKeywords` where `category`=".$this->_id; |
144 | $resArr = $db->getResultArray($queryStr); |
145 | if (is_bool($resArr) && !$resArr) |
146 | return false; |
147 | |
148 | return $resArr[0]['c']; |
149 | } /* }}} */ |
150 | |
151 | /** |
152 | * @param $listID |
153 | * @param $keywords |
154 | * @return bool |
155 | */ |
156 | function editKeywordList($listID, $keywords) { /* {{{ */ |
157 | $db = $this->_dms->getDB(); |
158 | |
159 | $queryStr = "UPDATE `tblKeywords` SET `keywords` = ".$db->qstr($keywords)." WHERE `id` = $listID"; |
160 | return $db->getResult($queryStr); |
161 | } /* }}} */ |
162 | |
163 | /** |
164 | * @param $keywords |
165 | * @return bool |
166 | */ |
167 | function addKeywordList($keywords) { /* {{{ */ |
168 | $db = $this->_dms->getDB(); |
169 | |
170 | $queryStr = "INSERT INTO `tblKeywords` (`category`, `keywords`) VALUES (" . $this->_id . ", ".$db->qstr($keywords).")"; |
171 | return $db->getResult($queryStr); |
172 | } /* }}} */ |
173 | |
174 | /** |
175 | * @param $listID |
176 | * @return bool |
177 | */ |
178 | function removeKeywordList($listID) { /* {{{ */ |
179 | $db = $this->_dms->getDB(); |
180 | |
181 | $queryStr = "DELETE FROM `tblKeywords` WHERE `id` = $listID"; |
182 | return $db->getResult($queryStr); |
183 | } /* }}} */ |
184 | |
185 | /** |
186 | * @return bool |
187 | */ |
188 | function remove() { /* {{{ */ |
189 | $db = $this->_dms->getDB(); |
190 | |
191 | $db->startTransaction(); |
192 | $queryStr = "DELETE FROM `tblKeywords` WHERE `category` = " . $this->_id; |
193 | if (!$db->getResult($queryStr)) { |
194 | $db->rollbackTransaction(); |
195 | return false; |
196 | } |
197 | |
198 | $queryStr = "DELETE FROM `tblKeywordCategories` WHERE `id` = " . $this->_id; |
199 | if (!$db->getResult($queryStr)) { |
200 | $db->rollbackTransaction(); |
201 | return false; |
202 | } |
203 | |
204 | $db->commitTransaction(); |
205 | return true; |
206 | } /* }}} */ |
207 | } |