Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.59% covered (warning)
77.59%
45 / 58
61.54% covered (warning)
61.54%
8 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeedDMS_Core_KeywordCategory
77.59% covered (warning)
77.59%
45 / 58
61.54% covered (warning)
61.54%
8 / 13
28.96
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOwner
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 setName
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
3.01
 setOwner
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
4.02
 getKeywordLists
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 countKeywordLists
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 editKeywordList
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 addKeywordList
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 removeKeywordList
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 remove
66.67% covered (warning)
66.67%
8 / 12
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2declare(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-2023 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-2023 Uwe Steinmann
25 * @version    Release: @package_version@
26 */
27class 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     * @param $id
55     * @param $ownerID
56     * @param $name
57     */
58    function __construct($id, $ownerID, $name) { /* {{{ */
59        $this->_id = $id;
60        $this->_name = $name;
61        $this->_ownerID = $ownerID;
62        $this->_dms = null;
63    } /* }}} */
64
65    /**
66     * @param SeedDMS_Core_DMS $dms
67     */
68    function setDMS($dms) { /* {{{ */
69        $this->_dms = $dms;
70    } /* }}} */
71
72    /**
73     * @return int
74     */
75    function getID() { return $this->_id; }
76
77    /**
78     * @return string
79     */
80    function getName() { return $this->_name; }
81
82    /**
83     * @return bool|SeedDMS_Core_User
84     */
85    function getOwner() { /* {{{ */
86        if (!isset($this->_owner))
87            $this->_owner = $this->_dms->getUser($this->_ownerID);
88        return $this->_owner;
89    } /* }}} */
90
91    /**
92     * @param $newName
93     * @return bool
94     */
95    function setName($newName) { /* {{{ */
96        $newName = trim($newName);
97        if(!$newName)
98            return false;
99
100        $db = $this->_dms->getDB();
101
102        $queryStr = "UPDATE `tblKeywordCategories` SET `name` = ".$db->qstr($newName)." WHERE `id` = ". $this->_id;
103        if (!$db->getResult($queryStr))
104            return false;
105
106        $this->_name = $newName;
107        return true;
108    } /* }}} */
109
110    /**
111     * @param SeedDMS_Core_User $user
112     * @return bool
113     */
114    function setOwner($user) { /* {{{ */
115        if(!$user || !$user->isType('user'))
116            return false;
117
118        $db = $this->_dms->getDB();
119
120        $queryStr = "UPDATE `tblKeywordCategories` SET `owner` = " . $user->getID() . " WHERE `id` = " . $this->_id;
121        if (!$db->getResult($queryStr))
122            return false;
123
124        $this->_ownerID = $user->getID();
125        $this->_owner = $user;
126        return true;
127    } /* }}} */
128
129    /**
130     * @return array keywords in this list
131     */
132    function getKeywordLists() { /* {{{ */
133        $db = $this->_dms->getDB();
134
135        $queryStr = "SELECT * FROM `tblKeywords` WHERE `category` = " . $this->_id . " order by `keywords`";
136        return $db->getResultArray($queryStr);
137    }
138
139    /**
140     * @return integer number of keywords in this list
141     */
142    function countKeywordLists() { /* {{{ */
143        $db = $this->_dms->getDB();
144
145        $queryStr = "SELECT COUNT(*) as `c` FROM `tblKeywords` where `category`=".$this->_id;
146        $resArr = $db->getResultArray($queryStr);
147        if (is_bool($resArr) && !$resArr)
148            return false;
149
150        return $resArr[0]['c'];
151    } /* }}} */
152
153    /**
154     * @param $listID
155     * @param $keywords
156     * @return bool
157     */
158    function editKeywordList($listID, $keywords) { /* {{{ */
159        $db = $this->_dms->getDB();
160
161        $queryStr = "UPDATE `tblKeywords` SET `keywords` = ".$db->qstr($keywords)." WHERE `id` = $listID";
162        return $db->getResult($queryStr);
163    } /* }}} */
164
165    /**
166     * @param $keywords
167     * @return bool
168     */
169    function addKeywordList($keywords) { /* {{{ */
170        $db = $this->_dms->getDB();
171
172        $queryStr = "INSERT INTO `tblKeywords` (`category`, `keywords`) VALUES (" . $this->_id . ", ".$db->qstr($keywords).")";
173        return $db->getResult($queryStr);
174    } /* }}} */
175
176    /**
177     * @param $listID
178     * @return bool
179     */
180    function removeKeywordList($listID) { /* {{{ */
181        $db = $this->_dms->getDB();
182
183        $queryStr = "DELETE FROM `tblKeywords` WHERE `id` = $listID";
184        return $db->getResult($queryStr);
185    } /* }}} */
186
187    /**
188     * @return bool
189     */
190    function remove() { /* {{{ */
191        $db = $this->_dms->getDB();
192
193        $db->startTransaction();
194        $queryStr = "DELETE FROM `tblKeywords` WHERE `category` = " . $this->_id;
195        if (!$db->getResult($queryStr)) {
196            $db->rollbackTransaction();
197            return false;
198        }
199
200        $queryStr = "DELETE FROM `tblKeywordCategories` WHERE `id` = " . $this->_id;
201        if (!$db->getResult($queryStr)) {
202            $db->rollbackTransaction();
203            return false;
204        }
205
206        $db->commitTransaction();
207        return true;
208    } /* }}} */
209}