Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 139 |
|
0.00% |
0 / 23 |
CRAP | |
0.00% |
0 / 2 |
| SeedDMS_Core_Transmittal | |
0.00% |
0 / 97 |
|
0.00% |
0 / 14 |
1406 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getInstance | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
72 | |||
| getAllInstances | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
| setDMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setName | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| getComment | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setComment | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getItems | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| getSize | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| addContent | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| remove | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| SeedDMS_Core_TransmittalItem | |
0.00% |
0 / 42 |
|
0.00% |
0 / 9 |
306 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getInstance | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
| setDMS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getID | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTransmittal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| remove | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| updateContent | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Implementation of the transmittal object 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 Uwe Steinmann |
| 12 | * @version Release: @package_version@ |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Class to represent a transmittal 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 Uwe Steinmann |
| 23 | * @version Release: @package_version@ |
| 24 | */ |
| 25 | class SeedDMS_Core_Transmittal { |
| 26 | /** |
| 27 | * @var integer id of transmittal |
| 28 | * |
| 29 | * @access protected |
| 30 | */ |
| 31 | var $_id; |
| 32 | |
| 33 | /** |
| 34 | * @var string name of transmittal |
| 35 | * |
| 36 | * @access protected |
| 37 | */ |
| 38 | var $_name; |
| 39 | |
| 40 | /** |
| 41 | * @var string comment of transmittal |
| 42 | * |
| 43 | * @access protected |
| 44 | */ |
| 45 | var $_comment; |
| 46 | |
| 47 | /** |
| 48 | * @var boolean true if transmittal is public |
| 49 | * |
| 50 | * @access protected |
| 51 | */ |
| 52 | var $_isPublic; |
| 53 | |
| 54 | /** |
| 55 | * @var object user this transmittal belongs to |
| 56 | * |
| 57 | * @access protected |
| 58 | */ |
| 59 | var $_user; |
| 60 | |
| 61 | /** |
| 62 | * @var object date of creation |
| 63 | * |
| 64 | * @access protected |
| 65 | */ |
| 66 | var $_date; |
| 67 | |
| 68 | /** |
| 69 | * @var object items |
| 70 | * |
| 71 | * @access protected |
| 72 | */ |
| 73 | var $_items; |
| 74 | |
| 75 | /** |
| 76 | * @var object reference to the dms instance this user belongs to |
| 77 | * |
| 78 | * @access protected |
| 79 | */ |
| 80 | var $_dms; |
| 81 | |
| 82 | function __construct($id, $user, $name, $comment, $isPublic=0, $date='') { |
| 83 | $this->_id = $id; |
| 84 | $this->_name = $name; |
| 85 | $this->_comment = $comment; |
| 86 | $this->_user = $user; |
| 87 | $this->_isPublic = $isPublic; |
| 88 | $this->_date = $date; |
| 89 | $this->_items = array(); |
| 90 | $this->_dms = null; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get an instance of a transmittal object |
| 95 | * |
| 96 | * @param string|integer $id id or name of transmittal, depending |
| 97 | * on the 3rd parameter. |
| 98 | * @param object $dms instance of dms |
| 99 | * @param string $by search by [id|name]. If this |
| 100 | * parameter is left empty, the user will be search by its Id. |
| 101 | * @return object instance of class SeedDMS_Core_Transmittal |
| 102 | */ |
| 103 | public static function getInstance($id, $dms, $by='') { /* {{{ */ |
| 104 | if(!$dms || get_class($dms) != 'SeedDMS_Core_DMS') |
| 105 | return false; |
| 106 | |
| 107 | $db = $dms->getDB(); |
| 108 | |
| 109 | switch($by) { |
| 110 | case 'name': |
| 111 | $queryStr = "SELECT * FROM `tblTransmittals` WHERE `name` = ".$db->qstr($id); |
| 112 | break; |
| 113 | default: |
| 114 | $queryStr = "SELECT * FROM `tblTransmittals` WHERE id = " . (int) $id; |
| 115 | } |
| 116 | |
| 117 | $resArr = $db->getResultArray($queryStr); |
| 118 | |
| 119 | if (is_bool($resArr) && $resArr == false) return false; |
| 120 | if (count($resArr) != 1) return false; |
| 121 | |
| 122 | $resArr = $resArr[0]; |
| 123 | |
| 124 | $uclassname = $dms->getClassname('user'); |
| 125 | $user = $uclassname::getInstance($resArr['userID'], $dms); |
| 126 | $transmittal = new self($resArr["id"], $user, $resArr["name"], $resArr["comment"], $resArr["public"], $resArr["date"]); |
| 127 | $transmittal->setDMS($dms); |
| 128 | return $transmittal; |
| 129 | } /* }}} */ |
| 130 | |
| 131 | /** |
| 132 | * Get all instances of a transmittal object |
| 133 | * |
| 134 | * @param string|integer $id id or name of transmittal, depending |
| 135 | * on the 3rd parameter. |
| 136 | * @param object $dms instance of dms |
| 137 | * @param string $by search by [id|name]. If this |
| 138 | * parameter is left empty, the user will be search by its Id. |
| 139 | * @return object instance of class SeedDMS_Core_Transmittal |
| 140 | */ |
| 141 | public static function getAllInstances($user, $orderby, $dms) { /* {{{ */ |
| 142 | $db = $dms->getDB(); |
| 143 | |
| 144 | $queryStr = "SELECT * FROM `tblTransmittals`"; |
| 145 | if($user) |
| 146 | $queryStr .= " WHERE `userID` = " . $user->getID(); |
| 147 | |
| 148 | $resArr = $db->getResultArray($queryStr); |
| 149 | |
| 150 | if (is_bool($resArr) && $resArr == false) return false; |
| 151 | |
| 152 | $uclassname = $dms->getClassname('user'); |
| 153 | $transmittals = array(); |
| 154 | foreach ($resArr as $res) { |
| 155 | $user = $uclassname::getInstance($res['userID'], $dms); |
| 156 | $transmittal = new self($res["id"], $user, $res["name"], $res["comment"], $res["public"], $res["date"]); |
| 157 | $transmittal->setDMS($dms); |
| 158 | $transmittals[] = $transmittal; |
| 159 | } |
| 160 | return $transmittals; |
| 161 | } /* }}} */ |
| 162 | |
| 163 | function setDMS($dms) { |
| 164 | $this->_dms = $dms; |
| 165 | } |
| 166 | |
| 167 | function getID() { return $this->_id; } |
| 168 | |
| 169 | function getName() { return $this->_name; } |
| 170 | |
| 171 | function setName($newName) { /* {{{ */ |
| 172 | $db = $this->_dms->getDB(); |
| 173 | |
| 174 | $queryStr = "UPDATE `tblTransmittals` SET `name` =".$db->qstr($newName)." WHERE `id` = " . $this->_id; |
| 175 | $res = $db->getResult($queryStr); |
| 176 | if (!$res) |
| 177 | return false; |
| 178 | |
| 179 | $this->_name = $newName; |
| 180 | return true; |
| 181 | } /* }}} */ |
| 182 | |
| 183 | function getComment() { return $this->_comment; } |
| 184 | |
| 185 | function setComment($newComment) { /* {{{ */ |
| 186 | $db = $this->_dms->getDB(); |
| 187 | |
| 188 | $queryStr = "UPDATE `tblTransmittals` SET `comment` =".$db->qstr($newComment)." WHERE `id` = " . $this->_id; |
| 189 | $res = $db->getResult($queryStr); |
| 190 | if (!$res) |
| 191 | return false; |
| 192 | |
| 193 | $this->_comment = $newComment; |
| 194 | return true; |
| 195 | } /* }}} */ |
| 196 | |
| 197 | function getUser() { return $this->_user; } |
| 198 | |
| 199 | function getItems() { /* {{{ */ |
| 200 | $db = $this->_dms->getDB(); |
| 201 | |
| 202 | if (!$this->_items) { |
| 203 | $queryStr = "SELECT `tblTransmittalItems`.* FROM `tblTransmittalItems` ". |
| 204 | "LEFT JOIN `tblDocuments` ON `tblTransmittalItems`.`document`=`tblDocuments`.`id` ". |
| 205 | "WHERE `tblTransmittalItems`.`transmittal` = '". $this->_id ."'"; |
| 206 | $resArr = $db->getResultArray($queryStr); |
| 207 | if (is_bool($resArr) && $resArr == false) |
| 208 | return false; |
| 209 | |
| 210 | $this->_users = array(); |
| 211 | |
| 212 | $classname = $this->_dms->getClassname('transmittalitem'); |
| 213 | foreach ($resArr as $row) { |
| 214 | $document = $this->_dms->getDocument($row['document']); |
| 215 | $content = $document->getContentByVersion($row['version']); |
| 216 | $item = new $classname($row["id"], $this, $content, $row["date"]); |
| 217 | array_push($this->_items, $item); |
| 218 | } |
| 219 | } |
| 220 | return $this->_items; |
| 221 | } /* }}} */ |
| 222 | |
| 223 | function getSize() { /* {{{ */ |
| 224 | $db = $this->_dms->getDB(); |
| 225 | |
| 226 | if (!$this->_items) { |
| 227 | self::getItems(); |
| 228 | } |
| 229 | |
| 230 | $size = 0; |
| 231 | foreach ($this->_items as $item) { |
| 232 | if($content = $item->getContent()) { |
| 233 | $size += $content->getFileSize(); |
| 234 | } |
| 235 | } |
| 236 | return $size; |
| 237 | } /* }}} */ |
| 238 | |
| 239 | /** |
| 240 | * Add an item to the transmittal |
| 241 | * |
| 242 | * @param object $item instance of SeedDMS_Core_DocumentContent |
| 243 | * @return boolean true if item could be added, otherwise false |
| 244 | */ |
| 245 | function addContent($item) { /* {{{ */ |
| 246 | $db = $this->_dms->getDB(); |
| 247 | |
| 248 | if(get_class($item) != $this->_dms->getClassname('documentcontent')) |
| 249 | return false; |
| 250 | |
| 251 | $document = $item->getDocument(); |
| 252 | $queryStr = "INSERT INTO `tblTransmittalItems` (`transmittal`, `document`, `version`, `date`) ". |
| 253 | "VALUES ('". $this->_id ."', ".$document->getID().", ".$item->getVersion().", ".$db->getCurrentDatetime().")"; |
| 254 | $res=$db->getResult($queryStr); |
| 255 | if(!$res) { |
| 256 | return false; |
| 257 | } |
| 258 | $itemID = $db->getInsertID('tblTransmittalItems'); |
| 259 | |
| 260 | return SeedDMS_Core_TransmittalItem::getInstance($itemID, $this->_dms); |
| 261 | } /* }}} */ |
| 262 | |
| 263 | function remove() { /* {{{ */ |
| 264 | $db = $this->_dms->getDB(); |
| 265 | |
| 266 | $queryStr = "DELETE FROM `tblTransmittals` WHERE `id` = " . $this->_id; |
| 267 | if (!$db->getResult($queryStr)) { |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | return true; |
| 272 | } /* }}} */ |
| 273 | |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Class to represent a transmittal in the document management system |
| 278 | * |
| 279 | * @category DMS |
| 280 | * @package SeedDMS_Core |
| 281 | * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx> |
| 282 | * @copyright Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, |
| 283 | * 2010 Uwe Steinmann |
| 284 | * @version Release: @package_version@ |
| 285 | */ |
| 286 | class SeedDMS_Core_TransmittalItem { |
| 287 | /** |
| 288 | * @var integer id of transmittal item |
| 289 | * |
| 290 | * @access protected |
| 291 | */ |
| 292 | var $_id; |
| 293 | |
| 294 | /** |
| 295 | * @var object document content |
| 296 | * |
| 297 | * @access protected |
| 298 | */ |
| 299 | var $_content; |
| 300 | |
| 301 | /** |
| 302 | * @var object transmittal |
| 303 | * |
| 304 | * @access protected |
| 305 | */ |
| 306 | var $_transmittal; |
| 307 | |
| 308 | /** |
| 309 | * @var object date of creation |
| 310 | * |
| 311 | * @access protected |
| 312 | */ |
| 313 | var $_date; |
| 314 | |
| 315 | function __construct($id, $transmittal, $content, $date='') { |
| 316 | $this->_id = $id; |
| 317 | $this->_transmittal = $transmittal; |
| 318 | $this->_content = $content; |
| 319 | $this->_date = $date; |
| 320 | $this->_dms = null; |
| 321 | } |
| 322 | |
| 323 | public static function getInstance($id, $dms) { /* {{{ */ |
| 324 | if(!$dms || get_class($dms) != 'SeedDMS_Core_DMS') |
| 325 | return false; |
| 326 | |
| 327 | $db = $dms->getDB(); |
| 328 | |
| 329 | $queryStr = "SELECT * FROM `tblTransmittalItems` WHERE `id` = " . (int) $id; |
| 330 | $resArr = $db->getResultArray($queryStr); |
| 331 | if (is_bool($resArr) && $resArr == false) |
| 332 | return false; |
| 333 | if (count($resArr) != 1) |
| 334 | return false; |
| 335 | $resArr = $resArr[0]; |
| 336 | |
| 337 | $transmittal = SeedDMS_Core_Transmittal::getInstance($resArr['transmittal'], $dms); |
| 338 | $dclassname = $dms->getClassname('document'); |
| 339 | $document = $dclassname::getInstance($resArr['document'], $dms); |
| 340 | $content = $document->getContentByVersion((int) $resArr['version']); |
| 341 | |
| 342 | $item = new self($resArr["id"], $transmittal, $content, $resArr["date"]); |
| 343 | $item->setDMS($dms); |
| 344 | return $item; |
| 345 | } /* }}} */ |
| 346 | |
| 347 | function setDMS($dms) { |
| 348 | $this->_dms = $dms; |
| 349 | } |
| 350 | |
| 351 | function getID() { return $this->_id; } |
| 352 | |
| 353 | function getTransmittal() { return $this->_transmittal; } |
| 354 | |
| 355 | function getContent() { return $this->_content; } |
| 356 | |
| 357 | function getDate() { return $this->_date; } |
| 358 | |
| 359 | function remove() { /* {{{ */ |
| 360 | $db = $this->_dms->getDB(); |
| 361 | $transmittal = $this->_transmittal; |
| 362 | |
| 363 | $queryStr = "DELETE FROM `tblTransmittalItems` WHERE `id` = " . $this->_id; |
| 364 | if (!$db->getResult($queryStr)) { |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | return true; |
| 369 | } /* }}} */ |
| 370 | |
| 371 | /** |
| 372 | * Check if the content referenzed by the transmittal item is unequal |
| 373 | * to the latest content of the document. |
| 374 | * |
| 375 | * This function updateѕ always to the latest version of the document, |
| 376 | * even if the version in the item is higher. This can happen if a |
| 377 | * version has been removed. |
| 378 | * |
| 379 | * @return boolean/integer false in case of an error, otherwise the new |
| 380 | * version. |
| 381 | */ |
| 382 | function updateContent() { /* {{{ */ |
| 383 | $db = $this->_dms->getDB(); |
| 384 | $transmittal = $this->_transmittal; |
| 385 | |
| 386 | $document = $this->_content->getDocument(); |
| 387 | $latestcontent = $document->getLatestContent(); |
| 388 | if($latestcontent->getVersion() != $this->_content->getVersion()) { |
| 389 | $queryStr = "UPDATE `tblTransmittalItems` set `version` = ".$latestcontent->getVersion()." WHERE `id` = " . $this->_id; |
| 390 | if (!$db->getResult($queryStr)) { |
| 391 | return false; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | return $latestcontent->getVersion(); |
| 396 | } /* }}} */ |
| 397 | } |
| 398 | ?> |