Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
86.96% covered (warning)
86.96%
40 / 46
55.56% covered (warning)
55.56%
5 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeedDMS_Core_DocumentCategory
86.96% covered (warning)
86.96%
40 / 46
55.56% covered (warning)
55.56%
5 / 9
25.28
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
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
 setName
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
3.01
 isUsed
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 remove
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
 getDocumentsByCategory
78.57% covered (warning)
78.57%
11 / 14
0.00% covered (danger)
0.00%
0 / 1
9.80
 countDocumentsByCategory
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
1<?php
2declare(strict_types=1);
3
4/**
5 * Implementation of document 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) 2010-2024 Uwe Steinmann
13 * @version    Release: @package_version@
14 */
15
16/**
17 * Class to represent a document category in the document management system
18 *
19 * @category   DMS
20 * @package    SeedDMS_Core
21 * @author     Uwe Steinmann <uwe@steinmann.cx>
22 * @copyright  Copyright (C) 2011-2024 Uwe Steinmann
23 * @version    Release: @package_version@
24 */
25class SeedDMS_Core_DocumentCategory {
26    /**
27     * @var integer $_id id of document category
28     * @access protected
29     */
30    protected $_id;
31
32    /**
33     * @var string $_name name of category
34     * @access protected
35     */
36    protected $_name;
37
38    /**
39     * @var object $_dms reference to dms this category belongs to
40     * @access protected
41     */
42    protected $_dms;
43
44    function __construct($id, $name) { /* {{{ */
45        $this->_id = $id;
46        $this->_name = $name;
47        $this->_dms = null;
48    } /* }}} */
49
50    function setDMS($dms) { /* {{{ */
51        $this->_dms = $dms;
52    } /* }}} */
53
54    function getID() { return $this->_id; }
55
56    function getName() { return $this->_name; }
57
58    function setName($newName) { /* {{{ */
59        $newName = trim($newName);
60        if(!$newName)
61            return false;
62
63        $db = $this->_dms->getDB();
64
65        $queryStr = "UPDATE `tblCategory` SET `name` = ".$db->qstr($newName)." WHERE `id` = ". $this->_id;
66        if (!$db->getResult($queryStr))
67            return false;
68
69        $this->_name = $newName;
70        return true;
71    } /* }}} */
72
73    function isUsed() { /* {{{ */
74        $db = $this->_dms->getDB();
75        
76        $queryStr = "SELECT * FROM `tblDocumentCategory` WHERE `categoryID`=".$this->_id;
77        $resArr = $db->getResultArray($queryStr);
78        if (is_array($resArr) && count($resArr) == 0)
79            return false;
80        return true;
81    } /* }}} */
82
83    function remove() { /* {{{ */
84        $db = $this->_dms->getDB();
85
86        $queryStr = "DELETE FROM `tblCategory` WHERE `id` = " . $this->_id;
87        if (!$db->getResult($queryStr))
88            return false;
89
90        return true;
91    } /* }}} */
92
93    function getDocumentsByCategory($limit=0, $offset=0) { /* {{{ */
94        $db = $this->_dms->getDB();
95
96        $queryStr = "SELECT * FROM `tblDocumentCategory` where `categoryID`=".$this->_id;
97        if($limit && is_numeric($limit))
98            $queryStr .= " LIMIT ".(int) $limit;
99        if($offset && is_numeric($offset))
100            $queryStr .= " OFFSET ".(int) $offset;
101        $resArr = $db->getResultArray($queryStr);
102        if (is_bool($resArr) && !$resArr)
103            return false;
104
105        $documents = array();
106        foreach ($resArr as $row) {
107            if($doc = $this->_dms->getDocument($row["documentID"]))
108                array_push($documents, $doc);
109        }
110        return $documents;
111    } /* }}} */
112
113    function countDocumentsByCategory() { /* {{{ */
114        $db = $this->_dms->getDB();
115
116        $queryStr = "SELECT COUNT(*) as `c` FROM `tblDocumentCategory` where `categoryID`=".$this->_id;
117        $resArr = $db->getResultArray($queryStr);
118        if (is_bool($resArr) && !$resArr)
119            return false;
120
121        return $resArr[0]['c'];
122    } /* }}} */
123
124}
125
126?>