Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.11% |
40 / 47 |
|
50.00% |
5 / 10 |
CRAP | |
0.00% |
0 / 1 |
| SeedDMS_Core_DocumentCategory | |
85.11% |
40 / 47 |
|
50.00% |
5 / 10 |
27.06 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
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 | |||
| setName | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
| getColor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isUsed | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| remove | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
2.03 | |||
| getDocumentsByCategory | |
78.57% |
11 / 14 |
|
0.00% |
0 / 1 |
9.80 | |||
| countDocumentsByCategory | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
3.04 | |||
| 1 | <?php |
| 2 | declare(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 | */ |
| 25 | class 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 | public function __construct($id, $name) { /* {{{ */ |
| 45 | $this->_id = $id; |
| 46 | $this->_name = $name; |
| 47 | $this->_dms = null; |
| 48 | } /* }}} */ |
| 49 | |
| 50 | public function setDMS($dms) { /* {{{ */ |
| 51 | $this->_dms = $dms; |
| 52 | } /* }}} */ |
| 53 | |
| 54 | public function getID() { return $this->_id; } |
| 55 | |
| 56 | public function getName() { return $this->_name; } |
| 57 | |
| 58 | public 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 | public function getColor() { return substr(md5($this->_name), 0, 6); } |
| 74 | |
| 75 | /** |
| 76 | * Check if this category is used |
| 77 | * |
| 78 | * @return boolean true if category is used, otherwise false |
| 79 | */ |
| 80 | public function isUsed() { /* {{{ */ |
| 81 | $db = $this->_dms->getDB(); |
| 82 | |
| 83 | $queryStr = "SELECT * FROM `tblDocumentCategory` WHERE `categoryID`=".$this->_id; |
| 84 | $resArr = $db->getResultArray($queryStr); |
| 85 | if (is_array($resArr) && count($resArr) == 0) |
| 86 | return false; |
| 87 | return true; |
| 88 | } /* }}} */ |
| 89 | |
| 90 | /** |
| 91 | * Remove category |
| 92 | */ |
| 93 | public function remove() { /* {{{ */ |
| 94 | $db = $this->_dms->getDB(); |
| 95 | |
| 96 | $queryStr = "DELETE FROM `tblCategory` WHERE `id` = " . $this->_id; |
| 97 | if (!$db->getResult($queryStr)) |
| 98 | return false; |
| 99 | |
| 100 | return true; |
| 101 | } /* }}} */ |
| 102 | |
| 103 | /** |
| 104 | * Return documents with this category |
| 105 | * |
| 106 | * @param integer $limit |
| 107 | * @param integer $offset |
| 108 | * @return array |
| 109 | */ |
| 110 | public function getDocumentsByCategory($limit = 0, $offset = 0) { /* {{{ */ |
| 111 | $db = $this->_dms->getDB(); |
| 112 | |
| 113 | $queryStr = "SELECT * FROM `tblDocumentCategory` WHERE `categoryID`=".$this->_id; |
| 114 | if ($limit && is_numeric($limit)) |
| 115 | $queryStr .= " LIMIT ".(int) $limit; |
| 116 | if ($offset && is_numeric($offset)) |
| 117 | $queryStr .= " OFFSET ".(int) $offset; |
| 118 | $resArr = $db->getResultArray($queryStr); |
| 119 | if (is_bool($resArr) && !$resArr) |
| 120 | return false; |
| 121 | |
| 122 | $documents = array(); |
| 123 | foreach ($resArr as $row) { |
| 124 | if ($doc = $this->_dms->getDocument($row["documentID"])) |
| 125 | array_push($documents, $doc); |
| 126 | } |
| 127 | return $documents; |
| 128 | } /* }}} */ |
| 129 | |
| 130 | /** |
| 131 | * Return number of documents with this category |
| 132 | * |
| 133 | * @return integer |
| 134 | */ |
| 135 | public function countDocumentsByCategory() { /* {{{ */ |
| 136 | $db = $this->_dms->getDB(); |
| 137 | |
| 138 | $queryStr = "SELECT COUNT(*) as `c` FROM `tblDocumentCategory` WHERE `categoryID`=".$this->_id; |
| 139 | $resArr = $db->getResultArray($queryStr); |
| 140 | if (is_bool($resArr) && !$resArr) |
| 141 | return false; |
| 142 | |
| 143 | return $resArr[0]['c']; |
| 144 | } /* }}} */ |
| 145 | |
| 146 | } |