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